@univerjs/docs-ui 1.0.0-alpha.1 → 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,5 +1,5 @@
1
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 { DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService, IDocStateChangeInterceptorService, InsertTextCommand, RichTextEditingMutation, SetTextSelectionsOperation, UpdateTextCommand } from "@univerjs/docs";
2
+ import { CreateHeaderFooterCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService, HeaderFooterType, IDocStateChangeInterceptorService, InsertTextCommand, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, UpdateTextCommand, consumeContentInsertRange } from "@univerjs/docs";
3
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";
@@ -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;
@@ -3823,7 +3828,7 @@ let DocClipboardService = class DocClipboardService extends Disposable {
3823
3828
  }
3824
3829
  _getDocumentBodyInRanges(sliceType, ranges) {
3825
3830
  var _docDataModel$getSelf;
3826
- const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
3831
+ const docDataModel = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
3827
3832
  const allRanges = ranges !== null && ranges !== void 0 ? ranges : this._docSelectionManagerService.getDocRanges();
3828
3833
  const results = [];
3829
3834
  let needCache = true;
@@ -3833,6 +3838,7 @@ let DocClipboardService = class DocClipboardService extends Disposable {
3833
3838
  const snapshot = docDataModel.getSnapshot();
3834
3839
  if (body == null) return;
3835
3840
  for (const range of allRanges) {
3841
+ var _docDataModel$getSelf2;
3836
3842
  const { startOffset, endOffset, collapsed, rangeType } = range;
3837
3843
  if (collapsed || startOffset == null || endOffset == null) continue;
3838
3844
  if (rangeType === DOC_RANGE_TYPE.RECT) {
@@ -3846,7 +3852,7 @@ let DocClipboardService = class DocClipboardService extends Disposable {
3846
3852
  endOffset,
3847
3853
  collapsed
3848
3854
  };
3849
- 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);
3850
3856
  if (docBody == null) continue;
3851
3857
  results.push(docBody);
3852
3858
  }
@@ -4120,18 +4126,19 @@ const MoveDocBlockCommand = {
4120
4126
  if (!params) return false;
4121
4127
  const univerInstanceService = accessor.get(IUniverInstanceService);
4122
4128
  const commandService = accessor.get(ICommandService);
4123
- 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);
4124
4131
  if (!doc) return false;
4125
4132
  const previousDocumentData = doc.getSnapshot();
4126
4133
  const moveResult = buildMoveDocBlockActions({
4127
4134
  documentData: previousDocumentData,
4128
- sourceRange: params.sourceRange,
4129
- targetOffset: params.targetOffset
4135
+ sourceRange,
4136
+ targetOffset
4130
4137
  });
4131
4138
  const { nextDocumentData, movedRange } = accessor.get(DocBlockMoveValidatorService).transformMoveResult({
4132
4139
  unitId: doc.getUnitId(),
4133
- sourceRange: params.sourceRange,
4134
- targetOffset: params.targetOffset,
4140
+ sourceRange,
4141
+ targetOffset,
4135
4142
  previousDocumentData,
4136
4143
  result: moveResult
4137
4144
  });
@@ -4317,7 +4324,7 @@ const DocSelectAllCommand = {
4317
4324
  id: "doc.command.select-all",
4318
4325
  type: CommandType.COMMAND,
4319
4326
  handler: async (accessor) => {
4320
- var _docRanges$find;
4327
+ var _docRanges$find, _docDataModel$getSelf;
4321
4328
  const univerInstanceService = accessor.get(IUniverInstanceService);
4322
4329
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
4323
4330
  const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
@@ -4326,7 +4333,7 @@ const DocSelectAllCommand = {
4326
4333
  if (docDataModel == null || activeRange == null) return false;
4327
4334
  const { segmentId } = activeRange;
4328
4335
  const unitId = docDataModel.getUnitId();
4329
- 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();
4330
4337
  if (body == null) return false;
4331
4338
  const { dataStream } = body;
4332
4339
  if (dataStream === "\r\n") return true;
@@ -4520,7 +4527,7 @@ const IMEInputCommand = {
4520
4527
  id: "doc.command.ime-input",
4521
4528
  type: CommandType.COMMAND,
4522
4529
  handler: async (accessor, params) => {
4523
- var _renderManagerService, _body$customRanges, _body$customDecoratio;
4530
+ var _renderManagerService, _docDataModel$getSelf, _body$customRanges, _body$customDecoratio;
4524
4531
  const { unitId, newText, oldTextLen, isCompositionEnd, isCompositionStart } = params;
4525
4532
  const commandService = accessor.get(ICommandService);
4526
4533
  const renderManagerService = accessor.get(IRenderManagerService);
@@ -4532,7 +4539,7 @@ const IMEInputCommand = {
4532
4539
  const previousActiveRange = imeInputManagerService.getActiveRange();
4533
4540
  if (previousActiveRange == null) return false;
4534
4541
  const { style, segmentId } = previousActiveRange;
4535
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
4542
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
4536
4543
  if (body == null) return false;
4537
4544
  Object.assign(previousActiveRange, previousActiveRange);
4538
4545
  const { startOffset, endOffset } = previousActiveRange;
@@ -4736,7 +4743,7 @@ const SetInlineFormatCommand = {
4736
4743
  id: "doc.command.set-inline-format",
4737
4744
  type: CommandType.COMMAND,
4738
4745
  handler: async (accessor, params) => {
4739
- var _docSelectionManagerS, _docRanges$find;
4746
+ var _docSelectionManagerS, _docRanges$find, _docDataModel$getSelf;
4740
4747
  const { value, preCommandId } = params;
4741
4748
  const commandService = accessor.get(ICommandService);
4742
4749
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
@@ -4749,7 +4756,7 @@ const SetInlineFormatCommand = {
4749
4756
  const { segmentId } = docRanges[0];
4750
4757
  const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
4751
4758
  if (docDataModel == null) return false;
4752
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
4759
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
4753
4760
  if (body == null) return false;
4754
4761
  const unitId = docDataModel.getUnitId();
4755
4762
  let formatValue;
@@ -4937,12 +4944,13 @@ const ReplaceSnapshotCommand = {
4937
4944
  id: "doc.command-replace-snapshot",
4938
4945
  type: CommandType.COMMAND,
4939
4946
  handler: (accessor, params) => {
4947
+ var _docDataModel$getSelf;
4940
4948
  const { unitId, snapshot, textRanges, segmentId = "", options } = params;
4941
4949
  const univerInstanceService = accessor.get(IUniverInstanceService);
4942
4950
  const commandService = accessor.get(ICommandService);
4943
4951
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
4944
4952
  const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
4945
- 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();
4946
4954
  if (docDataModel == null || prevSnapshot == null) return false;
4947
4955
  const { body, tableSource, footers, headers, lists, drawings, drawingsOrder, documentStyle } = Tools.deepClone(snapshot);
4948
4956
  const { body: prevBody, tableSource: prevTableSource, footers: prevFooters, headers: prevHeaders, lists: prevLists, drawings: prevDrawings, drawingsOrder: prevDrawingsOrder, documentStyle: prevDocumentStyle } = prevSnapshot;
@@ -5011,12 +5019,13 @@ const ReplaceContentCommand = {
5011
5019
  id: "doc.command-replace-content",
5012
5020
  type: CommandType.COMMAND,
5013
5021
  handler: async (accessor, params) => {
5022
+ var _docDataModel$getSelf2;
5014
5023
  const { unitId, body, textRanges, segmentId = "", options } = params;
5015
5024
  const univerInstanceService = accessor.get(IUniverInstanceService);
5016
5025
  const commandService = accessor.get(ICommandService);
5017
5026
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
5018
5027
  const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
5019
- 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();
5020
5029
  if (docDataModel == null || prevBody == null) return false;
5021
5030
  const doMutation = getMutationParams(unitId, segmentId, docDataModel, prevBody, body);
5022
5031
  doMutation.params.textRanges = textRanges;
@@ -5040,7 +5049,7 @@ const CoverContentCommand = {
5040
5049
  const univerInstanceService = accessor.get(IUniverInstanceService);
5041
5050
  const commandService = accessor.get(ICommandService);
5042
5051
  const undoRedoService = accessor.get(IUndoRedoService);
5043
- const docDatModel = univerInstanceService.getUniverDocInstance(unitId);
5052
+ const docDatModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
5044
5053
  const prevBody = docDatModel === null || docDatModel === void 0 ? void 0 : docDatModel.getSnapshot().body;
5045
5054
  if (docDatModel == null || prevBody == null) return false;
5046
5055
  const doMutation = getMutationParams(unitId, segmentId, docDatModel, prevBody, body);
@@ -5115,12 +5124,13 @@ const ReplaceTextRunsCommand = {
5115
5124
  id: "doc.command.replace-text-runs",
5116
5125
  type: CommandType.COMMAND,
5117
5126
  handler: (accessor, params) => {
5127
+ var _docDataModel$getSelf3;
5118
5128
  const { unitId, body, textRanges, segmentId = "", options } = params;
5119
5129
  const univerInstanceService = accessor.get(IUniverInstanceService);
5120
5130
  const commandService = accessor.get(ICommandService);
5121
5131
  const themeService = accessor.get(ThemeService);
5122
5132
  const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
5123
- 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();
5124
5134
  if (docDataModel == null || prevBody == null) return false;
5125
5135
  const textX = BuildTextUtils.selection.replaceTextRuns({
5126
5136
  doc: docDataModel,
@@ -5196,8 +5206,8 @@ const ListOperationCommand = {
5196
5206
  if (docDataModel == null || docRanges.length === 0) return false;
5197
5207
  const segmentId = docRanges[0].segmentId;
5198
5208
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5199
- 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 : [];
5200
- 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 : "";
5201
5211
  if (!paragraphs.length) return false;
5202
5212
  const currentParagraphs = BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream);
5203
5213
  const unitId = docDataModel.getUnitId();
@@ -5238,8 +5248,8 @@ const ChangeListTypeCommand = {
5238
5248
  if (docDataModel == null || activeRanges == null || !activeRanges.length) return false;
5239
5249
  const { segmentId } = activeRanges[0];
5240
5250
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5241
- 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 : [];
5242
- 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 : "";
5243
5253
  if (!paragraphs.length) return false;
5244
5254
  const currentParagraphs = BuildTextUtils.range.getParagraphsInRanges(activeRanges, paragraphs, dataStream);
5245
5255
  const unitId = docDataModel.getUnitId();
@@ -5287,8 +5297,8 @@ const ChangeListNestingLevelCommand = {
5287
5297
  const { segmentId } = activeRange;
5288
5298
  const selections = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
5289
5299
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5290
- 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 : [];
5291
- 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 : "";
5292
5302
  if (!paragraphs.length) return false;
5293
5303
  const currentParagraphs = BuildTextUtils.range.getParagraphsInRange(activeRange, paragraphs, dataStream);
5294
5304
  const unitId = docDataModel.getUnitId();
@@ -5355,7 +5365,7 @@ const ToggleCheckListCommand = {
5355
5365
  const { index, segmentId, textRanges } = params;
5356
5366
  const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
5357
5367
  if (docDataModel == null) return false;
5358
- 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;
5359
5369
  const unitId = docDataModel.getUnitId();
5360
5370
  const doMutation = {
5361
5371
  id: RichTextEditingMutation.id,
@@ -5569,14 +5579,14 @@ const AlignOperationCommand = {
5569
5579
  const univerInstanceService = accessor.get(IUniverInstanceService);
5570
5580
  const commandService = accessor.get(ICommandService);
5571
5581
  const { alignType } = params;
5572
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
5582
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
5573
5583
  if (docDataModel == null) return false;
5574
5584
  const allRanges = docSelectionManagerService.getDocRanges();
5575
5585
  if (allRanges.length === 0) return false;
5576
5586
  const segmentId = allRanges[0].segmentId;
5577
5587
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5578
- 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 : [];
5579
- 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 : "";
5580
5590
  if (paragraphs == null) return false;
5581
5591
  const currentParagraphs = BuildTextUtils.range.getParagraphsInRanges(allRanges, paragraphs, dataStream);
5582
5592
  const unitId = docDataModel.getUnitId();
@@ -5680,27 +5690,21 @@ const SetDocZoomRatioCommand = {
5680
5690
  type: CommandType.COMMAND,
5681
5691
  id: "doc.command.set-zoom-ratio",
5682
5692
  handler: async (accessor, params) => {
5683
- var _univerInstanceServic;
5684
5693
  const commandService = accessor.get(ICommandService);
5685
5694
  const undoRedoService = accessor.get(IUndoRedoService);
5686
5695
  const univerInstanceService = accessor.get(IUniverInstanceService);
5687
- let documentId = (_univerInstanceServic = univerInstanceService.getCurrentUniverDocInstance()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
5688
- if (!documentId) return false;
5689
- let zoomRatio = 1;
5690
- if (params) {
5691
- var _params$documentId, _params$zoomRatio;
5692
- documentId = (_params$documentId = params.documentId) !== null && _params$documentId !== void 0 ? _params$documentId : documentId;
5693
- zoomRatio = (_params$zoomRatio = params.zoomRatio) !== null && _params$zoomRatio !== void 0 ? _params$zoomRatio : zoomRatio;
5694
- }
5695
- 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();
5696
5700
  const setZoomRatioMutationParams = {
5697
5701
  zoomRatio,
5698
- unitId: documentId
5702
+ unitId
5699
5703
  };
5700
5704
  const undoMutationParams = SetDocZoomRatioUndoMutationFactory(accessor, setZoomRatioMutationParams);
5701
5705
  if (commandService.syncExecuteCommand(SetDocZoomRatioOperation.id, setZoomRatioMutationParams)) {
5702
5706
  undoRedoService.pushUndoRedo({
5703
- unitID: documentId,
5707
+ unitID: unitId,
5704
5708
  undoMutations: [{
5705
5709
  id: SetDocZoomRatioOperation.id,
5706
5710
  params: undoMutationParams
@@ -5736,8 +5740,10 @@ const SetParagraphNamedStyleCommand = {
5736
5740
  });
5737
5741
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return false;
5738
5742
  const segmentId = selections[0].segmentId;
5743
+ const documentDataModel = doc.getSelfOrHeaderFooterModel(segmentId);
5744
+ if (!documentDataModel) return false;
5739
5745
  const textX = BuildTextUtils.paragraph.style.set({
5740
- document: doc.getSelfOrHeaderFooterModel(segmentId),
5746
+ document: documentDataModel,
5741
5747
  textRanges: selections,
5742
5748
  style: {
5743
5749
  namedStyleType: params.value,
@@ -5764,13 +5770,6 @@ const SetParagraphNamedStyleCommand = {
5764
5770
  return Boolean(result);
5765
5771
  }
5766
5772
  };
5767
- function consumeContentInsertRange(accessor, unitId) {
5768
- try {
5769
- return accessor.get(DocContentInsertService).consumeInsertRange(unitId);
5770
- } catch {
5771
- return null;
5772
- }
5773
- }
5774
5773
  function insertNamedStyleParagraph(accessor, doc, namedStyleType, startOffset, endOffset) {
5775
5774
  const textX = BuildTextUtils.selection.replace({
5776
5775
  doc,
@@ -5820,8 +5819,8 @@ const QuickHeadingCommand = {
5820
5819
  if (docDataModel == null || activeRange == null || !activeRange.collapsed) return false;
5821
5820
  const { segmentId, startOffset } = activeRange;
5822
5821
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5823
- 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 : [];
5824
- 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 : "";
5825
5824
  const paragraph = BuildTextUtils.paragraph.util.getParagraphsInRange(activeRange, paragraphs, dataStream)[0];
5826
5825
  if (!paragraph) return false;
5827
5826
  const { paragraphStart } = paragraph;
@@ -6206,14 +6205,17 @@ var NodePositionConvertToCursor = class {
6206
6205
  this._resetCurrentNodePositionState();
6207
6206
  if (this._documentOffsetConfig == null) return [];
6208
6207
  const { pageLayoutType, pageMarginLeft, pageMarginTop } = this._documentOffsetConfig;
6209
- 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;
6210
6211
  for (let p = 0; p < skipPageIndex; p++) {
6211
6212
  const page = pages[p];
6212
6213
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6213
6214
  }
6214
- const endIndex = pageType === DocumentSkeletonPageType.BODY || pageType === DocumentSkeletonPageType.CELL ? endPageIndex : endSegmentPage;
6215
+ const endIndex = pageType === DocumentSkeletonPageType.BODY || pageType === DocumentSkeletonPageType.CELL ? endRootPageIndex : endSegmentPage;
6215
6216
  for (let p = skipPageIndex; p <= endIndex; p++) {
6216
6217
  const page = pages[p];
6218
+ if (page == null) continue;
6217
6219
  const { headerId, footerId, pageWidth } = page;
6218
6220
  let segmentPage = page;
6219
6221
  if (pageType === DocumentSkeletonPageType.HEADER) {
@@ -6222,7 +6224,7 @@ var NodePositionConvertToCursor = class {
6222
6224
  } else if (pageType === DocumentSkeletonPageType.FOOTER) {
6223
6225
  var _skeFooters$get;
6224
6226
  segmentPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
6225
- } 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);
6226
6228
  if (segmentPage == null) {
6227
6229
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
6228
6230
  continue;
@@ -6252,7 +6254,6 @@ var NodePositionConvertToCursor = class {
6252
6254
  this._liquid.translatePagePadding(segmentPage);
6253
6255
  break;
6254
6256
  }
6255
- this._liquid.translatePagePadding(page);
6256
6257
  const rowSke = segmentPage.parent;
6257
6258
  const tableSke = rowSke.parent;
6258
6259
  const tablePage = tableSke.parent;
@@ -6264,6 +6265,14 @@ var NodePositionConvertToCursor = class {
6264
6265
  const viewport = getDocsTableRenderViewport(getDocumentUnitId$1(skeleton), sourceTableId);
6265
6266
  const hasHorizontalViewport = hasHorizontalTableViewport$2(viewport);
6266
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);
6267
6276
  if (tablePageNestedOffset) {
6268
6277
  this._liquid.translate(tablePageNestedOffset.left, tablePageNestedOffset.top);
6269
6278
  this._liquid.translatePagePadding(tablePage);
@@ -6339,6 +6348,28 @@ function clipPositionToHorizontalRange(position, clip) {
6339
6348
  endX
6340
6349
  };
6341
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
+ }
6342
6373
  function getDocumentUnitId$1(docSkeleton) {
6343
6374
  var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3, _viewModel$getDataMod4;
6344
6375
  const viewModel = docSkeleton.getViewModel();
@@ -6492,9 +6523,12 @@ var NodePositionConvertToRectRange = class {
6492
6523
  docsLeft: (_this$_documentOffset = this._documentOffsetConfig.docsLeft) !== null && _this$_documentOffset !== void 0 ? _this$_documentOffset : 0,
6493
6524
  docsTop: (_this$_documentOffset2 = this._documentOffsetConfig.docsTop) !== null && _this$_documentOffset2 !== void 0 ? _this$_documentOffset2 : 0,
6494
6525
  pageMarginTop,
6526
+ skeFooters: skeletonData === null || skeletonData === void 0 ? void 0 : skeletonData.skeFooters,
6527
+ skeHeaders: skeletonData === null || skeletonData === void 0 ? void 0 : skeletonData.skeHeaders,
6495
6528
  unitId
6496
6529
  });
6497
- const skipPageIndex = pageType === DocumentSkeletonPageType.BODY || pageType === DocumentSkeletonPageType.CELL ? startPage : startSegmentPage;
6530
+ const startRootPage = pageType === DocumentSkeletonPageType.CELL && pages[startPage] == null ? startSegmentPage : startPage;
6531
+ const skipPageIndex = pageType === DocumentSkeletonPageType.BODY || pageType === DocumentSkeletonPageType.CELL ? startRootPage : startSegmentPage;
6498
6532
  for (let p = 0; p < skipPageIndex; p++) {
6499
6533
  const page = pages[p];
6500
6534
  this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
@@ -6506,12 +6540,13 @@ var NodePositionConvertToRectRange = class {
6506
6540
  let table = null;
6507
6541
  for (const [id, tableSke] of skeTables.entries()) if (id.startsWith(tableId)) table = tableSke;
6508
6542
  if (table == null) {
6509
- const nestedTableContext = nestedTableContexts.find((context) => context.pageIndex === p && context.source === "column" && context.tableId.startsWith(tableId));
6543
+ const nestedTableContext = nestedTableContexts.find((context) => context.pageIndex === p && (context.source === "column" || context.source === "header" || context.source === "footer") && context.tableId.startsWith(tableId));
6510
6544
  if (nestedTableContext) {
6545
+ var _this$_documentOffset3, _this$_documentOffset4;
6511
6546
  const nestedTable = nestedTableContext.table;
6512
6547
  const viewport = getDocsTableRenderViewport(unitId, sourceTableId);
6513
- const nestedX = nestedTableContext.tableRect.left - nestedTable.left;
6514
- const nestedY = nestedTableContext.tableRect.top;
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);
6515
6550
  if (intersectsMergedCell) {
6516
6551
  const rows = nestedTable.rows.filter((row) => row.index >= startRow && row.index <= endRow);
6517
6552
  const firstRow = rows[0];
@@ -6642,8 +6677,8 @@ var NodePositionConvertToRectRange = class {
6642
6677
  const { path: anchorPath } = anchorPosition;
6643
6678
  const { path: focusPath } = focusPosition;
6644
6679
  if (anchorPath.indexOf("cells") === -1 || focusPath.indexOf("cells") === -1) return;
6645
- const anchorCell = getPageFromPath(skeletonData, anchorPath);
6646
- const focusCell = getPageFromPath(skeletonData, focusPath);
6680
+ const anchorCell = getCellPageFromPositionPath(skeletonData, anchorPosition);
6681
+ const focusCell = getCellPageFromPositionPath(skeletonData, focusPosition);
6647
6682
  if (anchorCell == null || focusCell == null) return;
6648
6683
  const anchorRow = anchorCell.parent;
6649
6684
  const focusRow = focusCell.parent;
@@ -6719,6 +6754,28 @@ function rangeIntersectsMergedCell(table, range) {
6719
6754
  });
6720
6755
  }));
6721
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
+ }
6722
6779
  function normalizeRange(range) {
6723
6780
  return {
6724
6781
  startRowIndex: Math.min(range.startRowIndex, range.endRowIndex),
@@ -6811,17 +6868,17 @@ var TextRange = class {
6811
6868
  }, 1e3);
6812
6869
  }
6813
6870
  get startOffset() {
6814
- var _getOneTextSelectionR;
6871
+ var _getOneTextSelectionR, _this$_docSkeleton$ge;
6815
6872
  const { startOffset } = (_getOneTextSelectionR = getOneTextSelectionRange(this._cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
6816
- 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();
6817
6874
  if (startOffset == null || body == null) return startOffset;
6818
6875
  const maxLength = body.dataStream.length - 2;
6819
6876
  return Math.min(maxLength, startOffset);
6820
6877
  }
6821
6878
  get endOffset() {
6822
- var _getOneTextSelectionR2;
6879
+ var _getOneTextSelectionR2, _this$_docSkeleton$ge2;
6823
6880
  const { endOffset } = (_getOneTextSelectionR2 = getOneTextSelectionRange(this._cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
6824
- 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();
6825
6882
  if (endOffset == null || body == null) return endOffset;
6826
6883
  const maxLength = body.dataStream.length - 2;
6827
6884
  return Math.min(endOffset, maxLength);
@@ -8221,7 +8278,7 @@ const SwitchDocModeCommand = {
8221
8278
  const commandService = accessor.get(ICommandService);
8222
8279
  const renderManagerService = accessor.get(IRenderManagerService);
8223
8280
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8224
- const docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
8281
+ const docDataModel = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
8225
8282
  if (docDataModel == null) return false;
8226
8283
  const unitId = docDataModel.getUnitId();
8227
8284
  const skeleton = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getSkeleton();
@@ -8326,6 +8383,18 @@ function shouldCreateParagraphBeforeTable(body, startOffset) {
8326
8383
  function normalizeTableInsertOffset(body, startOffset) {
8327
8384
  return startOffset === 0 && body.dataStream[0] === DataStreamTreeTokenType.PARAGRAPH ? 1 : startOffset;
8328
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
+ }
8329
8398
  /**
8330
8399
  * The command to create a table at cursor point.
8331
8400
  */
@@ -8333,13 +8402,13 @@ const CreateDocTableCommand = {
8333
8402
  id: CreateDocTableCommandId,
8334
8403
  type: CommandType.COMMAND,
8335
8404
  handler: async (accessor, params) => {
8336
- 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;
8337
8406
  const { rowCount, colCount } = params;
8338
8407
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8339
8408
  const univerInstanceService = accessor.get(IUniverInstanceService);
8340
8409
  const commandService = accessor.get(ICommandService);
8341
8410
  const docMenuStyleService = accessor.get(DocMenuStyleService);
8342
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8411
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
8343
8412
  if (docDataModel == null) return false;
8344
8413
  let contentInsertRange = null;
8345
8414
  try {
@@ -8351,13 +8420,14 @@ const CreateDocTableCommand = {
8351
8420
  if (activeRange == null && contentInsertRange == null) return false;
8352
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 : "";
8353
8422
  const segmentPage = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentPage;
8354
- 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();
8355
8424
  if (body == null) return false;
8356
8425
  const unitId = docDataModel.getUnitId();
8357
8426
  const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
8358
8427
  const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
8359
8428
  if (skeleton == null) return false;
8360
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;
8361
8431
  const prevParagraph = ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).find((p) => p.startIndex >= startOffset);
8362
8432
  const curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
8363
8433
  if (curGlyph == null) return false;
@@ -8428,6 +8498,7 @@ const DocTableDeleteRowsCommand = {
8428
8498
  id: "doc.table.delete-rows",
8429
8499
  type: CommandType.COMMAND,
8430
8500
  handler: async (accessor) => {
8501
+ var _docDataModel$getSelf;
8431
8502
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8432
8503
  const univerInstanceService = accessor.get(IUniverInstanceService);
8433
8504
  const commandService = accessor.get(ICommandService);
@@ -8435,8 +8506,8 @@ const DocTableDeleteRowsCommand = {
8435
8506
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8436
8507
  if (rangeInfo == null) return false;
8437
8508
  const { segmentId } = rangeInfo;
8438
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8439
- 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();
8440
8511
  if (docDataModel == null || body == null) return false;
8441
8512
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8442
8513
  if (docSkeletonManagerService == null) return false;
@@ -8492,6 +8563,7 @@ const DocTableDeleteColumnsCommand = {
8492
8563
  id: "doc.table.delete-columns",
8493
8564
  type: CommandType.COMMAND,
8494
8565
  handler: async (accessor) => {
8566
+ var _docDataModel$getSelf2;
8495
8567
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8496
8568
  const univerInstanceService = accessor.get(IUniverInstanceService);
8497
8569
  const commandService = accessor.get(ICommandService);
@@ -8499,8 +8571,8 @@ const DocTableDeleteColumnsCommand = {
8499
8571
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8500
8572
  if (rangeInfo == null) return false;
8501
8573
  const { segmentId } = rangeInfo;
8502
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8503
- 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();
8504
8576
  if (docDataModel == null || body == null) return false;
8505
8577
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8506
8578
  if (docSkeletonManagerService == null) return false;
@@ -8571,6 +8643,7 @@ const DocTableDeleteTableCommand = {
8571
8643
  id: "doc.table.delete-table",
8572
8644
  type: CommandType.COMMAND,
8573
8645
  handler: async (accessor) => {
8646
+ var _docDataModel$getSelf3;
8574
8647
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8575
8648
  const univerInstanceService = accessor.get(IUniverInstanceService);
8576
8649
  const commandService = accessor.get(ICommandService);
@@ -8578,8 +8651,8 @@ const DocTableDeleteTableCommand = {
8578
8651
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8579
8652
  if (rangeInfo == null) return false;
8580
8653
  const { segmentId } = rangeInfo;
8581
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8582
- 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();
8583
8656
  if (docDataModel == null || body == null) return false;
8584
8657
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8585
8658
  if (docSkeletonManagerService == null) return false;
@@ -8667,6 +8740,7 @@ const DocTableInsertRowCommand = {
8667
8740
  id: DocTableInsertRowCommandId,
8668
8741
  type: CommandType.COMMAND,
8669
8742
  handler: async (accessor, params) => {
8743
+ var _docDataModel$getSelf;
8670
8744
  const { position } = params;
8671
8745
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8672
8746
  const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -8676,7 +8750,7 @@ const DocTableInsertRowCommand = {
8676
8750
  if (rangeInfo == null) return false;
8677
8751
  const { segmentId } = rangeInfo;
8678
8752
  const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
8679
- 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();
8680
8754
  if (docDataModel == null || body == null) return false;
8681
8755
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8682
8756
  if (docSkeletonManagerService == null) return false;
@@ -8736,7 +8810,7 @@ const DocTableInsertColumnCommand = {
8736
8810
  id: DocTableInsertColumnCommandId,
8737
8811
  type: CommandType.COMMAND,
8738
8812
  handler: async (accessor, params) => {
8739
- var _snapshot$tableSource, _documentStyle$pageSi, _documentStyle$pageSi2;
8813
+ var _docDataModel$getSelf2, _snapshot$tableSource, _documentStyle$pageSi, _documentStyle$pageSi2;
8740
8814
  const { position } = params;
8741
8815
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
8742
8816
  const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -8745,8 +8819,8 @@ const DocTableInsertColumnCommand = {
8745
8819
  const rangeInfo = getRangeInfoFromRanges(docSelectionManagerService.getActiveTextRange(), activeRectRanges);
8746
8820
  if (rangeInfo == null) return false;
8747
8821
  const { segmentId } = rangeInfo;
8748
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
8749
- 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();
8750
8824
  if (docDataModel == null || body == null) return false;
8751
8825
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
8752
8826
  if (docSkeletonManagerService == null) return false;
@@ -8845,7 +8919,7 @@ const DocTableTabCommand = {
8845
8919
  const textSelectionManager = accessor.get(DocSelectionManagerService);
8846
8920
  const docRanges = textSelectionManager.getDocRanges();
8847
8921
  const commandService = accessor.get(ICommandService);
8848
- const docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
8922
+ const docDataModel = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
8849
8923
  if (!docDataModel) return false;
8850
8924
  const activeRange = (_docRanges$find = docRanges.find((range) => range.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
8851
8925
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
@@ -9398,7 +9472,7 @@ let EditorService = class EditorService extends Disposable {
9398
9472
  this._univerInstanceService.disposeUnit(editorUnitId);
9399
9473
  }
9400
9474
  _getCurrentEditorUnitId() {
9401
- return this._univerInstanceService.getCurrentUniverDocInstance().getUnitId();
9475
+ return this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC).getUnitId();
9402
9476
  }
9403
9477
  _getBlank(id) {
9404
9478
  return {
@@ -10055,325 +10129,138 @@ function findFirstCursorOffset(snapshot) {
10055
10129
  }
10056
10130
 
10057
10131
  //#endregion
10058
- //#region src/views/header-footer/text-bubble.ts
10059
- const COLLAB_CURSOR_LABEL_HEIGHT = 18;
10060
- const COLLAB_CURSOR_LABEL_MAX_WIDTH = 200;
10061
- const COLLAB_CURSOR_LABEL_TEXT_PADDING_LR = 6;
10062
- const COLLAB_CURSOR_LABEL_TEXT_PADDING_TB = 4;
10063
- function drawBubble(ctx, props) {
10064
- var _radius, _width, _height;
10065
- let { radius, width, height } = props;
10066
- radius = (_radius = radius) !== null && _radius !== void 0 ? _radius : 0;
10067
- width = (_width = width) !== null && _width !== void 0 ? _width : 30;
10068
- height = (_height = height) !== null && _height !== void 0 ? _height : 30;
10069
- let bottomRight = 0;
10070
- bottomRight = Math.min(radius, width / 2, height / 2);
10071
- ctx.beginPath();
10072
- ctx.moveTo(0, 0);
10073
- ctx.lineTo(width, 0);
10074
- ctx.lineTo(width, height - bottomRight);
10075
- ctx.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
10076
- ctx.lineTo(0, height);
10077
- ctx.lineTo(0, 0);
10078
- ctx.closePath();
10079
- if (props.fill) {
10080
- ctx.save();
10081
- ctx.fillStyle = props.fill;
10082
- if (props.fillRule === "evenodd") ctx.fill("evenodd");
10083
- else ctx.fill();
10084
- ctx.restore();
10085
- }
10086
- }
10132
+ //#region src/views/header-footer/panel/component-name.ts
10087
10133
  /**
10088
- * 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.
10089
10147
  */
10090
- var TextBubbleShape = class TextBubbleShape extends Shape {
10091
- constructor(key, props) {
10092
- super(key, props);
10093
- _defineProperty(this, "color", void 0);
10094
- _defineProperty(this, "text", void 0);
10095
- this.color = props === null || props === void 0 ? void 0 : props.color;
10096
- this.text = props === null || props === void 0 ? void 0 : props.text;
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;
10097
10172
  }
10098
- static drawWith(ctx, props) {
10099
- const { text, color } = props;
10100
- ctx.save();
10101
- ctx.font = "13px Source Han Sans CN";
10102
- const textWidth = ctx.measureText(text).width;
10103
- drawBubble(ctx, {
10104
- height: 18,
10105
- width: Math.min(textWidth + 2 * 6, 200),
10106
- radius: 4,
10107
- fill: color,
10108
- evented: false
10173
+ };
10174
+
10175
+ //#endregion
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"
10109
10208
  });
10110
- ctx.fillStyle = "rgba(58, 96, 247, 1)";
10111
- const offsetX = 6;
10112
- const offsetY = 18 - 4;
10113
- const maxTextWidth = 200 - 2 * 6;
10114
- if (textWidth > maxTextWidth) {
10115
- let truncatedText = "";
10116
- let currentWidth = 0;
10117
- for (const element of text) {
10118
- const charWidth = ctx.measureText(element).width;
10119
- if (currentWidth + charWidth <= maxTextWidth - ctx.measureText("...").width) {
10120
- truncatedText += element;
10121
- currentWidth += charWidth;
10122
- } else {
10123
- truncatedText += "...";
10124
- break;
10125
- }
10126
- }
10127
- ctx.fillText(truncatedText, offsetX, offsetY);
10128
- } else ctx.fillText(text, offsetX, offsetY);
10129
- ctx.restore();
10130
10209
  }
10131
- _draw(ctx) {
10132
- TextBubbleShape.drawWith(ctx, this);
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" });
10216
+ }
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;
10133
10259
  }
10134
10260
  };
10135
10261
 
10136
10262
  //#endregion
10137
- //#region src/controllers/doc-header-footer.controller.ts
10138
- const HEADER_FOOTER_STROKE_COLOR = "rgba(58, 96, 247, 1)";
10139
- const HEADER_FOOTER_FILL_COLOR = "rgba(58, 96, 247, 0.08)";
10140
- function checkCreateHeaderFooterType(viewModel, editArea, segmentPage) {
10141
- const { documentStyle } = viewModel.getDataModel().getSnapshot();
10142
- const { defaultHeaderId, defaultFooterId, evenPageHeaderId, evenPageFooterId, firstPageHeaderId, firstPageFooterId, evenAndOddHeaders, useFirstPageHeaderFooter } = documentStyle;
10143
- switch (editArea) {
10144
- case DocumentEditArea.BODY: return {
10145
- createType: null,
10146
- headerFooterId: null
10147
- };
10148
- case DocumentEditArea.HEADER:
10149
- if (useFirstPageHeaderFooter === BooleanNumber.TRUE && !firstPageHeaderId) return {
10150
- createType: 0,
10151
- headerFooterId: null
10152
- };
10153
- if (evenAndOddHeaders === BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageHeaderId) return {
10154
- createType: 4,
10155
- headerFooterId: null
10156
- };
10157
- return defaultHeaderId ? {
10158
- createType: null,
10159
- headerFooterId: defaultHeaderId
10160
- } : {
10161
- createType: 2,
10162
- headerFooterId: null
10163
- };
10164
- case DocumentEditArea.FOOTER:
10165
- if (useFirstPageHeaderFooter === BooleanNumber.TRUE && !firstPageFooterId) return {
10166
- createType: 1,
10167
- headerFooterId: null
10168
- };
10169
- if (evenAndOddHeaders === BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageFooterId) return {
10170
- createType: 5,
10171
- headerFooterId: null
10172
- };
10173
- return defaultFooterId ? {
10174
- createType: null,
10175
- headerFooterId: defaultFooterId
10176
- } : {
10177
- createType: 3,
10178
- headerFooterId: null
10179
- };
10180
- default: throw new Error(`Invalid editArea: ${editArea}`);
10181
- }
10182
- }
10183
- let DocHeaderFooterController = class DocHeaderFooterController extends Disposable {
10184
- constructor(_context, _commandService, _editorService, _instanceSrv, _renderManagerService, _docSkeletonManagerService, _docSelectionRenderService, _localeService) {
10185
- super();
10186
- this._context = _context;
10187
- this._commandService = _commandService;
10188
- this._editorService = _editorService;
10189
- this._instanceSrv = _instanceSrv;
10190
- this._renderManagerService = _renderManagerService;
10191
- this._docSkeletonManagerService = _docSkeletonManagerService;
10192
- this._docSelectionRenderService = _docSelectionRenderService;
10193
- this._localeService = _localeService;
10194
- _defineProperty(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
10195
- this._initialize();
10196
- }
10197
- _initialize() {
10198
- this._init();
10199
- this._drawHeaderFooterLabel();
10200
- this._listenSwitchMode();
10201
- }
10202
- dispose() {
10203
- super.dispose();
10204
- }
10205
- _listenSwitchMode() {
10206
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
10207
- if (RichTextEditingMutation.id === command.id) {
10208
- const docDataModel = this._context.unit;
10209
- const editArea = this._docSkeletonManagerService.getViewModel().getEditArea();
10210
- const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
10211
- if (editArea !== DocumentEditArea.BODY && documentFlavor === DocumentFlavor.MODERN) this._commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId: this._context.unitId });
10212
- }
10213
- }));
10214
- }
10215
- _init() {
10216
- const { unitId } = this._context;
10217
- const docObject = neoGetDocObject(this._context);
10218
- if (docObject == null || docObject.document == null) return;
10219
- if (!this._loadedMap.has(docObject.document)) {
10220
- this._initialMain(unitId);
10221
- this._loadedMap.add(docObject.document);
10222
- }
10223
- }
10224
- _initialMain(unitId) {
10225
- const { document } = neoGetDocObject(this._context);
10226
- this.disposeWithMe(document.onDblclick$.subscribeEvent(async (evt) => {
10227
- if (this._isEditorReadOnly(unitId)) return;
10228
- if (!this._isTraditionalMode()) return;
10229
- const { offsetX, offsetY } = evt;
10230
- const { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = document.getOffsetConfig();
10231
- const coord = this._getTransformCoordForDocumentOffset(offsetX, offsetY);
10232
- if (coord == null) return;
10233
- const viewModel = this._docSkeletonManagerService.getViewModel();
10234
- const skeleton = this._docSkeletonManagerService.getSkeleton();
10235
- const preEditArea = viewModel.getEditArea();
10236
- const { editArea, pageNumber } = skeleton.findEditAreaByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop);
10237
- if (preEditArea === editArea) return;
10238
- viewModel.setEditArea(editArea);
10239
- const { createType, headerFooterId } = checkCreateHeaderFooterType(viewModel, editArea, pageNumber);
10240
- if (editArea === DocumentEditArea.BODY) {
10241
- this._docSelectionRenderService.setSegment("");
10242
- this._docSelectionRenderService.setSegmentPage(-1);
10243
- this._docSelectionRenderService.setCursorManually(offsetX, offsetY);
10244
- } else if (createType != null) {
10245
- const segmentId = generateRandomId(6);
10246
- this._docSelectionRenderService.setSegment(segmentId);
10247
- this._docSelectionRenderService.setSegmentPage(pageNumber);
10248
- await this._commandService.executeCommand(CoreHeaderFooterCommand.id, {
10249
- unitId,
10250
- createType,
10251
- segmentId
10252
- });
10253
- } else if (headerFooterId != null) {
10254
- this._docSelectionRenderService.setSegment(headerFooterId);
10255
- this._docSelectionRenderService.setSegmentPage(pageNumber);
10256
- this._docSelectionRenderService.setCursorManually(offsetX, offsetY);
10257
- }
10258
- }));
10259
- }
10260
- _getTransformCoordForDocumentOffset(evtOffsetX, evtOffsetY) {
10261
- const { document, scene } = neoGetDocObject(this._context);
10262
- const { documentTransform } = document.getOffsetConfig();
10263
- const activeViewport = scene.getViewports()[0];
10264
- if (activeViewport == null) return;
10265
- const originCoord = activeViewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
10266
- return documentTransform.clone().invert().applyPoint(originCoord);
10267
- }
10268
- _drawHeaderFooterLabel() {
10269
- const localeService = this._localeService;
10270
- this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).subscribe((unit) => {
10271
- if (unit == null) return;
10272
- const unitId = unit.getUnitId();
10273
- const currentRender = this._renderManagerService.getRenderById(unitId);
10274
- if (this._editorService.isEditor(unitId) || this._instanceSrv.getUniverDocInstance(unitId) == null) return;
10275
- if (currentRender == null) return;
10276
- const { mainComponent } = currentRender;
10277
- const docsComponent = mainComponent;
10278
- this.disposeWithMe(toDisposable(docsComponent.pageRender$.subscribe((config) => {
10279
- if (this._editorService.isEditor(unitId)) return;
10280
- if (!this._isTraditionalMode()) return;
10281
- const isEditBody = this._docSkeletonManagerService.getViewModel().getEditArea() === DocumentEditArea.BODY;
10282
- const { page, pageLeft, pageTop, ctx } = config;
10283
- const { pageWidth, pageHeight, marginTop, marginBottom } = page;
10284
- ctx.save();
10285
- ctx.translate(pageLeft - .5, pageTop - .5);
10286
- if (isEditBody) {
10287
- Rect.drawWith(ctx, {
10288
- left: 0,
10289
- top: 0,
10290
- width: pageWidth,
10291
- height: marginTop,
10292
- fill: "rgba(255, 255, 255, 0.5)"
10293
- });
10294
- ctx.save();
10295
- ctx.translate(0, pageHeight - marginBottom);
10296
- Rect.drawWith(ctx, {
10297
- left: 0,
10298
- top: 0,
10299
- width: pageWidth,
10300
- height: marginBottom,
10301
- fill: "rgba(255, 255, 255, 0.5)"
10302
- });
10303
- ctx.restore();
10304
- } else {
10305
- ctx.save();
10306
- ctx.translate(0, marginTop);
10307
- Rect.drawWith(ctx, {
10308
- left: 0,
10309
- top: marginTop,
10310
- width: pageWidth,
10311
- height: pageHeight - marginTop - marginBottom,
10312
- fill: "rgba(255, 255, 255, 0.5)"
10313
- });
10314
- ctx.restore();
10315
- }
10316
- if (!isEditBody) {
10317
- const headerPathConfigIPathProps = {
10318
- dataArray: [{
10319
- command: "M",
10320
- points: [0, marginTop]
10321
- }, {
10322
- command: "L",
10323
- points: [pageWidth, marginTop]
10324
- }],
10325
- strokeWidth: 1,
10326
- stroke: HEADER_FOOTER_STROKE_COLOR
10327
- };
10328
- const footerPathConfigIPathProps = {
10329
- dataArray: [{
10330
- command: "M",
10331
- points: [0, pageHeight - marginBottom]
10332
- }, {
10333
- command: "L",
10334
- points: [pageWidth, pageHeight - marginBottom]
10335
- }],
10336
- strokeWidth: 1,
10337
- stroke: HEADER_FOOTER_STROKE_COLOR
10338
- };
10339
- Path.drawWith(ctx, headerPathConfigIPathProps);
10340
- Path.drawWith(ctx, footerPathConfigIPathProps);
10341
- ctx.translate(0, marginTop + 1);
10342
- TextBubbleShape.drawWith(ctx, {
10343
- text: localeService.t("docs-ui.headerFooter.header"),
10344
- color: HEADER_FOOTER_FILL_COLOR
10345
- });
10346
- ctx.translate(0, pageHeight - marginTop - marginBottom);
10347
- TextBubbleShape.drawWith(ctx, {
10348
- text: localeService.t("docs-ui.headerFooter.footer"),
10349
- color: HEADER_FOOTER_FILL_COLOR
10350
- });
10351
- }
10352
- ctx.restore();
10353
- })));
10354
- }));
10355
- }
10356
- _isEditorReadOnly(unitId) {
10357
- const editor = this._editorService.getEditor(unitId);
10358
- if (!editor) return false;
10359
- return editor.isReadOnly();
10360
- }
10361
- _isTraditionalMode() {
10362
- return this._context.unit.getSnapshot().documentStyle.documentFlavor === DocumentFlavor.TRADITIONAL;
10363
- }
10364
- };
10365
- DocHeaderFooterController = __decorate([
10366
- __decorateParam(1, ICommandService),
10367
- __decorateParam(2, IEditorService),
10368
- __decorateParam(3, IUniverInstanceService),
10369
- __decorateParam(4, IRenderManagerService),
10370
- __decorateParam(5, Inject(DocSkeletonManagerService)),
10371
- __decorateParam(6, Inject(DocSelectionRenderService)),
10372
- __decorateParam(7, Inject(LocaleService))
10373
- ], DocHeaderFooterController);
10374
-
10375
- //#endregion
10376
- //#region src/views/header-footer/panel/component-name.ts
10263
+ //#region src/controllers/doc-paragraph-setting.controller.ts
10377
10264
  /**
10378
10265
  * Copyright 2023-present DreamNum Co., Ltd.
10379
10266
  *
@@ -10389,261 +10276,36 @@ DocHeaderFooterController = __decorate([
10389
10276
  * See the License for the specific language governing permissions and
10390
10277
  * limitations under the License.
10391
10278
  */
10392
- const COMPONENT_DOC_HEADER_FOOTER_PANEL = "COMPONENT_DOC_HEADER_FOOTER_PANEL";
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);
10393
10301
 
10394
10302
  //#endregion
10395
- //#region src/commands/operations/doc-header-footer-panel.operation.ts
10396
- const SidebarDocHeaderFooterPanelOperation = {
10397
- id: "sidebar.operation.doc-header-footer-panel",
10303
+ //#region src/commands/operations/doc-paragraph-setting-panel.operation.ts
10304
+ const DocParagraphSettingPanelOperation = {
10305
+ id: "sidebar.operation.doc-paragraph-setting-panel",
10398
10306
  type: CommandType.OPERATION,
10399
- handler: async (accessor, params) => {
10400
- const sidebarService = accessor.get(ISidebarService);
10401
- const localeService = accessor.get(LocaleService);
10402
- switch (params.value) {
10403
- case "open":
10404
- sidebarService.open({
10405
- header: { title: localeService.t("docs-ui.headerFooter.panel") },
10406
- children: { label: COMPONENT_DOC_HEADER_FOOTER_PANEL },
10407
- onClose: () => {},
10408
- width: 400
10409
- });
10410
- break;
10411
- default:
10412
- sidebarService.close();
10413
- break;
10414
- }
10415
- return true;
10416
- }
10417
- };
10418
-
10419
- //#endregion
10420
- //#region src/commands/commands/doc-header-footer.command.ts
10421
- function getEmptyHeaderFooterBody() {
10422
- return {
10423
- dataStream: "\r\n",
10424
- textRuns: [{
10425
- st: 0,
10426
- ed: 0,
10427
- ts: { fs: 9 }
10428
- }],
10429
- customBlocks: [],
10430
- paragraphs: [{
10431
- startIndex: 0,
10432
- paragraphId: createParagraphId(/* @__PURE__ */ new Set()),
10433
- paragraphStyle: {
10434
- spaceAbove: { v: 0 },
10435
- lineSpacing: 1.5,
10436
- spaceBelow: { v: 0 }
10437
- }
10438
- }],
10439
- sectionBreaks: [{ startIndex: 1 }]
10440
- };
10441
- }
10442
- function createHeaderFooterAction(segmentId, createType, documentStyle, actions) {
10443
- const jsonX = JSONX.getInstance();
10444
- const ID_LEN = 6;
10445
- const firstSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : generateRandomId(ID_LEN);
10446
- const isHeader = createType === 2 || createType === 0 || createType === 4;
10447
- const insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
10448
- [isHeader ? "headerId" : "footerId"]: firstSegmentId,
10449
- body: getEmptyHeaderFooterBody()
10450
- });
10451
- actions.push(insertAction);
10452
- const secondSegmentId = generateRandomId(ID_LEN);
10453
- const insertPairAction = jsonX.insertOp([isHeader ? "footers" : "headers", secondSegmentId], {
10454
- [isHeader ? "footerId" : "headerId"]: secondSegmentId,
10455
- body: getEmptyHeaderFooterBody()
10456
- });
10457
- actions.push(insertPairAction);
10458
- let key = "defaultHeaderId";
10459
- let pairKey = "defaultFooterId";
10460
- switch (createType) {
10461
- case 2:
10462
- key = "defaultHeaderId";
10463
- pairKey = "defaultFooterId";
10464
- break;
10465
- case 3:
10466
- key = "defaultFooterId";
10467
- pairKey = "defaultHeaderId";
10468
- break;
10469
- case 0:
10470
- key = "firstPageHeaderId";
10471
- pairKey = "firstPageFooterId";
10472
- break;
10473
- case 1:
10474
- key = "firstPageFooterId";
10475
- pairKey = "firstPageHeaderId";
10476
- break;
10477
- case 4:
10478
- key = "evenPageHeaderId";
10479
- pairKey = "evenPageFooterId";
10480
- break;
10481
- case 5:
10482
- key = "evenPageFooterId";
10483
- pairKey = "evenPageHeaderId";
10484
- break;
10485
- default: throw new Error(`Unknown header footer type: ${createType}`);
10486
- }
10487
- for (const [k, id] of [[key, firstSegmentId], [pairKey, secondSegmentId]]) if (documentStyle[k] != null) {
10488
- const replaceAction = jsonX.replaceOp(["documentStyle", k], documentStyle[k], id);
10489
- actions.push(replaceAction);
10490
- } else {
10491
- const insertAction = jsonX.insertOp(["documentStyle", k], id);
10492
- actions.push(insertAction);
10493
- }
10494
- return actions;
10495
- }
10496
- const CoreHeaderFooterCommandId = "doc.command.core-header-footer";
10497
- /**
10498
- * The command to update header and footer or create them.
10499
- */
10500
- const CoreHeaderFooterCommand = {
10501
- id: CoreHeaderFooterCommandId,
10502
- type: CommandType.COMMAND,
10503
- handler: async (accessor, params) => {
10504
- var _renderManagerService;
10505
- const commandService = accessor.get(ICommandService);
10506
- const univerInstanceService = accessor.get(IUniverInstanceService);
10507
- const renderManagerService = accessor.get(IRenderManagerService);
10508
- const { unitId, segmentId, createType, headerFooterProps } = params;
10509
- const docSkeletonManagerService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService);
10510
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
10511
- const docViewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
10512
- if (docDataModel == null || docViewModel == null) return false;
10513
- const editArea = docViewModel.getEditArea();
10514
- const { documentStyle } = docDataModel.getSnapshot();
10515
- const isUpdateMargin = (headerFooterProps === null || headerFooterProps === void 0 ? void 0 : headerFooterProps.marginFooter) != null || (headerFooterProps === null || headerFooterProps === void 0 ? void 0 : headerFooterProps.marginHeader) != null;
10516
- const doMutation = {
10517
- id: RichTextEditingMutation.id,
10518
- params: {
10519
- unitId,
10520
- actions: [],
10521
- textRanges: [{
10522
- startOffset: 0,
10523
- endOffset: 0,
10524
- collapsed: true
10525
- }],
10526
- debounce: true
10527
- }
10528
- };
10529
- if (isUpdateMargin) doMutation.params.noNeedSetTextRange = true;
10530
- const jsonX = JSONX.getInstance();
10531
- const rawActions = [];
10532
- if (createType != null) createHeaderFooterAction(segmentId, createType, documentStyle, rawActions);
10533
- if (headerFooterProps != null) Object.keys(headerFooterProps).forEach((key) => {
10534
- const value = headerFooterProps[key];
10535
- const oldValue = documentStyle[key];
10536
- if (value === oldValue) return;
10537
- let action;
10538
- if (oldValue === void 0) action = jsonX.insertOp(["documentStyle", key], value);
10539
- else action = jsonX.replaceOp(["documentStyle", key], oldValue, value);
10540
- rawActions.push(action);
10541
- if (key === "useFirstPageHeaderFooter" && value === BooleanNumber.TRUE && !documentStyle.firstPageHeaderId) createHeaderFooterAction(segmentId, editArea === DocumentEditArea.HEADER ? 0 : 1, documentStyle, rawActions);
10542
- else if (key === "evenAndOddHeaders" && value === BooleanNumber.TRUE && !documentStyle.evenPageHeaderId) createHeaderFooterAction(segmentId, editArea === DocumentEditArea.HEADER ? 4 : 5, documentStyle, rawActions);
10543
- });
10544
- if (rawActions.length === 0) return false;
10545
- doMutation.params.actions = rawActions.reduce((acc, cur) => {
10546
- return JSONX.compose(acc, cur);
10547
- }, null);
10548
- const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
10549
- return Boolean(result);
10550
- }
10551
- };
10552
- const OpenHeaderFooterPanelCommand = {
10553
- id: "doc.command.open-header-footer-panel",
10554
- type: CommandType.COMMAND,
10555
- handler: async (accessor, _params) => {
10556
- return accessor.get(ICommandService).executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "open" });
10557
- }
10558
- };
10559
- const CloseHeaderFooterCommand = {
10560
- id: "doc.command.close-header-footer",
10561
- type: CommandType.COMMAND,
10562
- handler: async (accessor, params) => {
10563
- var _renderObject$mainCom;
10564
- const commandService = accessor.get(ICommandService);
10565
- const renderManagerService = accessor.get(IRenderManagerService);
10566
- const docSelectionManagerService = accessor.get(DocSelectionManagerService);
10567
- const instanceService = accessor.get(IUniverInstanceService);
10568
- const { unitId } = params;
10569
- const renderObject = renderManagerService.getRenderById(unitId);
10570
- if (renderObject == null) return false;
10571
- const { scene } = renderObject;
10572
- const transformer = scene.getTransformerByCreate();
10573
- const docSkeletonManagerService = renderObject.with(DocSkeletonManagerService);
10574
- const docSelectionRenderService = renderObject.with(DocSelectionRenderService);
10575
- const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
10576
- const viewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
10577
- if (viewModel == null || skeleton == null) return false;
10578
- docSelectionManagerService.replaceDocRanges([]);
10579
- transformer.clearSelectedObjects();
10580
- docSelectionRenderService.setSegment("");
10581
- docSelectionRenderService.setSegmentPage(-1);
10582
- viewModel.setEditArea(DocumentEditArea.BODY);
10583
- skeleton.calculate();
10584
- (_renderObject$mainCom = renderObject.mainComponent) === null || _renderObject$mainCom === void 0 || _renderObject$mainCom.makeDirty(true);
10585
- queueMicrotask(() => {
10586
- const docDataModel = instanceService.getUnit(unitId);
10587
- const snapshot = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot();
10588
- if (snapshot == null) return;
10589
- const offset = findFirstCursorOffset(snapshot);
10590
- docSelectionManagerService.replaceDocRanges([{
10591
- startOffset: offset,
10592
- endOffset: offset
10593
- }]);
10594
- });
10595
- commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "close" });
10596
- return true;
10597
- }
10598
- };
10599
-
10600
- //#endregion
10601
- //#region src/controllers/doc-paragraph-setting.controller.ts
10602
- /**
10603
- * Copyright 2023-present DreamNum Co., Ltd.
10604
- *
10605
- * Licensed under the Apache License, Version 2.0 (the "License");
10606
- * you may not use this file except in compliance with the License.
10607
- * You may obtain a copy of the License at
10608
- *
10609
- * http://www.apache.org/licenses/LICENSE-2.0
10610
- *
10611
- * Unless required by applicable law or agreed to in writing, software
10612
- * distributed under the License is distributed on an "AS IS" BASIS,
10613
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10614
- * See the License for the specific language governing permissions and
10615
- * limitations under the License.
10616
- */
10617
- const paragraphSettingIndexKey$1 = "doc_ui_paragraph-setting-panel";
10618
- let DocParagraphSettingController = class DocParagraphSettingController extends Disposable {
10619
- constructor(_commandService, _sidebarService) {
10620
- super();
10621
- this._commandService = _commandService;
10622
- this._sidebarService = _sidebarService;
10623
- _defineProperty(this, "_id", void 0);
10624
- }
10625
- openPanel() {
10626
- const props = {
10627
- header: { title: "docs-ui.doc.slider.paragraphSetting" },
10628
- id: this._id,
10629
- children: { label: paragraphSettingIndexKey$1 },
10630
- width: 300
10631
- };
10632
- this._sidebarService.open(props);
10633
- }
10634
- closePanel() {
10635
- this._sidebarService.close(this._id);
10636
- }
10637
- };
10638
- DocParagraphSettingController = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, Inject(ISidebarService))], DocParagraphSettingController);
10639
-
10640
- //#endregion
10641
- //#region src/commands/operations/doc-paragraph-setting-panel.operation.ts
10642
- const DocParagraphSettingPanelOperation = {
10643
- id: "sidebar.operation.doc-paragraph-setting-panel",
10644
- type: CommandType.OPERATION,
10645
- handler: (accessor) => {
10646
- accessor.get(DocParagraphSettingController).openPanel();
10307
+ handler: (accessor) => {
10308
+ accessor.get(DocParagraphSettingController).openPanel();
10647
10309
  return true;
10648
10310
  }
10649
10311
  };
@@ -11049,8 +10711,8 @@ function notInTableSubscriber(subscriber, docSelectionManagerService, univerInst
11049
10711
  subscriber.next(true);
11050
10712
  return;
11051
10713
  }
11052
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
11053
- const tables = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.tables;
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;
11054
10716
  if (tables && tables.length) {
11055
10717
  if (tables.some((table) => {
11056
10718
  const { startIndex, endIndex } = table;
@@ -11376,6 +11038,46 @@ function getInsertTableHiddenObservable(accessor) {
11376
11038
  return () => subscription.unsubscribe();
11377
11039
  });
11378
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
+ }
11379
11081
  function getHeaderFooterMenuHiddenObservable(accessor) {
11380
11082
  const univerInstanceService = accessor.get(IUniverInstanceService);
11381
11083
  const commandService = accessor.get(ICommandService);
@@ -11394,11 +11096,11 @@ function getHeaderFooterMenuHiddenObservable(accessor) {
11394
11096
  });
11395
11097
  const subscription = univerInstanceService.focused$.subscribe((unitId) => {
11396
11098
  if (unitId == null) return subscriber.next(true);
11397
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
11099
+ const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
11398
11100
  const documentFlavor = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle.documentFlavor;
11399
11101
  subscriber.next(documentFlavor !== DocumentFlavor.TRADITIONAL);
11400
11102
  });
11401
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
11103
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
11402
11104
  if (docDataModel == null) return subscriber.next(true);
11403
11105
  const documentFlavor = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle.documentFlavor;
11404
11106
  subscriber.next(documentFlavor !== DocumentFlavor.TRADITIONAL);
@@ -11427,7 +11129,7 @@ function getTableDisabledObservable(accessor) {
11427
11129
  subscriber.next(true);
11428
11130
  return;
11429
11131
  }
11430
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
11132
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
11431
11133
  if (docDataModel == null) {
11432
11134
  subscriber.next(true);
11433
11135
  return;
@@ -12150,14 +11852,14 @@ const listValueFactory$ = (accessor) => {
12150
11852
  const subscription = univerInstanceService.focused$.subscribe((unitId) => {
12151
11853
  var _docRanges$find;
12152
11854
  if (unitId == null) return;
12153
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
11855
+ const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
12154
11856
  if (docDataModel == null) return;
12155
11857
  const docRanges = docSelectionManagerService.getDocRanges();
12156
11858
  const range = (_docRanges$find = docRanges.find((r) => r.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
12157
11859
  if (range) {
12158
11860
  var _doc$getBody$paragrap, _doc$getBody, _doc$getBody$dataStre, _doc$getBody2;
12159
11861
  const doc = docDataModel.getSelfOrHeaderFooterModel(range === null || range === void 0 ? void 0 : range.segmentId);
12160
- 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 : "");
12161
11863
  let listType;
12162
11864
  if (paragraphs.every((p) => {
12163
11865
  if (!listType) {
@@ -12317,7 +12019,7 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
12317
12019
  };
12318
12020
  }
12319
12021
  function getFontStyleAtCursor(accessor) {
12320
- var _docRanges$find2, _docMenuStyleService$, _paragraph$paragraphS11, _paragraph$paragraphS12;
12022
+ var _docRanges$find2, _docMenuStyleService$, _paragraph$paragraphS11, _paragraph$paragraphS12, _docDataModel$getSelf;
12321
12023
  const univerInstanceService = accessor.get(IUniverInstanceService);
12322
12024
  const textSelectionService = accessor.get(DocSelectionManagerService);
12323
12025
  const docMenuStyleService = accessor.get(DocMenuStyleService);
@@ -12334,7 +12036,7 @@ function getFontStyleAtCursor(accessor) {
12334
12036
  ...cacheStyle
12335
12037
  } };
12336
12038
  const { segmentId } = activeRange;
12337
- const body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
12039
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
12338
12040
  if (body == null) return { ts: {
12339
12041
  ...defaultTextStyle,
12340
12042
  ...namedStyle,
@@ -12350,15 +12052,15 @@ function getFontStyleAtCursor(accessor) {
12350
12052
  } };
12351
12053
  }
12352
12054
  function getParagraphStyleAtCursor(accessor) {
12353
- var _docRanges$find3, _docDataModel$getSelf;
12055
+ var _docRanges$find3, _docDataModel$getSelf2;
12354
12056
  const univerInstanceService = accessor.get(IUniverInstanceService);
12355
12057
  const textSelectionService = accessor.get(DocSelectionManagerService);
12356
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
12058
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
12357
12059
  const docRanges = textSelectionService.getDocRanges();
12358
12060
  const activeRange = (_docRanges$find3 = docRanges.find((r) => r.isActive)) !== null && _docRanges$find3 !== void 0 ? _docRanges$find3 : docRanges[0];
12359
12061
  if (docDataModel == null || activeRange == null) return;
12360
12062
  const { startOffset, segmentId } = activeRange;
12361
- 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;
12362
12064
  if (paragraphs == null) return;
12363
12065
  let prevIndex = -1;
12364
12066
  for (const paragraph of paragraphs) {
@@ -15120,7 +14822,7 @@ DocUIController = __decorate([
15120
14822
  //#endregion
15121
14823
  //#region package.json
15122
14824
  var name = "@univerjs/docs-ui";
15123
- var version = "1.0.0-alpha.1";
14825
+ var version = "1.0.0-alpha.2";
15124
14826
 
15125
14827
  //#endregion
15126
14828
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -15138,8 +14840,8 @@ const DocParagraphSettingCommand = {
15138
14840
  const segmentId = docRanges[0].segmentId;
15139
14841
  const unitId = docDataModel.getUnitId();
15140
14842
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
15141
- 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 : [];
15142
- 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 : "";
15143
14845
  const paragraphs = (_BuildTextUtils$range = BuildTextUtils.range.getParagraphsInRanges(docRanges, allParagraphs, dataStream)) !== null && _BuildTextUtils$range !== void 0 ? _BuildTextUtils$range : [];
15144
14846
  const doMutation = {
15145
14847
  id: RichTextEditingMutation.id,
@@ -15210,7 +14912,7 @@ const DocHeaderFooterOptions = (props) => {
15210
14912
  ...prev,
15211
14913
  [type]: val ? BooleanNumber.TRUE : BooleanNumber.FALSE
15212
14914
  }));
15213
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
14915
+ const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
15214
14916
  const documentStyle = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle;
15215
14917
  const docSkeletonManagerService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService);
15216
14918
  const viewModel = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel();
@@ -15268,7 +14970,7 @@ const DocHeaderFooterOptions = (props) => {
15268
14970
  commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId });
15269
14971
  };
15270
14972
  useEffect(() => {
15271
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
14973
+ const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
15272
14974
  const documentStyle = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSnapshot().documentStyle;
15273
14975
  if (documentStyle) {
15274
14976
  const { marginHeader = 0, marginFooter = 0, useFirstPageHeaderFooter = BooleanNumber.FALSE, evenAndOddHeaders = BooleanNumber.FALSE } = documentStyle;
@@ -15338,8 +15040,8 @@ const DocHeaderFooterPanel = () => {
15338
15040
  var _renderManagerService;
15339
15041
  const localeService = useDependency(LocaleService);
15340
15042
  const renderManagerService = useDependency(IRenderManagerService);
15341
- const unitId = useDependency(IUniverInstanceService).getCurrentUniverDocInstance().getUnitId();
15342
- 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();
15343
15045
  const [isEditHeaderFooter, setIsEditHeaderFooter] = useState(true);
15344
15046
  useEffect(() => {
15345
15047
  setIsEditHeaderFooter(viewModel.getEditArea() !== DocumentEditArea.BODY);
@@ -15604,8 +15306,8 @@ const useCurrentParagraph = () => {
15604
15306
  if (!docDataModel || docRanges.length === 0) return [];
15605
15307
  const segmentId = docRanges[0].segmentId;
15606
15308
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
15607
- 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 : [];
15608
- 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 : "";
15609
15311
  return (_BuildTextUtils$range = BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream)) !== null && _BuildTextUtils$range !== void 0 ? _BuildTextUtils$range : [];
15610
15312
  };
15611
15313
  const useFirstParagraphHorizontalAlign = (paragraph, defaultValue) => {
@@ -16194,12 +15896,12 @@ const LIST_ICON_MAP = {
16194
15896
  };
16195
15897
  let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16196
15898
  get activeParagraph() {
16197
- var _this$_paragrahMenu;
16198
- 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;
16199
15901
  }
16200
15902
  get activeTarget() {
16201
- var _this$_paragrahMenu$t, _this$_paragrahMenu2;
16202
- 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;
16203
15905
  }
16204
15906
  setBlockMenuDragging(isDragging) {
16205
15907
  this._isBlockMenuDragging = isDragging;
@@ -16216,7 +15918,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16216
15918
  this._docSkeletonManagerService = _docSkeletonManagerService;
16217
15919
  this._floatMenuService = _floatMenuService;
16218
15920
  this._docSelectionRenderService = _docSelectionRenderService;
16219
- _defineProperty(this, "_paragrahMenu", null);
15921
+ _defineProperty(this, "_paragraphMenu", null);
16220
15922
  _defineProperty(this, "_activeTarget$", new BehaviorSubject(null));
16221
15923
  _defineProperty(this, "activeTarget$", this._activeTarget$.asObservable());
16222
15924
  _defineProperty(this, "_slashMenuRequest$", new BehaviorSubject(null));
@@ -16228,10 +15930,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16228
15930
  this._init();
16229
15931
  }
16230
15932
  _isCursorInActiveParagraph() {
16231
- if (!this._paragrahMenu) return false;
15933
+ if (!this._paragraphMenu) return false;
16232
15934
  const activeTextRange = this._docSelectionManagerService.getActiveTextRange();
16233
15935
  if (!(activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.collapsed)) return false;
16234
- 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;
16235
15937
  return true;
16236
15938
  }
16237
15939
  _getExpandedSelectionState(ranges) {
@@ -16262,7 +15964,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16262
15964
  return this._hasExpandedSelectionRanges(this._docSelectionManagerService.getDocRanges());
16263
15965
  }
16264
15966
  setParagraphMenuActive(active) {
16265
- if (this._paragrahMenu) this._paragrahMenu.active = active;
15967
+ if (this._paragraphMenu) this._paragraphMenu.active = active;
16266
15968
  }
16267
15969
  _init() {
16268
15970
  var _this$_docEventManage;
@@ -16278,18 +15980,18 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16278
15980
  return;
16279
15981
  }
16280
15982
  if (selectionState.hasRectRange) {
16281
- var _this$_paragrahMenu3;
15983
+ var _this$_paragraphMenu3;
16282
15984
  if (tableBound) {
16283
15985
  this.showTableMenu(tableBound);
16284
15986
  return;
16285
15987
  }
16286
- if (((_this$_paragrahMenu3 = this._paragrahMenu) === null || _this$_paragrahMenu3 === void 0 ? void 0 : _this$_paragrahMenu3.target.kind) === DocumentBlockType.TABLE) return;
15988
+ if (((_this$_paragraphMenu3 = this._paragraphMenu) === null || _this$_paragraphMenu3 === void 0 ? void 0 : _this$_paragraphMenu3.target.kind) === DocumentBlockType.TABLE) return;
16287
15989
  this.hideParagraphMenu(true);
16288
15990
  return;
16289
15991
  }
16290
15992
  if (this._docSkeletonManagerService.getViewModel().getEditArea() === DocumentEditArea.BODY && !this._floatMenuService.floatMenu && !this._context.unit.getDisabled()) {
16291
- var _this$_paragrahMenu4;
16292
- 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;
16293
15995
  if (paragraph) {
16294
15996
  this.showParagraphMenu(paragraph);
16295
15997
  return;
@@ -16315,16 +16017,16 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16315
16017
  this.hideParagraphMenu(true);
16316
16018
  }));
16317
16019
  this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(({ textRanges, rectRanges }) => {
16318
- var _this$_paragrahMenu5;
16020
+ var _this$_paragraphMenu5;
16319
16021
  const selectionState = this._getExpandedSelectionState([...textRanges, ...rectRanges]);
16320
- if (selectionState.hasExpandedTextRange || selectionState.hasRectRange && ((_this$_paragrahMenu5 = this._paragrahMenu) === null || _this$_paragrahMenu5 === void 0 ? void 0 : _this$_paragrahMenu5.target.kind) !== DocumentBlockType.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);
16321
16023
  }));
16322
16024
  let lastScrollY = 0;
16323
16025
  this.disposeWithMe(this._context.scene.getViewport("viewMain").onScrollAfter$.subscribeEvent((e) => {
16324
- var _this$_paragrahMenu6;
16026
+ var _this$_paragraphMenu6;
16325
16027
  if (lastScrollY === e.scrollY) return;
16326
16028
  lastScrollY = e.scrollY;
16327
- 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;
16328
16030
  if (this._isBlockMenuDragging) return;
16329
16031
  this.hideParagraphMenu(true);
16330
16032
  }));
@@ -16388,10 +16090,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16388
16090
  return null;
16389
16091
  }
16390
16092
  _getSlashMenuParagraph(config) {
16391
- var _this$_paragrahMenu$p, _this$_paragrahMenu7, _find;
16093
+ var _this$_paragraphMenu$2, _this$_paragraphMenu7, _find;
16392
16094
  const activeRange = this._getCollapsedTextRange(config);
16393
16095
  const offset = activeRange === null || activeRange === void 0 ? void 0 : activeRange.startOffset;
16394
- 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;
16395
16097
  if (activeParagraph && offset != null && offset >= activeParagraph.paragraphStart && offset <= activeParagraph.paragraphEnd) return activeParagraph;
16396
16098
  if (activeParagraph && offset == null) return activeParagraph;
16397
16099
  if (offset == null) return null;
@@ -16412,7 +16114,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16412
16114
  }
16413
16115
  }
16414
16116
  showParagraphMenu(paragraph) {
16415
- var _this$_paragrahMenu8, _target$paragraph;
16117
+ var _this$_paragraphMenu8, _target$paragraph;
16416
16118
  if (this._hasExpandedSelection()) {
16417
16119
  this.hideParagraphMenu(true);
16418
16120
  return;
@@ -16422,7 +16124,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16422
16124
  this.hideParagraphMenu(true);
16423
16125
  return;
16424
16126
  }
16425
- 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;
16426
16128
  this.hideParagraphMenu(true);
16427
16129
  const targetParagraph = (_target$paragraph = target.paragraph) !== null && _target$paragraph !== void 0 ? _target$paragraph : paragraph;
16428
16130
  const blockRange = target.blockRange;
@@ -16447,7 +16149,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16447
16149
  },
16448
16150
  zIndex: 101
16449
16151
  }, this._context.unitId);
16450
- this._paragrahMenu = {
16152
+ this._paragraphMenu = {
16451
16153
  paragraph: targetParagraph,
16452
16154
  target,
16453
16155
  blockRange,
@@ -16457,7 +16159,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16457
16159
  this._activeTarget$.next(target);
16458
16160
  }
16459
16161
  showTableMenu(tableBound) {
16460
- var _body$tables, _this$_paragrahMenu9;
16162
+ var _body$tables, _this$_paragraphMenu9;
16461
16163
  if (this._hasExpandedTextSelection()) {
16462
16164
  this.hideParagraphMenu(true);
16463
16165
  return;
@@ -16483,7 +16185,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16483
16185
  draggable: true
16484
16186
  };
16485
16187
  if (this._shouldKeepCurrentCellMenuForTable(table)) return;
16486
- 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;
16487
16189
  const anchorRect = getTableAnchorRect(tableBound);
16488
16190
  const paragraph = {
16489
16191
  rect: tableBound.rect,
@@ -16507,7 +16209,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16507
16209
  },
16508
16210
  zIndex: 101
16509
16211
  }, this._context.unitId);
16510
- this._paragrahMenu = {
16212
+ this._paragraphMenu = {
16511
16213
  paragraph,
16512
16214
  target,
16513
16215
  disposable,
@@ -16516,8 +16218,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16516
16218
  this._activeTarget$.next(target);
16517
16219
  }
16518
16220
  _shouldKeepCurrentCellMenuForTable(table) {
16519
- var _this$_paragrahMenu10;
16520
- const target = (_this$_paragrahMenu10 = this._paragrahMenu) === null || _this$_paragrahMenu10 === void 0 ? void 0 : _this$_paragrahMenu10.target;
16221
+ var _this$_paragraphMenu10;
16222
+ const target = (_this$_paragraphMenu10 = this._paragraphMenu) === null || _this$_paragraphMenu10 === void 0 ? void 0 : _this$_paragraphMenu10.target;
16521
16223
  if (!target || target.kind === DocumentBlockType.TABLE || !target.cellRange) return false;
16522
16224
  return target.cellRange.startOffset >= table.startIndex && target.cellRange.startOffset <= table.endIndex;
16523
16225
  }
@@ -16558,9 +16260,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
16558
16260
  }
16559
16261
  hideParagraphMenu(force = false) {
16560
16262
  if (this._isBlockMenuDragging) return;
16561
- if (this._paragrahMenu && (this._paragrahMenu.disposable.canDispose() || force)) {
16562
- this._paragrahMenu.disposable.dispose();
16563
- this._paragrahMenu = null;
16263
+ if (this._paragraphMenu && (this._paragraphMenu.disposable.canDispose() || force)) {
16264
+ this._paragraphMenu.disposable.dispose();
16265
+ this._paragraphMenu = null;
16564
16266
  this._isSlashMenuActive = false;
16565
16267
  this._slashMenuRequest$.next(null);
16566
16268
  this._activeTarget$.next(null);
@@ -17048,6 +16750,14 @@ function getParagraphMenuResolvedCommand(option, targetRange) {
17048
16750
  id: (_option$id = option.id) !== null && _option$id !== void 0 ? _option$id : commandId
17049
16751
  }, targetRange);
17050
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
+ }
17051
16761
  function getParagraphMenuType(target, emptyMode) {
17052
16762
  if ((target === null || target === void 0 ? void 0 : target.kind) === "table") return DOC_TABLE_BLOCK_MENU_ID;
17053
16763
  if (emptyMode) return DOC_PARAGRAPH_T_INSERT_MENU_ID;
@@ -17485,7 +17195,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
17485
17195
  await executeResolvedCommand({
17486
17196
  ...option,
17487
17197
  commandId,
17488
- params: commandParams
17198
+ params: getParagraphMenuCommandParams(commandId, commandParams, latestTarget, popup.unitId)
17489
17199
  }, getParagraphMenuCommandTargetRange(commandId, targetRange, formattingRange));
17490
17200
  } finally {
17491
17201
  restoreTextRanges(previousTextRanges);
@@ -17887,162 +17597,480 @@ let ComponentsController = class ComponentsController extends Disposable {
17887
17597
  "DocParagraphBackgroundColorSwatchIcon.15": DocParagraphBackgroundColorSwatchIcon15
17888
17598
  }));
17889
17599
  }
17890
- _registerComponents() {
17891
- if (!this._componentManager.get("COMPONENT_DOC_HEADER_FOOTER_PANEL")) this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_HEADER_FOOTER_PANEL, DocHeaderFooterPanel));
17892
- this.disposeWithMe(this._componentManager.register(paragraphSettingIndexKey, ParagraphSettingIndex));
17893
- [
17894
- [BULLET_LIST_TYPE_COMPONENT, BulletListTypePicker],
17895
- [ORDER_LIST_TYPE_COMPONENT, OrderListTypePicker],
17896
- [DOC_PARAGRAPH_MENU_COMPONENT_KEY, ParagraphMenu],
17897
- [DOC_TABLE_BLOCK_MENU_COMPONENT_KEY, TableBlockMenu],
17898
- [PAGE_SETTING_COMPONENT_ID, PageSettings]
17899
- ].forEach(([key, comp]) => {
17900
- this.disposeWithMe(this._componentManager.register(key, comp));
17901
- });
17902
- }
17903
- };
17904
- ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
17905
-
17906
- //#endregion
17907
- //#region src/controllers/doc-auto-format.controller.ts
17908
- function hasQuickListType(text) {
17909
- return Object.prototype.hasOwnProperty.call(QuickListTypeMap, text);
17910
- }
17911
- function hasQuickHeading(text) {
17912
- return Object.prototype.hasOwnProperty.call(QUICK_HEADING_MAP, text);
17913
- }
17914
- let DocAutoFormatController = class DocAutoFormatController extends Disposable {
17915
- constructor(_docAutoFormatService, _renderManagerService) {
17916
- super();
17917
- this._docAutoFormatService = _docAutoFormatService;
17918
- this._renderManagerService = _renderManagerService;
17919
- this._initListTabAutoFormat();
17920
- this._initSpaceAutoFormat();
17921
- this._initDefaultEnterFormat();
17922
- this._initExitListAutoFormat();
17600
+ _registerComponents() {
17601
+ if (!this._componentManager.get("COMPONENT_DOC_HEADER_FOOTER_PANEL")) this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_HEADER_FOOTER_PANEL, DocHeaderFooterPanel));
17602
+ this.disposeWithMe(this._componentManager.register(paragraphSettingIndexKey, ParagraphSettingIndex));
17603
+ [
17604
+ [BULLET_LIST_TYPE_COMPONENT, BulletListTypePicker],
17605
+ [ORDER_LIST_TYPE_COMPONENT, OrderListTypePicker],
17606
+ [DOC_PARAGRAPH_MENU_COMPONENT_KEY, ParagraphMenu],
17607
+ [DOC_TABLE_BLOCK_MENU_COMPONENT_KEY, TableBlockMenu],
17608
+ [PAGE_SETTING_COMPONENT_ID, PageSettings]
17609
+ ].forEach(([key, comp]) => {
17610
+ this.disposeWithMe(this._componentManager.register(key, comp));
17611
+ });
17612
+ }
17613
+ };
17614
+ ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
17615
+
17616
+ //#endregion
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
+ }
17624
+ let DocAutoFormatController = class DocAutoFormatController extends Disposable {
17625
+ constructor(_docAutoFormatService, _renderManagerService) {
17626
+ super();
17627
+ this._docAutoFormatService = _docAutoFormatService;
17628
+ this._renderManagerService = _renderManagerService;
17629
+ this._initListTabAutoFormat();
17630
+ this._initSpaceAutoFormat();
17631
+ this._initDefaultEnterFormat();
17632
+ this._initExitListAutoFormat();
17633
+ }
17634
+ _initListTabAutoFormat() {
17635
+ this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17636
+ id: TabCommand.id,
17637
+ match: (context) => {
17638
+ const { selection, paragraphs, unit } = context;
17639
+ if (paragraphs.length === 1 && selection.startOffset === paragraphs[0].paragraphStart && paragraphs[0].bullet) {
17640
+ var _unit$getBody;
17641
+ const allParagraphs = (_unit$getBody = unit.getBody()) === null || _unit$getBody === void 0 ? void 0 : _unit$getBody.paragraphs;
17642
+ const bulletParagraphs = allParagraphs === null || allParagraphs === void 0 ? void 0 : allParagraphs.filter((p) => {
17643
+ var _p$bullet;
17644
+ return ((_p$bullet = p.bullet) === null || _p$bullet === void 0 ? void 0 : _p$bullet.listId) === paragraphs[0].bullet.listId;
17645
+ });
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);
17923
17967
  }
17924
- _initListTabAutoFormat() {
17925
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17926
- id: TabCommand.id,
17927
- match: (context) => {
17928
- const { selection, paragraphs, unit } = context;
17929
- if (paragraphs.length === 1 && selection.startOffset === paragraphs[0].paragraphStart && paragraphs[0].bullet) {
17930
- var _unit$getBody;
17931
- const allParagraphs = (_unit$getBody = unit.getBody()) === null || _unit$getBody === void 0 ? void 0 : _unit$getBody.paragraphs;
17932
- const bulletParagraphs = allParagraphs === null || allParagraphs === void 0 ? void 0 : allParagraphs.filter((p) => {
17933
- var _p$bullet;
17934
- return ((_p$bullet = p.bullet) === null || _p$bullet === void 0 ? void 0 : _p$bullet.listId) === paragraphs[0].bullet.listId;
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)"
17935
17993
  });
17936
- if ((bulletParagraphs === null || bulletParagraphs === void 0 ? void 0 : bulletParagraphs.findIndex((p) => p.startIndex === paragraphs[0].startIndex)) === 0) return false;
17937
- return true;
17938
- } else if (paragraphs.length > 1 && paragraphs.some((p) => p.bullet)) return true;
17939
- return false;
17940
- },
17941
- getMutations(context) {
17942
- const params = context.commandParams;
17943
- return [{
17944
- id: ChangeListNestingLevelCommand.id,
17945
- params: { type: (params === null || params === void 0 ? void 0 : params.shift) ? -1 : 1 }
17946
- }];
17947
- },
17948
- priority: 100
17949
- }));
17950
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17951
- id: TabCommand.id,
17952
- match: (context) => {
17953
- const { selection, unit } = context;
17954
- const { startNodePosition, endNodePosition } = selection;
17955
- const renderObject = this._renderManagerService.getRenderById(unit.getUnitId());
17956
- const skeleton = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
17957
- if (skeleton == null) return false;
17958
- if (startNodePosition && endNodePosition && isInSameTableCellData(skeleton, startNodePosition, endNodePosition)) return true;
17959
- if (startNodePosition && !endNodePosition && startNodePosition.path.indexOf("cells") > -1) return true;
17960
- return false;
17961
- },
17962
- getMutations(context) {
17963
- const params = context.commandParams;
17964
- return [{
17965
- id: DocTableTabCommand.id,
17966
- params: { shift: !!(params === null || params === void 0 ? void 0 : params.shift) }
17967
- }];
17968
- },
17969
- priority: 99
17970
- }));
17971
- }
17972
- _initSpaceAutoFormat() {
17973
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
17974
- id: AfterSpaceCommand.id,
17975
- match: (context) => {
17976
- var _unit$getBody2;
17977
- const { selection, paragraphs, unit } = context;
17978
- if (!selection.collapsed) return false;
17979
- if (paragraphs.length !== 1) return false;
17980
- if (!selection.collapsed) return false;
17981
- const text = (_unit$getBody2 = unit.getBody()) === null || _unit$getBody2 === void 0 ? void 0 : _unit$getBody2.dataStream.slice(paragraphs[0].paragraphStart, selection.startOffset - 1);
17982
- if (text && (hasQuickListType(text) || hasQuickHeading(text))) return true;
17983
- return false;
17984
- },
17985
- getMutations(context) {
17986
- var _unit$getBody3;
17987
- const { paragraphs, unit, selection } = context;
17988
- const text = (_unit$getBody3 = unit.getBody()) === null || _unit$getBody3 === void 0 ? void 0 : _unit$getBody3.dataStream.slice(paragraphs[0].paragraphStart, selection.startOffset - 1);
17989
- if (text && hasQuickListType(text)) {
17990
- const type = QuickListTypeMap[text];
17991
- return [{
17992
- id: QuickListCommand.id,
17993
- params: {
17994
- listType: type,
17995
- paragraph: paragraphs[0]
17996
- }
17997
- }];
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();
17998
18015
  }
17999
- if (text && hasQuickHeading(text)) {
18000
- const type = QUICK_HEADING_MAP[text];
18001
- return [{
18002
- id: QuickHeadingCommand.id,
18003
- params: { value: type }
18004
- }];
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
+ });
18005
18051
  }
18006
- return [];
18007
- }
18052
+ ctx.restore();
18053
+ })));
18008
18054
  }));
18009
18055
  }
18010
- _initExitListAutoFormat() {
18011
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
18012
- id: EnterCommand.id,
18013
- match: (context) => {
18014
- const { paragraphs } = context;
18015
- if (paragraphs.length === 1 && paragraphs[0].bullet && paragraphs[0].paragraphStart === paragraphs[0].paragraphEnd) return true;
18016
- return false;
18017
- },
18018
- getMutations: (context) => {
18019
- const bullet = context.paragraphs[0].bullet;
18020
- if (!bullet) return [];
18021
- if (bullet.nestingLevel > 0) return [{
18022
- id: ChangeListNestingLevelCommand.id,
18023
- params: { type: -1 }
18024
- }];
18025
- return [{
18026
- id: ListOperationCommand.id,
18027
- params: { listType: context.paragraphs[0].bullet.listType }
18028
- }];
18029
- }
18030
- }));
18056
+ _isEditorReadOnly(unitId) {
18057
+ const editor = this._editorService.getEditor(unitId);
18058
+ if (!editor) return false;
18059
+ return editor.isReadOnly();
18031
18060
  }
18032
- _initDefaultEnterFormat() {
18033
- this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({
18034
- id: EnterCommand.id,
18035
- match: () => {
18036
- return true;
18037
- },
18038
- getMutations() {
18039
- return [{ id: BreakLineCommand.id }];
18040
- },
18041
- priority: -9999
18042
- }));
18061
+ _isTraditionalMode() {
18062
+ return this._context.unit.getSnapshot().documentStyle.documentFlavor === DocumentFlavor.TRADITIONAL;
18043
18063
  }
18044
18064
  };
18045
- 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);
18046
18074
 
18047
18075
  //#endregion
18048
18076
  //#region src/basics/table.ts
@@ -18108,10 +18136,10 @@ let DocMoveCursorController = class DocMoveCursorController extends Disposable {
18108
18136
  }));
18109
18137
  }
18110
18138
  _handleShiftMoveSelection(direction, granularity = "character") {
18111
- var _this$_renderManagerS, _body$dataStream$leng, _docDataModel$getCust;
18139
+ var _this$_renderManagerS, _docDataModel$getSelf, _body$dataStream$leng, _docDataModel$getCust;
18112
18140
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
18113
18141
  const allRanges = this._textSelectionManagerService.getTextRanges();
18114
- const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
18142
+ const docDataModel = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
18115
18143
  if (docDataModel == null) return;
18116
18144
  const skeleton = (_this$_renderManagerS = this._renderManagerService.getRenderById(docDataModel.getUnitId())) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(DocSkeletonManagerService).getSkeleton();
18117
18145
  const docObject = this._getDocObject();
@@ -18135,7 +18163,7 @@ let DocMoveCursorController = class DocMoveCursorController extends Disposable {
18135
18163
  }
18136
18164
  const anchorOffset = collapsed ? startOffset : rangeDirection === RANGE_DIRECTION.FORWARD ? startOffset : endOffset;
18137
18165
  let focusOffset = collapsed ? endOffset : rangeDirection === RANGE_DIRECTION.FORWARD ? endOffset : startOffset;
18138
- const body = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId).getBody();
18166
+ const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
18139
18167
  if (body == null) return;
18140
18168
  const dataStreamLength = (_body$dataStream$leng = body.dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : Number.POSITIVE_INFINITY;
18141
18169
  const customRanges = (_docDataModel$getCust = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust !== void 0 ? _docDataModel$getCust : [];
@@ -18191,10 +18219,10 @@ let DocMoveCursorController = class DocMoveCursorController extends Disposable {
18191
18219
  }
18192
18220
  }
18193
18221
  _handleMoveCursor(direction, granularity = "character") {
18194
- var _this$_renderManagerS2, _body$dataStream$leng2, _docDataModel$getCust2;
18222
+ var _this$_renderManagerS2, _docDataModel$getSelf2, _body$dataStream$leng2, _docDataModel$getCust2;
18195
18223
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
18196
18224
  const allRanges = this._textSelectionManagerService.getTextRanges();
18197
- const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
18225
+ const docDataModel = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
18198
18226
  if (docDataModel == null) return false;
18199
18227
  const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(DocSkeletonManagerService).getSkeleton();
18200
18228
  const docObject = this._getDocObject();
@@ -18202,7 +18230,7 @@ let DocMoveCursorController = class DocMoveCursorController extends Disposable {
18202
18230
  const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange;
18203
18231
  const normalizedSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : "";
18204
18232
  const normalizedSegmentPage = segmentPage !== null && segmentPage !== void 0 ? segmentPage : -1;
18205
- const body = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId).getBody();
18233
+ const body = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
18206
18234
  if (body == null) return;
18207
18235
  const dataStreamLength = (_body$dataStream$leng2 = body.dataStream.length) !== null && _body$dataStream$leng2 !== void 0 ? _body$dataStream$leng2 : Number.POSITIVE_INFINITY;
18208
18236
  const customRanges = (_docDataModel$getCust2 = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust2 !== void 0 ? _docDataModel$getCust2 : [];
@@ -18970,7 +18998,7 @@ let DocEditorBridgeController = class DocEditorBridgeController extends Disposab
18970
18998
  if (unitId == null) return;
18971
18999
  const editor = this._editorService.getEditor(unitId);
18972
19000
  if ((editor === null || editor === void 0 ? void 0 : editor.cancelDefaultResizeListener) === true) return;
18973
- const editorDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
19001
+ const editorDataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
18974
19002
  if (!editorDataModel) return;
18975
19003
  const skeleton = this._docSkeletonManagerService.getSkeleton();
18976
19004
  if (editor == null || editor.render == null || skeleton == null || editorDataModel == null) return;
@@ -19185,7 +19213,7 @@ let DocInputController = class DocInputController extends Disposable {
19185
19213
  }
19186
19214
  _initialNormalInput() {
19187
19215
  this._onInputSubscription = this._docSelectionRenderService.onInput$.subscribe(async (config) => {
19188
- var _originBody$customRan, _originBody$customDec;
19216
+ var _docDataModel$getSelf, _originBody$customRan, _originBody$customDec;
19189
19217
  if (config == null) return;
19190
19218
  const { unitId } = this._context;
19191
19219
  const { event, content = "", activeRange } = config;
@@ -19194,7 +19222,8 @@ let DocInputController = class DocInputController extends Disposable {
19194
19222
  const skeleton = this._docSkeletonManagerService.getSkeleton();
19195
19223
  if (e.data == null || skeleton == null || activeRange == null) return;
19196
19224
  const { segmentId } = activeRange;
19197
- 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;
19198
19227
  const defaultTextStyle = this._docMenuStyleService.getDefaultStyle();
19199
19228
  const cacheStyle = this._docMenuStyleService.getStyleCache();
19200
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));
@@ -19451,11 +19480,11 @@ let DocZoomRenderController = class DocZoomRenderController extends Disposable {
19451
19480
  _initSkeletonListener() {
19452
19481
  this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((param) => {
19453
19482
  if (param == null) return;
19454
- const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
19483
+ const documentModel = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
19455
19484
  if (!documentModel) return;
19456
19485
  this._updateTimer = window.setTimeout(() => {
19457
19486
  const currentSheet = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
19458
- const sheetRenderer = currentSheet && this._renderManagerService.getRenderById(currentSheet.getUnitId());
19487
+ const sheetRenderer = currentSheet && this._renderManagerService.getRenderUnitById(currentSheet.getUnitId());
19459
19488
  const zoomRatio = !this._isSheetEditor ? getDocEffectiveZoomRatio(documentModel) : (sheetRenderer === null || sheetRenderer === void 0 ? void 0 : sheetRenderer.scene.scaleX) || 1;
19460
19489
  this.updateViewZoom(zoomRatio, false);
19461
19490
  });
@@ -19491,7 +19520,7 @@ let DocZoomRenderController = class DocZoomRenderController extends Disposable {
19491
19520
  _initZoomEventListener() {
19492
19521
  const scene = this._context.scene;
19493
19522
  this.disposeWithMe(scene.onMouseWheel$.subscribeEvent((e) => {
19494
- const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
19523
+ const documentModel = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
19495
19524
  if (!documentModel) return;
19496
19525
  const { documentFlavor } = documentModel.getSnapshot().documentStyle;
19497
19526
  if (!shouldHandleDocWheelZoom(e, Boolean(this._contextService.getContextValue(FOCUSING_DOC)), documentFlavor)) return;
@@ -19645,6 +19674,11 @@ const DeleteRightShortcut = {
19645
19674
  preconditions: whenDocAndEditorFocused,
19646
19675
  binding: KeyCode.DELETE
19647
19676
  };
19677
+ const CloseHeaderFooterShortcut = {
19678
+ id: CloseHeaderFooterCommand.id,
19679
+ preconditions: whenDocAndEditorFocused,
19680
+ binding: KeyCode.ESC
19681
+ };
19648
19682
 
19649
19683
  //#endregion
19650
19684
  //#region src/shortcuts/cursor.shortcut.ts
@@ -19871,7 +19905,6 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends Plugin {
19871
19905
  InsertCustomRangeCommand,
19872
19906
  SetParagraphNamedStyleCommand,
19873
19907
  QuickHeadingCommand,
19874
- DeleteCurrentParagraphCommand,
19875
19908
  DocCopyCurrentParagraphCommand,
19876
19909
  DocCutCurrentParagraphCommand,
19877
19910
  H1HeadingCommand,
@@ -19894,7 +19927,8 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends Plugin {
19894
19927
  [
19895
19928
  DocCopyCommand,
19896
19929
  DocCutCommand,
19897
- DocPasteCommand
19930
+ DocPasteCommand,
19931
+ DeleteCurrentParagraphCommand
19898
19932
  ].forEach((command) => this.disposeWithMe(this._commandService.registerMultipleCommand(command)));
19899
19933
  }
19900
19934
  _initializeShortcut() {
@@ -19926,6 +19960,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends Plugin {
19926
19960
  SelectAllShortcut,
19927
19961
  DeleteLeftShortcut,
19928
19962
  DeleteRightShortcut,
19963
+ CloseHeaderFooterShortcut,
19929
19964
  BreakLineShortcut,
19930
19965
  SoftBreakLineShortcut,
19931
19966
  ShiftTabShortCut,
@@ -20011,7 +20046,7 @@ _defineProperty(UniverDocsUIPlugin, "pluginName", "DOC_UI_PLUGIN");
20011
20046
  _defineProperty(UniverDocsUIPlugin, "packageName", name);
20012
20047
  _defineProperty(UniverDocsUIPlugin, "version", version);
20013
20048
  UniverDocsUIPlugin = __decorate([
20014
- DependentOn(UniverRenderEnginePlugin),
20049
+ DependentOn(UniverRenderEnginePlugin, UniverDocsPlugin),
20015
20050
  __decorateParam(1, Inject(Injector)),
20016
20051
  __decorateParam(2, IRenderManagerService),
20017
20052
  __decorateParam(3, ICommandService),
@@ -20575,4 +20610,4 @@ const RichTextEditor = (props) => {
20575
20610
  };
20576
20611
 
20577
20612
  //#endregion
20578
- 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, 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, 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 };