@univerjs/docs-ui 0.2.8 → 0.2.10

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
@@ -2,11 +2,11 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, FOCUSING_COMMON_DRAWINGS, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, Tools, LRUMap, BaselineOffset, BooleanNumber, ColorKit, DataStreamTreeTokenType, CustomRangeType, skipParseTagNames, DataStreamTreeNodeType, createIdentifier, Inject, IUniverInstanceService, ILogService, ICommandService, Disposable, SliceBodyType, normalizeBody, UniverInstanceType, toDisposable, getBodySlice, RxDisposable, Direction, EDITOR_ACTIVATED, LocaleService, Injector, Optional, useDependency, DocumentFlavor, CommandType, JSONX, useObservable, PresetListType, ThemeService, HorizontalAlign, MemoryCursor, TextX, TextXActionType, UpdateDocsAttributeType, generateRandomId, OnLifecycle, LifecycleStages, connectInjector, IContextService, checkForSubstrings, IConfigService, isInternalEditorID, DisposableCollection, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, fromEventSubject, QuickListTypeMap, Plugin, mergeOverrideWithDependencies, ObjectRelativeFromH, ObjectRelativeFromV } from "@univerjs/core";
5
+ import { FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, FOCUSING_COMMON_DRAWINGS, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, Tools, LRUMap, BaselineOffset, BooleanNumber, ColorKit, DataStreamTreeTokenType, CustomRangeType, skipParseTagNames, DataStreamTreeNodeType, createIdentifier, Inject, IUniverInstanceService, ILogService, ICommandService, Disposable, SliceBodyType, UniverInstanceType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, normalizeBody, toDisposable, getBodySlice, RxDisposable, Direction, EDITOR_ACTIVATED, LocaleService, Injector, Optional, useDependency, DocumentFlavor, CommandType, JSONX, useObservable, PresetListType, ThemeService, HorizontalAlign, MemoryCursor, TextX, TextXActionType, UpdateDocsAttributeType, generateRandomId, OnLifecycle, LifecycleStages, connectInjector, IContextService, checkForSubstrings, IConfigService, isInternalEditorID, DisposableCollection, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, fromEventSubject, QuickListTypeMap, Plugin, mergeOverrideWithDependencies, ObjectRelativeFromH, ObjectRelativeFromV } from "@univerjs/core";
6
6
  import { IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, HTML_CLIPBOARD_MIME_TYPE, IEditorService, KeyCode, MetaKeys, ILayoutService, ComponentManager, ISidebarService, IConfirmService, MenuGroup, MenuItemType, MenuPosition, getMenuHiddenObservable, FONT_FAMILY_LIST, FONT_SIZE_LIST, getHeaderFooterMenuHiddenObservable, CopyCommand, CutCommand, PasteCommand, FontFamily, FontFamilyItem, FontSize, BuiltInUIPart, IMenuService, IUIPartsService, IShortcutService, SetEditorResizeOperation, ICanvasPopupService, IContextMenuService } from "@univerjs/ui";
7
- import { getEmptyTableCell, getEmptyTableRow, genTableSource, getTableColumn, TextSelectionManagerService, DocCustomRangeService, getCursorWhenDelete, CutContentCommand, InnerPasteCommand, getDeleteSelection, DocSkeletonManagerService, VIEWPORT_KEY, getDocObject, MoveCursorOperation, MoveSelectionOperation, SelectAllOperation, neoGetDocObject, RichTextEditingMutation, SetDocZoomRatioOperation, SetInlineFormatBoldCommand, SetInlineFormatItalicCommand, SetInlineFormatUnderlineCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, AlignLeftCommand, AlignRightCommand, AlignCenterCommand, AlignJustifyCommand, OrderListCommand, BulletListCommand, TabCommand, CreateDocTableCommand, SetTextSelectionsOperation, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextColorCommand, AlignOperationCommand, CheckListCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextBackgroundColorCommand, getCommandSkeleton, getParagraphsInRange, getParagraphsInRanges, serializeDocRange, getRichTextEditPath, DeleteLeftCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableDeleteRowsCommand, DocTableDeleteColumnsCommand, DocTableDeleteTableCommand, EnterCommand, DeleteRightCommand, CoverContentCommand, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_VIEW_KEY, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, SetDocZoomRatioCommand, ChangeListNestingLevelCommand, ChangeListNestingLevelType, AfterSpaceCommand, QuickListCommand, ListOperationCommand, BreakLineCommand, DocAutoFormatService, ToggleCheckListCommand, DocTableTabCommand, DocTableShiftTabCommand, DocInterceptorService } from "@univerjs/docs";
8
- import { pixelToPt, ptToPixel, parseDataStreamToTree, DOC_RANGE_TYPE, NodePositionConvertToCursor, getAnchorBounding, IRenderManagerService, ITextSelectionRenderManager, Shape, DocumentEditArea, PageLayoutType, Vector2, Rect, Path, getNumberUnitValue, ScrollBar, Viewport, Layer, Documents, DocBackground, CURSOR_TYPE, pxToNum, getLineBounding, TRANSFORM_CHANGE_OBSERVABLE_TYPE, getParagraphByGlyph, GlyphType, isInSameTableCell } from "@univerjs/engine-render";
9
- import { takeUntil, Observable, combineLatest, map, fromEvent, BehaviorSubject, filter, throttleTime, Subject, debounceTime } from "rxjs";
7
+ import { getEmptyTableCell, getEmptyTableRow, genTableSource, getTableColumn, TextSelectionManagerService, DocCustomRangeService, getCursorWhenDelete, CutContentCommand, InnerPasteCommand, getDeleteSelection, DocSkeletonManagerService, VIEWPORT_KEY, getDocObject, MoveCursorOperation, MoveSelectionOperation, SelectAllOperation, neoGetDocObject, RichTextEditingMutation, SetDocZoomRatioOperation, SetInlineFormatBoldCommand, SetInlineFormatItalicCommand, SetInlineFormatUnderlineCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, AlignLeftCommand, AlignRightCommand, AlignCenterCommand, AlignJustifyCommand, OrderListCommand, BulletListCommand, TabCommand, CreateDocTableCommand, SetTextSelectionsOperation, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextColorCommand, AlignOperationCommand, CheckListCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextBackgroundColorCommand, getCommandSkeleton, getParagraphsInRange, getParagraphsInRanges, serializeDocRange, getRichTextEditPath, DeleteLeftCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableDeleteRowsCommand, DocTableDeleteColumnsCommand, DocTableDeleteTableCommand, EnterCommand, DeleteRightCommand, CoverContentCommand, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_VIEW_KEY, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, SetDocZoomRatioCommand, ChangeListNestingLevelCommand, ChangeListNestingLevelType, DocTableTabCommand, AfterSpaceCommand, QuickListCommand, ListOperationCommand, BreakLineCommand, DocAutoFormatService, ToggleCheckListCommand, DocInterceptorService } from "@univerjs/docs";
8
+ import { pixelToPt, ptToPixel, parseDataStreamToTree, DOC_RANGE_TYPE, NodePositionConvertToCursor, getAnchorBounding, IRenderManagerService, ITextSelectionRenderManager, Shape, DocumentEditArea, PageLayoutType, Vector2, Rect, Path, getNumberUnitValue, ScrollBar, Viewport, Layer, Documents, DocBackground, CURSOR_TYPE, pxToNum, getLineBounding, TRANSFORM_CHANGE_OBSERVABLE_TYPE, isInSameTableCell } from "@univerjs/engine-render";
9
+ import { takeUntil, Observable, combineLatest, map, fromEvent, BehaviorSubject, filter, throttleTime, animationFrameScheduler, Subject, distinctUntilChanged, mergeMap, take } from "rxjs";
10
10
  import * as require$$0 from "react";
11
11
  import require$$0__default, { forwardRef, useRef, createElement, useState, useEffect, useMemo, useCallback } from "react";
12
12
  import { Checkbox, InputNumber, Button, Slider, Tooltip, ColorPicker } from "@univerjs/design";
@@ -81,7 +81,7 @@ function extractNodeStyle(node) {
81
81
  const cssRule = styles2[i], cssValue = styles2.getPropertyValue(cssRule);
82
82
  switch (cssRule) {
83
83
  case "font-family": {
84
- docStyles.ff = cssValue;
84
+ docStyles.ff = cssValue.replace(/^"/g, "").replace(/"$/g, "");
85
85
  break;
86
86
  }
87
87
  case "font-size": {
@@ -108,10 +108,13 @@ function extractNodeStyle(node) {
108
108
  break;
109
109
  }
110
110
  case "color": {
111
- const color = new ColorKit(cssValue);
112
- color.isValid && (docStyles.cl = {
113
- rgb: color.toRgbString()
114
- });
111
+ try {
112
+ const color = new ColorKit(cssValue);
113
+ color.isValid && (docStyles.cl = {
114
+ rgb: color.toRgbString()
115
+ });
116
+ } catch {
117
+ }
115
118
  break;
116
119
  }
117
120
  case "background-color": {
@@ -152,6 +155,9 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
152
155
  const pastePlugin = _HtmlToUDMService._pluginList.find((plugin) => plugin.checkPasteType(html)), dom = parseToDom(html), docData = {
153
156
  body: {
154
157
  dataStream: "",
158
+ paragraphs: [],
159
+ sectionBreaks: [],
160
+ tables: [],
155
161
  textRuns: []
156
162
  },
157
163
  tableSource: {}
@@ -159,11 +165,11 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
159
165
  return pastePlugin && (this._styleRules = [...pastePlugin.stylesRules], this._afterProcessRules = [...pastePlugin.afterProcessRules]), this._tableCache = [], this._styleCache.clear(), this._process(null, dom.childNodes, docData), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], docData;
160
166
  }
161
167
  _process(parent, nodes, doc) {
162
- var _a23, _b, _c;
168
+ var _a22, _b, _c;
163
169
  const body = doc.body;
164
170
  for (const node of nodes)
165
171
  if (node.nodeType === Node.TEXT_NODE) {
166
- if (((_a23 = node.nodeValue) == null ? void 0 : _a23.trim()) === "")
172
+ if (((_a22 = node.nodeValue) == null ? void 0 : _a22.trim()) === "")
167
173
  continue;
168
174
  let text = (_b = node.nodeValue) == null ? void 0 : _b.replace(/[\r\n]/g, ""), style;
169
175
  if (parent && parent.nodeType === Node.ELEMENT_NODE && parent.tagName.toUpperCase() === "A") {
@@ -202,11 +208,11 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
202
208
  }
203
209
  }
204
210
  _processBeforeTable(node, doc) {
205
- var _a23;
211
+ var _a22;
206
212
  const tagName = node.tagName.toUpperCase(), body = doc.body;
207
213
  switch (tagName) {
208
214
  case "TABLE": {
209
- body.dataStream[body.dataStream.length - 1] !== "\r" && (body.dataStream += "\r", (_a23 = body.paragraphs) == null || _a23.push({
215
+ body.dataStream[body.dataStream.length - 1] !== "\r" && (body.dataStream += "\r", body.paragraphs == null && (body.paragraphs = []), (_a22 = body.paragraphs) == null || _a22.push({
210
216
  startIndex: body.dataStream.length - 1
211
217
  }));
212
218
  const table = genTableSource(0, 0, DEFAULT_TABLE_WIDTH);
@@ -229,7 +235,7 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
229
235
  }
230
236
  }
231
237
  _processAfterTable(node, doc) {
232
- var _a23;
238
+ var _a22, _b;
233
239
  const tagName = node.tagName.toUpperCase(), body = doc.body;
234
240
  doc.tableSource == null && (doc.tableSource = {}), body.tables == null && (body.tables = []), body.sectionBreaks == null && (body.sectionBreaks = []);
235
241
  const { tableSource } = doc;
@@ -248,7 +254,9 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
248
254
  break;
249
255
  }
250
256
  case "TD": {
251
- (_a23 = body.sectionBreaks) == null || _a23.push({
257
+ body.dataStream[body.dataStream.length - 1] !== "\r" && ((_a22 = body.paragraphs) == null || _a22.push({
258
+ startIndex: body.dataStream.length
259
+ }), body.dataStream += "\r"), (_b = body.sectionBreaks) == null || _b.push({
252
260
  startIndex: body.dataStream.length
253
261
  }), body.dataStream += `
254
262
  ${DataStreamTreeTokenType.TABLE_CELL_END}`;
@@ -411,7 +419,7 @@ function convertBodyToHtml(body) {
411
419
  }
412
420
  __name(convertBodyToHtml, "convertBodyToHtml");
413
421
  function processNode(node, body, result) {
414
- var _a23;
422
+ var _a22;
415
423
  switch (node.nodeType) {
416
424
  case DataStreamTreeNodeType.SECTION_BREAK: {
417
425
  for (const n2 of node.children)
@@ -419,7 +427,7 @@ function processNode(node, body, result) {
419
427
  break;
420
428
  }
421
429
  case DataStreamTreeNodeType.PARAGRAPH: {
422
- const { children, startIndex, endIndex } = node, paragraph = (_a23 = body.paragraphs.find((p2) => p2.startIndex === endIndex)) != null ? _a23 : {}, { paragraphStyle = {} } = paragraph, { spaceAbove, spaceBelow, lineSpacing } = paragraphStyle, style = [];
430
+ const { children, startIndex, endIndex } = node, paragraph = (_a22 = body.paragraphs.find((p2) => p2.startIndex === endIndex)) != null ? _a22 : {}, { paragraphStyle = {} } = paragraph, { spaceAbove, spaceBelow, lineSpacing } = paragraphStyle, style = [];
423
431
  if (spaceAbove != null && (typeof spaceAbove == "number" ? style.push(`margin-top: ${spaceAbove}px`) : style.push(`margin-top: ${spaceAbove.v}px`)), spaceBelow != null && (typeof spaceBelow == "number" ? style.push(`margin-bottom: ${spaceBelow}px`) : style.push(`margin-bottom: ${spaceBelow.v}px`)), lineSpacing != null && style.push(`line-height: ${lineSpacing}`), result.html += `<p class="UniverNormal" ${style.length ? `style="${style.join("; ")};"` : ""}>`, children.length)
424
432
  for (const table of children)
425
433
  processNode(table, body, result);
@@ -467,18 +475,18 @@ const _UDMToHtmlService = class _UDMToHtmlService {
467
475
  };
468
476
  __name(_UDMToHtmlService, "UDMToHtmlService");
469
477
  let UDMToHtmlService = _UDMToHtmlService;
470
- var __defProp$l = Object.defineProperty, __getOwnPropDesc$l = Object.getOwnPropertyDescriptor, __decorateClass$l = /* @__PURE__ */ __name((decorators, target, key, kind) => {
471
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$l(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
478
+ var __defProp$k = Object.defineProperty, __getOwnPropDesc$k = Object.getOwnPropertyDescriptor, __decorateClass$k = /* @__PURE__ */ __name((decorators, target, key, kind) => {
479
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
472
480
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
473
- return kind && result && __defProp$l(target, key, result), result;
474
- }, "__decorateClass$l"), __decorateParam$l = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$l");
481
+ return kind && result && __defProp$k(target, key, result), result;
482
+ }, "__decorateClass$k"), __decorateParam$k = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$k");
475
483
  HtmlToUDMService.use(PastePluginWord);
476
484
  HtmlToUDMService.use(PastePluginLark);
477
485
  HtmlToUDMService.use(PastePluginUniver);
478
486
  function getTableSlice(body, start, end) {
479
- var _a23, _b, _c;
487
+ var _a22, _b, _c;
480
488
  const bodySlice = getBodySlice(body, start, end + 2), dataStream = DataStreamTreeTokenType.TABLE_START + DataStreamTreeTokenType.TABLE_ROW_START + DataStreamTreeTokenType.TABLE_CELL_START + bodySlice.dataStream + DataStreamTreeTokenType.TABLE_CELL_END + DataStreamTreeTokenType.TABLE_ROW_END + DataStreamTreeTokenType.TABLE_END;
481
- return bodySlice.dataStream = dataStream, (_a23 = bodySlice.textRuns) == null || _a23.forEach((textRun) => {
489
+ return bodySlice.dataStream = dataStream, (_a22 = bodySlice.textRuns) == null || _a22.forEach((textRun) => {
482
490
  const { st, ed } = textRun;
483
491
  textRun.st = st + 3, textRun.ed = ed + 3;
484
492
  }), (_b = bodySlice.tables) == null || _b.forEach((table) => {
@@ -501,12 +509,13 @@ let DocClipboardService = (_a = class extends Disposable {
501
509
  this._univerInstanceService = _univerInstanceService, this._logService = _logService, this._commandService = _commandService, this._clipboardInterfaceService = _clipboardInterfaceService, this._textSelectionManagerService = _textSelectionManagerService, this._docCustomRangeService = _docCustomRangeService;
502
510
  }
503
511
  async copy(sliceType = SliceBodyType.copy) {
504
- const { bodyList, needCache } = this._getDocumentBodyInRanges(sliceType);
505
- if (bodyList.length === 0)
512
+ var _a22;
513
+ const { bodyList = [], needCache = !1, snapshot } = (_a22 = this._getDocumentBodyInRanges(sliceType)) != null ? _a22 : {};
514
+ if (bodyList.length === 0 || snapshot == null)
506
515
  return !1;
507
516
  try {
508
517
  const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), isCopyInHeaderFooter = !!(activeRange != null && activeRange.segmentId);
509
- this._setClipboardData(bodyList, !isCopyInHeaderFooter && needCache);
518
+ this._setClipboardData(bodyList, snapshot, !isCopyInHeaderFooter && needCache);
510
519
  } catch (e) {
511
520
  return this._logService.error("[DocClipboardService] copy failed", e), !1;
512
521
  }
@@ -520,16 +529,23 @@ let DocClipboardService = (_a = class extends Disposable {
520
529
  return this._paste(partDocData);
521
530
  }
522
531
  async legacyPaste(html, text) {
532
+ var _a22;
523
533
  const partDocData = this._genDocDataFromHtmlAndText(html, text);
534
+ if (((_a22 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a22.getUnitId()) === DOCS_NORMAL_EDITOR_UNIT_ID_KEY)
535
+ if (text) {
536
+ const textDocData = this._generateBody(text);
537
+ return this._paste({ body: textDocData });
538
+ } else
539
+ partDocData.body.textRuns = [];
524
540
  return this._paste(partDocData);
525
541
  }
526
542
  async _cut() {
527
- var _a23, _b, _c;
543
+ var _a22, _b, _c;
528
544
  const {
529
545
  segmentId,
530
546
  endOffset: activeEndOffset,
531
547
  style
532
- } = (_a23 = this._textSelectionManagerService.getActiveTextRangeWithStyle()) != null ? _a23 : {}, textRanges = (_b = this._textSelectionManagerService.getCurrentTextRanges()) != null ? _b : [], rectRanges = (_c = this._textSelectionManagerService.getCurrentRectRanges()) != null ? _c : [];
548
+ } = (_a22 = this._textSelectionManagerService.getActiveTextRangeWithStyle()) != null ? _a22 : {}, textRanges = (_b = this._textSelectionManagerService.getCurrentTextRanges()) != null ? _b : [], rectRanges = (_c = this._textSelectionManagerService.getCurrentRectRanges()) != null ? _c : [];
533
549
  if (segmentId == null && this._logService.error("[DocClipboardController] segmentId is not existed"), textRanges.length === 0 && rectRanges.length === 0)
534
550
  return !1;
535
551
  this.copy(SliceBodyType.cut);
@@ -537,11 +553,13 @@ let DocClipboardService = (_a = class extends Disposable {
537
553
  let cursor = 0;
538
554
  if (rectRanges.length > 0)
539
555
  cursor = getCursorWhenDelete(textRanges, rectRanges);
540
- else if (activeEndOffset != null)
556
+ else if (activeEndOffset != null) {
557
+ cursor = activeEndOffset;
541
558
  for (const range of textRanges) {
542
559
  const { startOffset, endOffset } = range;
543
560
  startOffset == null || endOffset == null || endOffset <= activeEndOffset && (cursor -= endOffset - startOffset);
544
561
  }
562
+ }
545
563
  const newTextRanges = [
546
564
  {
547
565
  startOffset: cursor,
@@ -555,12 +573,12 @@ let DocClipboardService = (_a = class extends Disposable {
555
573
  }
556
574
  }
557
575
  async _paste(docData) {
558
- var _a23, _b;
576
+ var _a22, _b;
559
577
  const { body: _body } = docData;
560
578
  if (_body == null)
561
579
  return !1;
562
580
  let body = normalizeBody(_body);
563
- const unitId = (_a23 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a23.getUnitId();
581
+ const unitId = (_a22 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a22.getUnitId();
564
582
  if (!unitId)
565
583
  return !1;
566
584
  this._clipboardHooks.forEach((hook) => {
@@ -594,11 +612,30 @@ let DocClipboardService = (_a = class extends Disposable {
594
612
  return this._logService.error("[DocClipboardController]", "clipboard is empty."), !1;
595
613
  }
596
614
  }
597
- async _setClipboardData(documentBodyList, needCache = !0) {
615
+ async _setClipboardData(documentBodyList, snapshot, needCache = !0) {
616
+ var _a22, _b;
598
617
  const copyId = genId(), text = documentBodyList.length > 1 ? documentBodyList.map((body) => body.dataStream).join(`
599
618
  `) : documentBodyList[0].dataStream;
600
619
  let html = this._umdToHtml.convert(documentBodyList);
601
- return documentBodyList.length === 1 && needCache && (html = html.replace(/(<[a-z]+)/, (_p0, p1) => `${p1} data-copy-id="${copyId}"`), copyContentCache.set(copyId, { body: documentBodyList[0] })), this._clipboardInterfaceService.write(text, html);
620
+ if (documentBodyList.length === 1 && needCache) {
621
+ html = html.replace(/(<[a-z]+)/, (_p0, p1) => `${p1} data-copy-id="${copyId}"`);
622
+ const body = documentBodyList[0], cache = { body };
623
+ if ((_a22 = body.customBlocks) != null && _a22.length) {
624
+ cache.drawings = {};
625
+ for (const block of body.customBlocks) {
626
+ const { blockId } = block, drawing = (_b = snapshot.drawings) == null ? void 0 : _b[blockId];
627
+ if (drawing) {
628
+ const id = Tools.generateRandomId(6);
629
+ block.blockId = id, cache.drawings[id] = {
630
+ ...Tools.deepClone(drawing),
631
+ drawingId: id
632
+ };
633
+ }
634
+ }
635
+ }
636
+ copyContentCache.set(copyId, cache);
637
+ }
638
+ return this._clipboardInterfaceService.write(text, html);
602
639
  }
603
640
  addClipboardHook(hook) {
604
641
  return this._clipboardHooks.push(hook), toDisposable(() => {
@@ -608,50 +645,45 @@ let DocClipboardService = (_a = class extends Disposable {
608
645
  }
609
646
  // eslint-disable-next-line max-lines-per-function
610
647
  _getDocumentBodyInRanges(sliceType) {
611
- var _a23;
648
+ var _a22;
612
649
  const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance(), allRanges = this._textSelectionManagerService.getDocRanges(), results = [];
613
650
  let needCache = !0;
614
651
  if (docDataModel == null || allRanges.length === 0)
652
+ return;
653
+ const segmentId = allRanges[0].segmentId, body = (_a22 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a22.getBody(), snapshot = docDataModel.getSnapshot();
654
+ if (body != null) {
655
+ for (const range of allRanges) {
656
+ const { startOffset, endOffset, collapsed, rangeType } = range;
657
+ if (collapsed || startOffset == null || endOffset == null)
658
+ continue;
659
+ if (rangeType === DOC_RANGE_TYPE.RECT) {
660
+ needCache = !1;
661
+ const { spanEntireRow } = range;
662
+ let bodySlice;
663
+ bodySlice = getTableSlice(body, startOffset, endOffset), results.push(bodySlice);
664
+ continue;
665
+ }
666
+ const deleteRange = getDeleteSelection({ startOffset, endOffset, collapsed }, body), docBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
667
+ if (docBody != null) {
668
+ if (docBody.customRanges) {
669
+ const deleteRange2 = [];
670
+ docBody.customRanges.forEach((range2) => {
671
+ range2.startIndex === range2.endIndex && deleteRange2.push(range2);
672
+ }), docBody.customRanges = docBody.customRanges.filter((range2) => deleteRange2.indexOf(range2) === -1);
673
+ let text = "", cursor = 0;
674
+ deleteRange2.forEach((range2) => {
675
+ text += docBody.dataStream.slice(cursor, range2.endIndex), cursor = range2.endIndex + 1;
676
+ }), text += docBody.dataStream.slice(cursor, docBody.dataStream.length), docBody.dataStream = text;
677
+ }
678
+ results.push(docBody);
679
+ }
680
+ }
615
681
  return {
616
682
  bodyList: results,
617
- needCache
618
- };
619
- const segmentId = allRanges[0].segmentId, body = (_a23 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a23.getBody();
620
- if (body == null)
621
- return {
622
- bodyList: results,
623
- needCache
683
+ needCache,
684
+ snapshot
624
685
  };
625
- for (const range of allRanges) {
626
- const { startOffset, endOffset, collapsed, rangeType } = range;
627
- if (collapsed || startOffset == null || endOffset == null)
628
- continue;
629
- if (rangeType === DOC_RANGE_TYPE.RECT) {
630
- needCache = !1;
631
- const { spanEntireRow } = range;
632
- let bodySlice;
633
- bodySlice = getTableSlice(body, startOffset, endOffset), results.push(bodySlice);
634
- continue;
635
- }
636
- const deleteRange = getDeleteSelection({ startOffset, endOffset, collapsed }, body), docBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
637
- if (docBody != null) {
638
- if (docBody.customRanges) {
639
- const deleteRange2 = [];
640
- docBody.customRanges.forEach((range2) => {
641
- range2.startIndex === range2.endIndex && deleteRange2.push(range2);
642
- }), docBody.customRanges = docBody.customRanges.filter((range2) => deleteRange2.indexOf(range2) === -1);
643
- let text = "", cursor = 0;
644
- deleteRange2.forEach((range2) => {
645
- text += docBody.dataStream.slice(cursor, range2.endIndex), cursor = range2.endIndex + 1;
646
- }), text += docBody.dataStream.slice(cursor, docBody.dataStream.length), docBody.dataStream = text;
647
- }
648
- results.push(docBody);
649
- }
650
686
  }
651
- return {
652
- bodyList: results,
653
- needCache
654
- };
655
687
  }
656
688
  async _genDocDataFromClipboardItems(items) {
657
689
  try {
@@ -705,19 +737,19 @@ let DocClipboardService = (_a = class extends Disposable {
705
737
  return this._htmlToUDM.convert(html);
706
738
  }
707
739
  }, __name(_a, "DocClipboardService"), _a);
708
- DocClipboardService = __decorateClass$l([
709
- __decorateParam$l(0, IUniverInstanceService),
710
- __decorateParam$l(1, ILogService),
711
- __decorateParam$l(2, ICommandService),
712
- __decorateParam$l(3, IClipboardInterfaceService),
713
- __decorateParam$l(4, Inject(TextSelectionManagerService)),
714
- __decorateParam$l(5, Inject(DocCustomRangeService))
740
+ DocClipboardService = __decorateClass$k([
741
+ __decorateParam$k(0, IUniverInstanceService),
742
+ __decorateParam$k(1, ILogService),
743
+ __decorateParam$k(2, ICommandService),
744
+ __decorateParam$k(3, IClipboardInterfaceService),
745
+ __decorateParam$k(4, Inject(TextSelectionManagerService)),
746
+ __decorateParam$k(5, Inject(DocCustomRangeService))
715
747
  ], DocClipboardService);
716
- var __defProp$k = Object.defineProperty, __getOwnPropDesc$k = Object.getOwnPropertyDescriptor, __decorateClass$k = /* @__PURE__ */ __name((decorators, target, key, kind) => {
717
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
748
+ var __defProp$j = Object.defineProperty, __getOwnPropDesc$j = Object.getOwnPropertyDescriptor, __decorateClass$j = /* @__PURE__ */ __name((decorators, target, key, kind) => {
749
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
718
750
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
719
- return kind && result && __defProp$k(target, key, result), result;
720
- }, "__decorateClass$k"), __decorateParam$k = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$k");
751
+ return kind && result && __defProp$j(target, key, result), result;
752
+ }, "__decorateClass$j"), __decorateParam$j = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$j");
721
753
  const ANCHOR_WIDTH = 1.5;
722
754
  var _a2;
723
755
  let DocBackScrollRenderController = (_a2 = class extends RxDisposable {
@@ -733,16 +765,16 @@ let DocBackScrollRenderController = (_a2 = class extends RxDisposable {
733
765
  });
734
766
  }
735
767
  scrollToRange(unitId, range) {
736
- var _a23;
737
- const docSkeletonManagerService = (_a23 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a23.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
768
+ var _a22;
769
+ const docSkeletonManagerService = (_a22 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a22.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
738
770
  if (!skeleton)
739
771
  return;
740
772
  const { startOffset } = range, anchorNodePosition = skeleton.findNodePositionByCharIndex(startOffset);
741
773
  this.scrollToNode(unitId, anchorNodePosition);
742
774
  }
743
775
  scrollToNode(unitId, startNodePosition) {
744
- var _a23;
745
- const docObject = this._getDocObject(), docSkeletonManagerService = (_a23 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a23.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
776
+ var _a22;
777
+ const docObject = this._getDocObject(), docSkeletonManagerService = (_a22 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a22.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
746
778
  if (docObject == null || skeleton == null)
747
779
  return;
748
780
  const documentOffsetConfig = docObject.document.getOffsetConfig(), { docsLeft, docsTop } = documentOffsetConfig, convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { contentBoxPointGroup } = convertor.getRangePointData(startNodePosition, startNodePosition), { left: aLeft, top: aTop, height } = getAnchorBounding(contentBoxPointGroup), left = aLeft + docsLeft, top = aTop + docsTop, viewportMain = docObject.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN), isEditor = !!this._editorService.getEditor(unitId);
@@ -772,11 +804,11 @@ let DocBackScrollRenderController = (_a2 = class extends RxDisposable {
772
804
  return getDocObject(this._univerInstanceService, this._renderManagerService);
773
805
  }
774
806
  }, __name(_a2, "DocBackScrollRenderController"), _a2);
775
- DocBackScrollRenderController = __decorateClass$k([
776
- __decorateParam$k(1, Inject(TextSelectionManagerService)),
777
- __decorateParam$k(2, IEditorService),
778
- __decorateParam$k(3, Inject(IUniverInstanceService)),
779
- __decorateParam$k(4, IRenderManagerService)
807
+ DocBackScrollRenderController = __decorateClass$j([
808
+ __decorateParam$j(1, Inject(TextSelectionManagerService)),
809
+ __decorateParam$j(2, IEditorService),
810
+ __decorateParam$j(3, Inject(IUniverInstanceService)),
811
+ __decorateParam$j(4, IRenderManagerService)
780
812
  ], DocBackScrollRenderController);
781
813
  const DefaultToolbarConfig = {
782
814
  undo: !0,
@@ -885,11 +917,11 @@ const DefaultToolbarConfig = {
885
917
  binding: KeyCode.A | MetaKeys.CTRL_COMMAND,
886
918
  preconditions: /* @__PURE__ */ __name((contextService) => contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && (contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED)), "preconditions")
887
919
  };
888
- var __defProp$j = Object.defineProperty, __getOwnPropDesc$j = Object.getOwnPropertyDescriptor, __decorateClass$j = /* @__PURE__ */ __name((decorators, target, key, kind) => {
889
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
920
+ var __defProp$i = Object.defineProperty, __getOwnPropDesc$i = Object.getOwnPropertyDescriptor, __decorateClass$i = /* @__PURE__ */ __name((decorators, target, key, kind) => {
921
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
890
922
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
891
- return kind && result && __defProp$j(target, key, result), result;
892
- }, "__decorateClass$j"), __decorateParam$j = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$j"), _a3;
923
+ return kind && result && __defProp$i(target, key, result), result;
924
+ }, "__decorateClass$i"), __decorateParam$i = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$i"), _a3;
893
925
  let DocContainerUIController = (_a3 = class {
894
926
  constructor(_config, _localeService, _injector) {
895
927
  __publicField(this, "_docContainer");
@@ -929,15 +961,15 @@ let DocContainerUIController = (_a3 = class {
929
961
  return this._docContainer;
930
962
  }
931
963
  }, __name(_a3, "DocContainerUIController"), _a3);
932
- DocContainerUIController = __decorateClass$j([
933
- __decorateParam$j(1, Inject(LocaleService)),
934
- __decorateParam$j(2, Inject(Injector))
964
+ DocContainerUIController = __decorateClass$i([
965
+ __decorateParam$i(1, Inject(LocaleService)),
966
+ __decorateParam$i(2, Inject(Injector))
935
967
  ], DocContainerUIController);
936
- var __defProp$i = Object.defineProperty, __getOwnPropDesc$i = Object.getOwnPropertyDescriptor, __decorateClass$i = /* @__PURE__ */ __name((decorators, target, key, kind) => {
937
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
968
+ var __defProp$h = Object.defineProperty, __getOwnPropDesc$h = Object.getOwnPropertyDescriptor, __decorateClass$h = /* @__PURE__ */ __name((decorators, target, key, kind) => {
969
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
938
970
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
939
- return kind && result && __defProp$i(target, key, result), result;
940
- }, "__decorateClass$i"), __decorateParam$i = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$i"), _a4;
971
+ return kind && result && __defProp$h(target, key, result), result;
972
+ }, "__decorateClass$h"), __decorateParam$h = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$h"), _a4;
941
973
  let AppUIController = (_a4 = class extends RxDisposable {
942
974
  constructor(_config, _localeService, _injector, _textSelectionRenderManager, _layoutService) {
943
975
  super();
@@ -964,11 +996,11 @@ let AppUIController = (_a4 = class extends RxDisposable {
964
996
  return this._docContainerController;
965
997
  }
966
998
  }, __name(_a4, "AppUIController"), _a4);
967
- AppUIController = __decorateClass$i([
968
- __decorateParam$i(1, Inject(LocaleService)),
969
- __decorateParam$i(2, Inject(Injector)),
970
- __decorateParam$i(3, ITextSelectionRenderManager),
971
- __decorateParam$i(4, Optional(ILayoutService))
999
+ AppUIController = __decorateClass$h([
1000
+ __decorateParam$h(1, Inject(LocaleService)),
1001
+ __decorateParam$h(2, Inject(Injector)),
1002
+ __decorateParam$h(3, ITextSelectionRenderManager),
1003
+ __decorateParam$h(4, Optional(ILayoutService))
972
1004
  ], AppUIController);
973
1005
  var __assign = function() {
974
1006
  return __assign = Object.assign || function(t) {
@@ -999,15 +1031,15 @@ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
999
1031
  var attrs = __assign({}, node.attrs);
1000
1032
  extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
1001
1033
  var defIds = runtimeProps.defIds;
1002
- return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a23) {
1003
- var key = _a23[0], value = _a23[1];
1034
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a22) {
1035
+ var key = _a22[0], value = _a22[1];
1004
1036
  typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
1005
1037
  })), attrs;
1006
1038
  }
1007
1039
  __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
1008
1040
  function replaceRuntimeIdsInDefs(node, runtimeProps) {
1009
- var _a23, defIds = runtimeProps.defIds;
1010
- return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a23 = node.children) === null || _a23 === void 0) && _a23.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
1041
+ var _a22, defIds = runtimeProps.defIds;
1042
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a22 = node.children) === null || _a22 === void 0) && _a22.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
1011
1043
  return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
1012
1044
  }) }) : node;
1013
1045
  }
@@ -1142,12 +1174,12 @@ const panel = "univer-panel", optionsSection = "univer-options-section", options
1142
1174
  optionsMarginSetting
1143
1175
  }, DocHeaderFooterOptions = /* @__PURE__ */ __name((props) => {
1144
1176
  const localeService = useDependency(LocaleService), univerInstanceService = useDependency(IUniverInstanceService), renderManagerService = useDependency(IRenderManagerService), commandService = useDependency(ICommandService), textSelectionRenderService = useDependency(ITextSelectionRenderManager), textSelectionManagerService = useDependency(TextSelectionManagerService), { unitId } = props, [options, setOptions] = useState({}), handleCheckboxChange = /* @__PURE__ */ __name((val, type) => {
1145
- var _a23;
1177
+ var _a22;
1146
1178
  setOptions((prev) => ({
1147
1179
  ...prev,
1148
1180
  [type]: val ? BooleanNumber.TRUE : BooleanNumber.FALSE
1149
1181
  }));
1150
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId), documentStyle = docDataModel == null ? void 0 : docDataModel.getSnapshot().documentStyle, docSkeletonManagerService = (_a23 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a23.with(DocSkeletonManagerService), viewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel();
1182
+ const docDataModel = univerInstanceService.getUniverDocInstance(unitId), documentStyle = docDataModel == null ? void 0 : docDataModel.getSnapshot().documentStyle, docSkeletonManagerService = (_a22 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a22.with(DocSkeletonManagerService), viewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel();
1151
1183
  if (documentStyle == null || viewModel == null)
1152
1184
  return;
1153
1185
  const editArea = viewModel.getEditArea();
@@ -1181,12 +1213,12 @@ const panel = "univer-panel", optionsSection = "univer-options-section", options
1181
1213
  }
1182
1214
  }), textSelectionRenderService.removeAllRanges(), textSelectionRenderService.blur();
1183
1215
  }, "handleMarginChange"), closeHeaderFooter = /* @__PURE__ */ __name(() => {
1184
- var _a23;
1216
+ var _a22;
1185
1217
  const renderObject = renderManagerService.getRenderById(unitId);
1186
1218
  if (renderObject == null)
1187
1219
  return;
1188
1220
  const { scene } = renderObject, transformer = scene.getTransformerByCreate(), docSkeletonManagerService = renderObject.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton(), viewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel(), render2 = renderManagerService.getRenderById(unitId);
1189
- render2 == null || viewModel == null || skeleton == null || (textSelectionManagerService.replaceTextRanges([]), transformer.clearSelectedObjects(), textSelectionRenderService.setSegment(""), textSelectionRenderService.setSegmentPage(-1), viewModel.setEditArea(DocumentEditArea.BODY), skeleton.calculate(), (_a23 = render2.mainComponent) == null || _a23.makeDirty(!0));
1221
+ render2 == null || viewModel == null || skeleton == null || (textSelectionManagerService.replaceTextRanges([]), transformer.clearSelectedObjects(), textSelectionRenderService.setSegment(""), textSelectionRenderService.setSegmentPage(-1), viewModel.setEditArea(DocumentEditArea.BODY), skeleton.calculate(), (_a22 = render2.mainComponent) == null || _a22.makeDirty(!0));
1190
1222
  }, "closeHeaderFooter");
1191
1223
  return useEffect(() => {
1192
1224
  const docDataModel = univerInstanceService.getUniverDocInstance(unitId), documentStyle = docDataModel == null ? void 0 : docDataModel.getSnapshot().documentStyle;
@@ -1264,8 +1296,8 @@ const panel = "univer-panel", optionsSection = "univer-options-section", options
1264
1296
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$5.optionsSection, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: closeHeaderFooter, children: localeService.t("headerFooter.closeHeaderFooter") }) })
1265
1297
  ] });
1266
1298
  }, "DocHeaderFooterOptions"), DocHeaderFooterPanel = /* @__PURE__ */ __name(() => {
1267
- var _a23;
1268
- const localeService = useDependency(LocaleService), renderManagerService = useDependency(IRenderManagerService), unitId = useDependency(IUniverInstanceService).getCurrentUniverDocInstance().getUnitId(), viewModel = ((_a23 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a23.with(DocSkeletonManagerService)).getViewModel(), [isEditHeaderFooter, setIsEditHeaderFooter] = useState(!0);
1299
+ var _a22;
1300
+ const localeService = useDependency(LocaleService), renderManagerService = useDependency(IRenderManagerService), unitId = useDependency(IUniverInstanceService).getCurrentUniverDocInstance().getUnitId(), viewModel = ((_a22 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a22.with(DocSkeletonManagerService)).getViewModel(), [isEditHeaderFooter, setIsEditHeaderFooter] = useState(!0);
1269
1301
  return useEffect(() => {
1270
1302
  const editArea = viewModel.getEditArea();
1271
1303
  setIsEditHeaderFooter(editArea !== DocumentEditArea.BODY);
@@ -1277,11 +1309,11 @@ const panel = "univer-panel", optionsSection = "univer-options-section", options
1277
1309
  };
1278
1310
  }, []), /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$5.panel, children: isEditHeaderFooter ? /* @__PURE__ */ jsxRuntimeExports.jsx(DocHeaderFooterOptions, { unitId }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$5.panelDisableText, children: localeService.t("headerFooter.disableText") }) });
1279
1311
  }, "DocHeaderFooterPanel");
1280
- var __defProp$h = Object.defineProperty, __getOwnPropDesc$h = Object.getOwnPropertyDescriptor, __decorateClass$h = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1281
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1312
+ var __defProp$g = Object.defineProperty, __getOwnPropDesc$g = Object.getOwnPropertyDescriptor, __decorateClass$g = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1313
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1282
1314
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1283
- return kind && result && __defProp$h(target, key, result), result;
1284
- }, "__decorateClass$h"), __decorateParam$h = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$h");
1315
+ return kind && result && __defProp$g(target, key, result), result;
1316
+ }, "__decorateClass$g"), __decorateParam$g = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$g");
1285
1317
  const HEADER_FOOTER_STROKE_COLOR = "rgba(58, 96, 247, 1)", HEADER_FOOTER_FILL_COLOR = "rgba(58, 96, 247, 0.08)";
1286
1318
  var HeaderFooterType = /* @__PURE__ */ ((HeaderFooterType2) => (HeaderFooterType2[HeaderFooterType2.FIRST_PAGE_HEADER = 0] = "FIRST_PAGE_HEADER", HeaderFooterType2[HeaderFooterType2.FIRST_PAGE_FOOTER = 1] = "FIRST_PAGE_FOOTER", HeaderFooterType2[HeaderFooterType2.DEFAULT_HEADER = 2] = "DEFAULT_HEADER", HeaderFooterType2[HeaderFooterType2.DEFAULT_FOOTER = 3] = "DEFAULT_FOOTER", HeaderFooterType2[HeaderFooterType2.EVEN_PAGE_HEADER = 4] = "EVEN_PAGE_HEADER", HeaderFooterType2[HeaderFooterType2.EVEN_PAGE_FOOTER = 5] = "EVEN_PAGE_FOOTER", HeaderFooterType2))(HeaderFooterType || {});
1287
1319
  function checkCreateHeaderFooterType(viewModel, editArea, segmentPage) {
@@ -1472,15 +1504,15 @@ let DocHeaderFooterController = (_a5 = class extends Disposable {
1472
1504
  return this._context.unit;
1473
1505
  }
1474
1506
  }, __name(_a5, "DocHeaderFooterController"), _a5);
1475
- DocHeaderFooterController = __decorateClass$h([
1476
- __decorateParam$h(1, ICommandService),
1477
- __decorateParam$h(2, IEditorService),
1478
- __decorateParam$h(3, IUniverInstanceService),
1479
- __decorateParam$h(4, IRenderManagerService),
1480
- __decorateParam$h(5, Inject(DocSkeletonManagerService)),
1481
- __decorateParam$h(6, ITextSelectionRenderManager),
1482
- __decorateParam$h(7, Inject(LocaleService)),
1483
- __decorateParam$h(8, Inject(ComponentManager))
1507
+ DocHeaderFooterController = __decorateClass$g([
1508
+ __decorateParam$g(1, ICommandService),
1509
+ __decorateParam$g(2, IEditorService),
1510
+ __decorateParam$g(3, IUniverInstanceService),
1511
+ __decorateParam$g(4, IRenderManagerService),
1512
+ __decorateParam$g(5, Inject(DocSkeletonManagerService)),
1513
+ __decorateParam$g(6, ITextSelectionRenderManager),
1514
+ __decorateParam$g(7, Inject(LocaleService)),
1515
+ __decorateParam$g(8, Inject(ComponentManager))
1484
1516
  ], DocHeaderFooterController);
1485
1517
  const SidebarDocHeaderFooterPanelOperation = {
1486
1518
  id: "sidebar.operation.doc-header-footer-panel",
@@ -1586,8 +1618,8 @@ const CoreHeaderFooterCommandId = "doc.command.core-header-footer", CoreHeaderFo
1586
1618
  type: CommandType.COMMAND,
1587
1619
  // eslint-disable-next-line max-lines-per-function
1588
1620
  handler: /* @__PURE__ */ __name(async (accessor, params) => {
1589
- var _a23;
1590
- const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), { unitId, segmentId, createType, headerFooterProps } = params, docSkeletonManagerService = (_a23 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a23.with(DocSkeletonManagerService), docDataModel = univerInstanceService.getUniverDocInstance(unitId), docViewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel();
1621
+ var _a22;
1622
+ const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), { unitId, segmentId, createType, headerFooterProps } = params, docSkeletonManagerService = (_a22 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a22.with(DocSkeletonManagerService), docDataModel = univerInstanceService.getUniverDocInstance(unitId), docViewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel();
1591
1623
  if (docDataModel == null || docViewModel == null)
1592
1624
  return !1;
1593
1625
  const editArea = docViewModel.getEditArea(), { documentStyle } = docDataModel.getSnapshot(), isUpdateMargin = (headerFooterProps == null ? void 0 : headerFooterProps.marginFooter) != null || (headerFooterProps == null ? void 0 : headerFooterProps.marginHeader) != null, textRanges = [{
@@ -1628,9 +1660,9 @@ const CoreHeaderFooterCommandId = "doc.command.core-header-footer", CoreHeaderFo
1628
1660
  }, ZOOM_MAP = [50, 80, 100, 130, 150, 170, 200, 400], DOC_ZOOM_RANGE = [10, 400];
1629
1661
  function ZoomSlider() {
1630
1662
  const commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), currentDoc$ = useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), []), documentDataModel = useObservable(currentDoc$), getCurrentZoom = useCallback(() => {
1631
- var _a23, _b;
1663
+ var _a22, _b;
1632
1664
  if (!documentDataModel) return 100;
1633
- const currentZoom = ((_b = (_a23 = documentDataModel.getSettings()) == null ? void 0 : _a23.zoomRatio) != null ? _b : 1) * 100;
1665
+ const currentZoom = ((_b = (_a22 = documentDataModel.getSettings()) == null ? void 0 : _a22.zoomRatio) != null ? _b : 1) * 100;
1634
1666
  return Math.round(currentZoom);
1635
1667
  }, [documentDataModel]), [zoom, setZoom] = useState(() => getCurrentZoom());
1636
1668
  useEffect(() => (setZoom(getCurrentZoom()), commandService.onCommandExecuted((commandInfo) => {
@@ -1903,6 +1935,25 @@ function getTableDisabledObservable(accessor) {
1903
1935
  });
1904
1936
  }
1905
1937
  __name(getTableDisabledObservable, "getTableDisabledObservable");
1938
+ function disableMenuWhenNoDocRange(accessor) {
1939
+ const textSelectionManagerService = accessor.get(TextSelectionManagerService);
1940
+ return new Observable((subscriber) => {
1941
+ const subscription = textSelectionManagerService.textSelection$.subscribe((selection) => {
1942
+ if (selection == null) {
1943
+ subscriber.next(!0);
1944
+ return;
1945
+ }
1946
+ const { textRanges, rectRanges } = selection;
1947
+ if (textRanges.length === 0 && rectRanges.length === 0) {
1948
+ subscriber.next(!0);
1949
+ return;
1950
+ }
1951
+ subscriber.next(!1);
1952
+ });
1953
+ return () => subscription.unsubscribe();
1954
+ });
1955
+ }
1956
+ __name(disableMenuWhenNoDocRange, "disableMenuWhenNoDocRange");
1906
1957
  function BoldMenuItemFactory(accessor) {
1907
1958
  const commandService = accessor.get(ICommandService);
1908
1959
  return {
@@ -1915,18 +1966,21 @@ function BoldMenuItemFactory(accessor) {
1915
1966
  positions: [MenuPosition.TOOLBAR_START],
1916
1967
  activated$: new Observable((subscriber) => {
1917
1968
  const disposable = commandService.onCommandExecuted((c) => {
1918
- var _a23;
1969
+ var _a22;
1919
1970
  const id = c.id;
1920
1971
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1921
1972
  const textRun = getFontStyleAtCursor(accessor);
1922
- if (textRun == null)
1973
+ if (textRun == null) {
1974
+ subscriber.next(!1);
1923
1975
  return;
1924
- const bl = (_a23 = textRun.ts) == null ? void 0 : _a23.bl;
1976
+ }
1977
+ const bl = (_a22 = textRun.ts) == null ? void 0 : _a22.bl;
1925
1978
  subscriber.next(bl === BooleanNumber.TRUE);
1926
1979
  }
1927
1980
  });
1928
1981
  return subscriber.next(!1), disposable.dispose;
1929
1982
  }),
1983
+ disabled$: disableMenuWhenNoDocRange(accessor),
1930
1984
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1931
1985
  };
1932
1986
  }
@@ -1943,18 +1997,21 @@ function ItalicMenuItemFactory(accessor) {
1943
1997
  positions: [MenuPosition.TOOLBAR_START],
1944
1998
  activated$: new Observable((subscriber) => {
1945
1999
  const disposable = commandService.onCommandExecuted((c) => {
1946
- var _a23;
2000
+ var _a22;
1947
2001
  const id = c.id;
1948
2002
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1949
2003
  const textRun = getFontStyleAtCursor(accessor);
1950
- if (textRun == null)
2004
+ if (textRun == null) {
2005
+ subscriber.next(!1);
1951
2006
  return;
1952
- const it = (_a23 = textRun.ts) == null ? void 0 : _a23.it;
2007
+ }
2008
+ const it = (_a22 = textRun.ts) == null ? void 0 : _a22.it;
1953
2009
  subscriber.next(it === BooleanNumber.TRUE);
1954
2010
  }
1955
2011
  });
1956
2012
  return subscriber.next(!1), disposable.dispose;
1957
2013
  }),
2014
+ disabled$: disableMenuWhenNoDocRange(accessor),
1958
2015
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1959
2016
  };
1960
2017
  }
@@ -1971,18 +2028,21 @@ function UnderlineMenuItemFactory(accessor) {
1971
2028
  positions: [MenuPosition.TOOLBAR_START],
1972
2029
  activated$: new Observable((subscriber) => {
1973
2030
  const disposable = commandService.onCommandExecuted((c) => {
1974
- var _a23;
2031
+ var _a22;
1975
2032
  const id = c.id;
1976
2033
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1977
2034
  const textRun = getFontStyleAtCursor(accessor);
1978
- if (textRun == null)
2035
+ if (textRun == null) {
2036
+ subscriber.next(!1);
1979
2037
  return;
1980
- const ul = (_a23 = textRun.ts) == null ? void 0 : _a23.ul;
2038
+ }
2039
+ const ul = (_a22 = textRun.ts) == null ? void 0 : _a22.ul;
1981
2040
  subscriber.next((ul == null ? void 0 : ul.s) === BooleanNumber.TRUE);
1982
2041
  }
1983
2042
  });
1984
2043
  return subscriber.next(!1), disposable.dispose;
1985
2044
  }),
2045
+ disabled$: disableMenuWhenNoDocRange(accessor),
1986
2046
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1987
2047
  };
1988
2048
  }
@@ -1999,18 +2059,21 @@ function StrikeThroughMenuItemFactory(accessor) {
1999
2059
  positions: [MenuPosition.TOOLBAR_START],
2000
2060
  activated$: new Observable((subscriber) => {
2001
2061
  const disposable = commandService.onCommandExecuted((c) => {
2002
- var _a23;
2062
+ var _a22;
2003
2063
  const id = c.id;
2004
2064
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2005
2065
  const textRun = getFontStyleAtCursor(accessor);
2006
- if (textRun == null)
2066
+ if (textRun == null) {
2067
+ subscriber.next(!1);
2007
2068
  return;
2008
- const st = (_a23 = textRun.ts) == null ? void 0 : _a23.st;
2069
+ }
2070
+ const st = (_a22 = textRun.ts) == null ? void 0 : _a22.st;
2009
2071
  subscriber.next((st == null ? void 0 : st.s) === BooleanNumber.TRUE);
2010
2072
  }
2011
2073
  });
2012
2074
  return subscriber.next(!1), disposable.dispose;
2013
2075
  }),
2076
+ disabled$: disableMenuWhenNoDocRange(accessor),
2014
2077
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2015
2078
  };
2016
2079
  }
@@ -2026,18 +2089,21 @@ function SubscriptMenuItemFactory(accessor) {
2026
2089
  positions: [MenuPosition.TOOLBAR_START],
2027
2090
  activated$: new Observable((subscriber) => {
2028
2091
  const disposable = commandService.onCommandExecuted((c) => {
2029
- var _a23;
2092
+ var _a22;
2030
2093
  const id = c.id;
2031
2094
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2032
2095
  const textRun = getFontStyleAtCursor(accessor);
2033
- if (textRun == null)
2096
+ if (textRun == null) {
2097
+ subscriber.next(!1);
2034
2098
  return;
2035
- const va = (_a23 = textRun.ts) == null ? void 0 : _a23.va;
2099
+ }
2100
+ const va = (_a22 = textRun.ts) == null ? void 0 : _a22.va;
2036
2101
  subscriber.next(va === BaselineOffset.SUBSCRIPT);
2037
2102
  }
2038
2103
  });
2039
2104
  return subscriber.next(!1), disposable.dispose;
2040
2105
  }),
2106
+ disabled$: disableMenuWhenNoDocRange(accessor),
2041
2107
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2042
2108
  };
2043
2109
  }
@@ -2053,18 +2119,21 @@ function SuperscriptMenuItemFactory(accessor) {
2053
2119
  positions: [MenuPosition.TOOLBAR_START],
2054
2120
  activated$: new Observable((subscriber) => {
2055
2121
  const disposable = commandService.onCommandExecuted((c) => {
2056
- var _a23;
2122
+ var _a22;
2057
2123
  const id = c.id;
2058
2124
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2059
2125
  const textRun = getFontStyleAtCursor(accessor);
2060
- if (textRun == null)
2126
+ if (textRun == null) {
2127
+ subscriber.next(!1);
2061
2128
  return;
2062
- const va = (_a23 = textRun.ts) == null ? void 0 : _a23.va;
2129
+ }
2130
+ const va = (_a22 = textRun.ts) == null ? void 0 : _a22.va;
2063
2131
  subscriber.next(va === BaselineOffset.SUPERSCRIPT);
2064
2132
  }
2065
2133
  });
2066
2134
  return subscriber.next(!1), disposable.dispose;
2067
2135
  }),
2136
+ disabled$: disableMenuWhenNoDocRange(accessor),
2068
2137
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2069
2138
  };
2070
2139
  }
@@ -2088,18 +2157,21 @@ function FontFamilySelectorMenuItemFactory(accessor) {
2088
2157
  // disabled$: getCurrentSheetDisabled$(accessor),
2089
2158
  value$: new Observable((subscriber) => {
2090
2159
  const defaultValue = FONT_FAMILY_LIST[0].value, disposable = commandService.onCommandExecuted((c) => {
2091
- var _a23;
2160
+ var _a22;
2092
2161
  const id = c.id;
2093
2162
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontFamilyCommand.id) {
2094
2163
  const textRun = getFontStyleAtCursor(accessor);
2095
- if (textRun == null)
2164
+ if (textRun == null) {
2165
+ subscriber.next(defaultValue);
2096
2166
  return;
2097
- const ff = (_a23 = textRun.ts) == null ? void 0 : _a23.ff;
2167
+ }
2168
+ const ff = (_a22 = textRun.ts) == null ? void 0 : _a22.ff;
2098
2169
  subscriber.next(ff != null ? ff : defaultValue);
2099
2170
  }
2100
2171
  });
2101
2172
  return subscriber.next(defaultValue), disposable.dispose;
2102
2173
  }),
2174
+ disabled$: disableMenuWhenNoDocRange(accessor),
2103
2175
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2104
2176
  };
2105
2177
  }
@@ -2124,18 +2196,21 @@ function FontSizeSelectorMenuItemFactory(accessor) {
2124
2196
  // disabled$,
2125
2197
  value$: new Observable((subscriber) => {
2126
2198
  const disposable = commandService.onCommandExecuted((c) => {
2127
- var _a23;
2199
+ var _a22;
2128
2200
  const id = c.id;
2129
2201
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontSizeCommand.id) {
2130
2202
  const textRun = getFontStyleAtCursor(accessor);
2131
- if (textRun == null)
2203
+ if (textRun == null) {
2204
+ subscriber.next(14);
2132
2205
  return;
2133
- const fs = (_a23 = textRun.ts) == null ? void 0 : _a23.fs;
2206
+ }
2207
+ const fs = (_a22 = textRun.ts) == null ? void 0 : _a22.fs;
2134
2208
  subscriber.next(fs != null ? fs : 14);
2135
2209
  }
2136
2210
  });
2137
2211
  return subscriber.next(14), disposable.dispose;
2138
2212
  }),
2213
+ disabled$: disableMenuWhenNoDocRange(accessor),
2139
2214
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2140
2215
  };
2141
2216
  }
@@ -2166,6 +2241,7 @@ function TextColorSelectorMenuItemFactory(accessor) {
2166
2241
  });
2167
2242
  return subscriber.next(defaultColor), disposable.dispose;
2168
2243
  }),
2244
+ disabled$: disableMenuWhenNoDocRange(accessor),
2169
2245
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2170
2246
  // disabled$: getCurrentSheetDisabled$(accessor),
2171
2247
  };
@@ -2217,15 +2293,16 @@ function AlignLeftMenuItemFactory(accessor) {
2217
2293
  icon: "LeftJustifyingSingle",
2218
2294
  tooltip: "toolbar.alignLeft",
2219
2295
  positions: [MenuPosition.TOOLBAR_START],
2296
+ disabled$: disableMenuWhenNoDocRange(accessor),
2220
2297
  activated$: new Observable((subscriber) => {
2221
2298
  const disposable = commandService.onCommandExecuted((c) => {
2222
- var _a23;
2299
+ var _a22;
2223
2300
  const id = c.id;
2224
2301
  if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2225
2302
  const paragraph = getParagraphStyleAtCursor(accessor);
2226
2303
  if (paragraph == null)
2227
2304
  return;
2228
- const alignType = (_a23 = paragraph.paragraphStyle) == null ? void 0 : _a23.horizontalAlign;
2305
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2229
2306
  subscriber.next(alignType === HorizontalAlign.LEFT);
2230
2307
  }
2231
2308
  });
@@ -2246,18 +2323,19 @@ function AlignCenterMenuItemFactory(accessor) {
2246
2323
  positions: [MenuPosition.TOOLBAR_START],
2247
2324
  activated$: new Observable((subscriber) => {
2248
2325
  const disposable = commandService.onCommandExecuted((c) => {
2249
- var _a23;
2326
+ var _a22;
2250
2327
  const id = c.id;
2251
2328
  if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2252
2329
  const paragraph = getParagraphStyleAtCursor(accessor);
2253
2330
  if (paragraph == null)
2254
2331
  return;
2255
- const alignType = (_a23 = paragraph.paragraphStyle) == null ? void 0 : _a23.horizontalAlign;
2332
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2256
2333
  subscriber.next(alignType === HorizontalAlign.CENTER);
2257
2334
  }
2258
2335
  });
2259
2336
  return subscriber.next(!1), disposable.dispose;
2260
2337
  }),
2338
+ disabled$: disableMenuWhenNoDocRange(accessor),
2261
2339
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2262
2340
  };
2263
2341
  }
@@ -2273,18 +2351,19 @@ function AlignRightMenuItemFactory(accessor) {
2273
2351
  positions: [MenuPosition.TOOLBAR_START],
2274
2352
  activated$: new Observable((subscriber) => {
2275
2353
  const disposable = commandService.onCommandExecuted((c) => {
2276
- var _a23;
2354
+ var _a22;
2277
2355
  const id = c.id;
2278
2356
  if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2279
2357
  const paragraph = getParagraphStyleAtCursor(accessor);
2280
2358
  if (paragraph == null)
2281
2359
  return;
2282
- const alignType = (_a23 = paragraph.paragraphStyle) == null ? void 0 : _a23.horizontalAlign;
2360
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2283
2361
  subscriber.next(alignType === HorizontalAlign.RIGHT);
2284
2362
  }
2285
2363
  });
2286
2364
  return subscriber.next(!1), disposable.dispose;
2287
2365
  }),
2366
+ disabled$: disableMenuWhenNoDocRange(accessor),
2288
2367
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2289
2368
  };
2290
2369
  }
@@ -2300,18 +2379,19 @@ function AlignJustifyMenuItemFactory(accessor) {
2300
2379
  positions: [MenuPosition.TOOLBAR_START],
2301
2380
  activated$: new Observable((subscriber) => {
2302
2381
  const disposable = commandService.onCommandExecuted((c) => {
2303
- var _a23;
2382
+ var _a22;
2304
2383
  const id = c.id;
2305
2384
  if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2306
2385
  const paragraph = getParagraphStyleAtCursor(accessor);
2307
2386
  if (paragraph == null)
2308
2387
  return;
2309
- const alignType = (_a23 = paragraph.paragraphStyle) == null ? void 0 : _a23.horizontalAlign;
2388
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2310
2389
  subscriber.next(alignType === HorizontalAlign.JUSTIFIED);
2311
2390
  }
2312
2391
  });
2313
2392
  return subscriber.next(!1), disposable.dispose;
2314
2393
  }),
2394
+ disabled$: disableMenuWhenNoDocRange(accessor),
2315
2395
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2316
2396
  };
2317
2397
  }
@@ -2324,14 +2404,14 @@ const listValueFactory$ = /* @__PURE__ */ __name((accessor) => new Observable((s
2324
2404
  return;
2325
2405
  const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
2326
2406
  docDataModel != null && (textSubscription = textSelectionManagerService.textSelection$.subscribe(() => {
2327
- var _a23, _b;
2407
+ var _a22, _b;
2328
2408
  const range = textSelectionManagerService.getActiveTextRangeWithStyle();
2329
2409
  if (range) {
2330
- const doc = docDataModel.getSelfOrHeaderFooterModel(range == null ? void 0 : range.segmentId), paragraphs = getParagraphsInRange(range, (_b = (_a23 = doc.getBody()) == null ? void 0 : _a23.paragraphs) != null ? _b : []);
2410
+ const doc = docDataModel.getSelfOrHeaderFooterModel(range == null ? void 0 : range.segmentId), paragraphs = getParagraphsInRange(range, (_b = (_a22 = doc.getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : []);
2331
2411
  let listType;
2332
2412
  if (paragraphs.every((p2) => {
2333
- var _a24;
2334
- return listType || (listType = (_a24 = p2.bullet) == null ? void 0 : _a24.listType), p2.bullet && p2.bullet.listType === listType;
2413
+ var _a23;
2414
+ return listType || (listType = (_a23 = p2.bullet) == null ? void 0 : _a23.listType), p2.bullet && p2.bullet.listType === listType;
2335
2415
  })) {
2336
2416
  subscriber.next(listType);
2337
2417
  return;
@@ -2362,6 +2442,7 @@ function OrderListMenuItemFactory(accessor) {
2362
2442
  tooltip: "toolbar.order",
2363
2443
  positions: [MenuPosition.TOOLBAR_START],
2364
2444
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2445
+ disabled$: disableMenuWhenNoDocRange(accessor),
2365
2446
  activated$: listValueFactory$(accessor).pipe(map((v) => v && v.indexOf("ORDER_LIST") === 0))
2366
2447
  };
2367
2448
  }
@@ -2383,6 +2464,7 @@ function BulletListMenuItemFactory(accessor) {
2383
2464
  icon: "UnorderSingle",
2384
2465
  tooltip: "toolbar.unorder",
2385
2466
  positions: [MenuPosition.TOOLBAR_START],
2467
+ disabled$: disableMenuWhenNoDocRange(accessor),
2386
2468
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2387
2469
  activated$: listValueFactory$(accessor).pipe(map((v) => v && v.indexOf("BULLET_LIST") === 0))
2388
2470
  };
@@ -2396,6 +2478,7 @@ function CheckListMenuItemFactory(accessor) {
2396
2478
  icon: "TodoList",
2397
2479
  tooltip: "toolbar.checklist",
2398
2480
  positions: [MenuPosition.TOOLBAR_START],
2481
+ disabled$: disableMenuWhenNoDocRange(accessor),
2399
2482
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2400
2483
  activated$: listValueFactory$(accessor).pipe(map((v) => v && v.indexOf("CHECK_LIST") === 0))
2401
2484
  };
@@ -2437,25 +2520,22 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
2437
2520
  });
2438
2521
  return subscriber.next(defaultColor), disposable.dispose;
2439
2522
  }),
2523
+ disabled$: disableMenuWhenNoDocRange(accessor),
2440
2524
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2441
2525
  };
2442
2526
  }
2443
2527
  __name(BackgroundColorSelectorMenuItemFactory, "BackgroundColorSelectorMenuItemFactory");
2444
2528
  function getFontStyleAtCursor(accessor) {
2445
- var _a23;
2529
+ var _a22;
2446
2530
  const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveTextRangeWithStyle();
2447
2531
  if (docDataModel == null || activeTextRange == null)
2448
2532
  return;
2449
- const { startOffset, segmentId } = activeTextRange, textRuns = (_a23 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a23.textRuns;
2533
+ const { startOffset, segmentId } = activeTextRange, textRuns = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.textRuns;
2450
2534
  if (textRuns == null)
2451
2535
  return;
2452
2536
  let textRun;
2453
- for (let i = 0; i < textRuns.length; i++) {
2454
- const curTextRun = textRuns[i], nextTextRun = textRuns[i + 1];
2455
- if (nextTextRun && nextTextRun.st === nextTextRun.ed && startOffset === nextTextRun.st) {
2456
- textRun = nextTextRun;
2457
- break;
2458
- }
2537
+ for (let i = textRuns.length - 1; i >= 0; i--) {
2538
+ const curTextRun = textRuns[i];
2459
2539
  if (curTextRun.st <= startOffset && startOffset <= curTextRun.ed) {
2460
2540
  textRun = curTextRun;
2461
2541
  break;
@@ -2465,11 +2545,11 @@ function getFontStyleAtCursor(accessor) {
2465
2545
  }
2466
2546
  __name(getFontStyleAtCursor, "getFontStyleAtCursor");
2467
2547
  function getParagraphStyleAtCursor(accessor) {
2468
- var _a23;
2548
+ var _a22;
2469
2549
  const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveTextRangeWithStyle();
2470
2550
  if (docDataModel == null || activeTextRange == null)
2471
2551
  return;
2472
- const { startOffset, segmentId } = activeTextRange, paragraphs = (_a23 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a23.paragraphs;
2552
+ const { startOffset, segmentId } = activeTextRange, paragraphs = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs;
2473
2553
  if (paragraphs == null)
2474
2554
  return;
2475
2555
  let prevIndex = -1;
@@ -2486,6 +2566,10 @@ function whenDocOrEditor(contextService) {
2486
2566
  return contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED);
2487
2567
  }
2488
2568
  __name(whenDocOrEditor, "whenDocOrEditor");
2569
+ function whenFocusEditor(contextService) {
2570
+ return contextService.getContextValue(EDITOR_ACTIVATED);
2571
+ }
2572
+ __name(whenFocusEditor, "whenFocusEditor");
2489
2573
  const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
2490
2574
  id: CopyCommand.id,
2491
2575
  name: "doc.command.copy",
@@ -2517,11 +2601,11 @@ const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
2517
2601
  id: "doc-paragraph-setting.command",
2518
2602
  type: CommandType.COMMAND,
2519
2603
  handler: /* @__PURE__ */ __name(async (accessor, config) => {
2520
- var _a23, _b, _c;
2604
+ var _a22, _b, _c;
2521
2605
  const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = textSelectionManagerService.getDocRanges();
2522
2606
  if (!docDataModel || docRanges.length === 0 || !config)
2523
2607
  return !1;
2524
- const segmentId = docRanges[0].segmentId, unitId = docDataModel.getUnitId(), allParagraphs = (_b = (_a23 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a23.paragraphs) != null ? _b : [], paragraphs = (_c = getParagraphsInRanges(docRanges, allParagraphs)) != null ? _c : [], serializedSelections = docRanges.map(serializeDocRange), doMutation = {
2608
+ const segmentId = docRanges[0].segmentId, unitId = docDataModel.getUnitId(), allParagraphs = (_b = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : [], paragraphs = (_c = getParagraphsInRanges(docRanges, allParagraphs)) != null ? _c : [], serializedSelections = docRanges.map(serializeDocRange), doMutation = {
2525
2609
  id: RichTextEditingMutation.id,
2526
2610
  params: {
2527
2611
  unitId,
@@ -2563,80 +2647,80 @@ const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
2563
2647
  return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2564
2648
  }, "handler")
2565
2649
  }, useCurrentParagraph = /* @__PURE__ */ __name(() => {
2566
- var _a23, _b, _c;
2650
+ var _a22, _b, _c;
2567
2651
  const textSelectionManagerService = useDependency(TextSelectionManagerService), docDataModel = useDependency(IUniverInstanceService).getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = useMemo(() => textSelectionManagerService.getDocRanges(), []);
2568
2652
  if (!docDataModel || docRanges.length === 0)
2569
2653
  return [];
2570
- const segmentId = docRanges[0].segmentId, paragraphs = (_b = (_a23 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a23.paragraphs) != null ? _b : [];
2654
+ const segmentId = docRanges[0].segmentId, paragraphs = (_b = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : [];
2571
2655
  return (_c = getParagraphsInRanges(docRanges, paragraphs)) != null ? _c : [];
2572
2656
  }, "useCurrentParagraph"), useFirstParagraphHorizontalAlign = /* @__PURE__ */ __name((paragraph, defaultValue) => {
2573
2657
  const commandService = useDependency(ICommandService), [horizontalAlign, _horizontalAlignSet] = useState(() => {
2574
- var _a23, _b;
2658
+ var _a22, _b;
2575
2659
  const firstParagraph = paragraph[0];
2576
- return firstParagraph ? String((_b = (_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.horizontalAlign) != null ? _b : defaultValue) : defaultValue;
2660
+ return firstParagraph ? String((_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign) != null ? _b : defaultValue) : defaultValue;
2577
2661
  });
2578
2662
  return [horizontalAlign, /* @__PURE__ */ __name((v) => (_horizontalAlignSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2579
2663
  horizontalAlign: Number(v)
2580
2664
  })), "horizontalAlignSet")];
2581
2665
  }, "useFirstParagraphHorizontalAlign"), useFirstParagraphIndentStart = /* @__PURE__ */ __name((paragraph) => {
2582
2666
  const commandService = useDependency(ICommandService), [indentStart, _indentStartSet] = useState(() => {
2583
- var _a23;
2667
+ var _a22;
2584
2668
  const firstParagraph = paragraph[0];
2585
- return firstParagraph ? getNumberUnitValue((_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.indentStart, 0) : 0;
2669
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentStart, 0) : 0;
2586
2670
  });
2587
2671
  return [indentStart, /* @__PURE__ */ __name((v) => (_indentStartSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2588
2672
  indentStart: { v }
2589
2673
  })), "indentStartSet")];
2590
2674
  }, "useFirstParagraphIndentStart"), useFirstParagraphIndentEnd = /* @__PURE__ */ __name((paragraph) => {
2591
2675
  const commandService = useDependency(ICommandService), [indentEnd, _indentEndSet] = useState(() => {
2592
- var _a23;
2676
+ var _a22;
2593
2677
  const firstParagraph = paragraph[0];
2594
- return firstParagraph ? getNumberUnitValue((_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.indentEnd, 0) : 0;
2678
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentEnd, 0) : 0;
2595
2679
  });
2596
2680
  return [indentEnd, /* @__PURE__ */ __name((v) => (_indentEndSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2597
2681
  indentEnd: { v }
2598
2682
  })), "indentEndSet")];
2599
2683
  }, "useFirstParagraphIndentEnd"), useFirstParagraphIndentFirstLine = /* @__PURE__ */ __name((paragraph) => {
2600
2684
  const commandService = useDependency(ICommandService), [indentFirstLine, _indentFirstLineSet] = useState(() => {
2601
- var _a23;
2685
+ var _a22;
2602
2686
  const firstParagraph = paragraph[0];
2603
- return firstParagraph ? getNumberUnitValue((_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.indentFirstLine, 0) : 0;
2687
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentFirstLine, 0) : 0;
2604
2688
  });
2605
2689
  return [indentFirstLine, /* @__PURE__ */ __name((v) => (_indentFirstLineSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2606
2690
  indentFirstLine: { v }
2607
2691
  })), "indentFirstLineSet")];
2608
2692
  }, "useFirstParagraphIndentFirstLine"), useFirstParagraphIndentHanging = /* @__PURE__ */ __name((paragraph) => {
2609
2693
  const commandService = useDependency(ICommandService), [hanging, _hangingSet] = useState(() => {
2610
- var _a23;
2694
+ var _a22;
2611
2695
  const firstParagraph = paragraph[0];
2612
- return firstParagraph ? getNumberUnitValue((_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.hanging, 0) : 0;
2696
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.hanging, 0) : 0;
2613
2697
  });
2614
2698
  return [hanging, /* @__PURE__ */ __name((v) => (_hangingSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2615
2699
  hanging: { v }
2616
2700
  })), "hangingSet")];
2617
2701
  }, "useFirstParagraphIndentHanging"), useFirstParagraphIndentSpaceAbove = /* @__PURE__ */ __name((paragraph) => {
2618
2702
  const commandService = useDependency(ICommandService), [spaceAbove, _spaceAboveSet] = useState(() => {
2619
- var _a23;
2703
+ var _a22;
2620
2704
  const firstParagraph = paragraph[0];
2621
- return firstParagraph ? getNumberUnitValue((_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.spaceAbove, 0) : 0;
2705
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spaceAbove, 0) : 0;
2622
2706
  });
2623
2707
  return [spaceAbove, /* @__PURE__ */ __name((v) => (_spaceAboveSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2624
2708
  spaceAbove: { v }
2625
2709
  })), "spaceAboveSet")];
2626
2710
  }, "useFirstParagraphIndentSpaceAbove"), useFirstParagraphSpaceBelow = /* @__PURE__ */ __name((paragraph) => {
2627
2711
  const commandService = useDependency(ICommandService), [spaceBelow, _spaceBelowSet] = useState(() => {
2628
- var _a23;
2712
+ var _a22;
2629
2713
  const firstParagraph = paragraph[0];
2630
- return firstParagraph ? getNumberUnitValue((_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.spaceBelow, 0) : 0;
2714
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spaceBelow, 0) : 0;
2631
2715
  });
2632
2716
  return [spaceBelow, /* @__PURE__ */ __name((v) => (_spaceBelowSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2633
2717
  spaceBelow: { v }
2634
2718
  })), "spaceBelowSet")];
2635
2719
  }, "useFirstParagraphSpaceBelow"), useFirstParagraphLineSpacing = /* @__PURE__ */ __name((paragraph) => {
2636
2720
  const commandService = useDependency(ICommandService), [lineSpacing, _lineSpacingSet] = useState(() => {
2637
- var _a23, _b;
2721
+ var _a22, _b;
2638
2722
  const firstParagraph = paragraph[0];
2639
- return firstParagraph && (_b = (_a23 = firstParagraph.paragraphStyle) == null ? void 0 : _a23.lineSpacing) != null ? _b : 1;
2723
+ return firstParagraph && (_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.lineSpacing) != null ? _b : 1;
2640
2724
  });
2641
2725
  return [lineSpacing, /* @__PURE__ */ __name((v) => (_lineSpacingSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2642
2726
  lineSpacing: v
@@ -2661,8 +2745,8 @@ const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
2661
2745
  onChange: /* @__PURE__ */ __name((v) => {
2662
2746
  onChange(v != null ? v : 0).finally(() => {
2663
2747
  setTimeout(() => {
2664
- var _a23;
2665
- (_a23 = ref.current) == null || _a23.focus();
2748
+ var _a22;
2749
+ (_a22 = ref.current) == null || _a22.focus();
2666
2750
  }, 2);
2667
2751
  });
2668
2752
  }, "onChange"),
@@ -2756,13 +2840,13 @@ function ParagraphSettingIndex() {
2756
2840
  const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), currentLocale = useObservable(localeService.currentLocale$), [key, keySet] = useState(""), rangeRef = useRef([]);
2757
2841
  return useEffect(() => {
2758
2842
  const dispose = commandService.onCommandExecuted((info) => {
2759
- var _a23;
2843
+ var _a22;
2760
2844
  if (SetTextSelectionsOperation.id === info.id) {
2761
2845
  const ranges = info.params.ranges;
2762
2846
  isRangesEqual(ranges, rangeRef.current) || keySet(generateRandomId(4)), rangeRef.current = ranges;
2763
2847
  }
2764
2848
  if (RichTextEditingMutation.id === info.id) {
2765
- const params = info.params, ranges = (_a23 = params.textRanges) != null ? _a23 : [];
2849
+ const params = info.params, ranges = (_a22 = params.textRanges) != null ? _a22 : [];
2766
2850
  params.trigger !== DocParagraphSettingCommand.id && isRangesIntersection(ranges, rangeRef.current) && keySet(generateRandomId(4));
2767
2851
  }
2768
2852
  });
@@ -2772,11 +2856,11 @@ function ParagraphSettingIndex() {
2772
2856
  }, [currentLocale]), /* @__PURE__ */ jsxRuntimeExports.jsx(ParagraphSetting, {}, key);
2773
2857
  }
2774
2858
  __name(ParagraphSettingIndex, "ParagraphSettingIndex");
2775
- var __defProp$g = Object.defineProperty, __getOwnPropDesc$g = Object.getOwnPropertyDescriptor, __decorateClass$g = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2776
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2859
+ var __defProp$f = Object.defineProperty, __getOwnPropDesc$f = Object.getOwnPropertyDescriptor, __decorateClass$f = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2860
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$f(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2777
2861
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2778
- return kind && result && __defProp$g(target, key, result), result;
2779
- }, "__decorateClass$g"), __decorateParam$g = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$g");
2862
+ return kind && result && __defProp$f(target, key, result), result;
2863
+ }, "__decorateClass$f"), __decorateParam$f = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$f");
2780
2864
  const paragraphSettingIndexKey = "doc_ui_paragraph-setting-panel";
2781
2865
  var _a6;
2782
2866
  let DocParagraphSettingController = (_a6 = class extends Disposable {
@@ -2797,11 +2881,11 @@ let DocParagraphSettingController = (_a6 = class extends Disposable {
2797
2881
  this._sidebarService.open(props);
2798
2882
  }
2799
2883
  }, __name(_a6, "DocParagraphSettingController"), _a6);
2800
- DocParagraphSettingController = __decorateClass$g([
2884
+ DocParagraphSettingController = __decorateClass$f([
2801
2885
  OnLifecycle(LifecycleStages.Rendered, DocParagraphSettingController),
2802
- __decorateParam$g(0, ICommandService),
2803
- __decorateParam$g(1, Inject(ComponentManager)),
2804
- __decorateParam$g(2, Inject(ISidebarService))
2886
+ __decorateParam$f(0, ICommandService),
2887
+ __decorateParam$f(1, Inject(ComponentManager)),
2888
+ __decorateParam$f(2, Inject(ISidebarService))
2805
2889
  ], DocParagraphSettingController);
2806
2890
  const DocParagraphSettingPanelOperation = {
2807
2891
  id: "sidebar.operation.doc-paragraph-setting-panel",
@@ -2828,14 +2912,14 @@ const getDisableWhenSelectionNotInTableObservable = /* @__PURE__ */ __name((acce
2828
2912
  const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
2829
2913
  return new Observable((subscriber) => {
2830
2914
  const observable = textSelectionManagerService.textSelection$.subscribe(() => {
2831
- var _a23;
2915
+ var _a22;
2832
2916
  const rectRanges = textSelectionManagerService.getCurrentRectRanges(), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
2833
2917
  if (rectRanges && rectRanges.length && inSameTable(rectRanges)) {
2834
2918
  subscriber.next(!1);
2835
2919
  return;
2836
2920
  }
2837
2921
  if (activeRange && (rectRanges == null || rectRanges.length === 0)) {
2838
- const { segmentId, startOffset, endOffset } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), tables = (_a23 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a23.tables;
2922
+ const { segmentId, startOffset, endOffset } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), tables = (_a22 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.tables;
2839
2923
  if (tables && tables.length && tables.some((table) => {
2840
2924
  const { startIndex, endIndex } = table;
2841
2925
  return startOffset > startIndex && startOffset < endIndex || endOffset > startIndex && endOffset < endIndex;
@@ -3001,11 +3085,11 @@ function DeleteTableMenuItemFactory(accessor) {
3001
3085
  };
3002
3086
  }
3003
3087
  __name(DeleteTableMenuItemFactory, "DeleteTableMenuItemFactory");
3004
- var __defProp$f = Object.defineProperty, __getOwnPropDesc$f = Object.getOwnPropertyDescriptor, __decorateClass$f = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3005
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$f(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3088
+ var __defProp$e = Object.defineProperty, __getOwnPropDesc$e = Object.getOwnPropertyDescriptor, __decorateClass$e = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3089
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$e(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3006
3090
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3007
- return kind && result && __defProp$f(target, key, result), result;
3008
- }, "__decorateClass$f"), __decorateParam$f = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$f"), _a7;
3091
+ return kind && result && __defProp$e(target, key, result), result;
3092
+ }, "__decorateClass$e"), __decorateParam$e = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$e"), _a7;
3009
3093
  let DocUIController = (_a7 = class extends Disposable {
3010
3094
  constructor(_config, _injector, _componentManager, _commandService, _layoutService, _menuService, _uiPartsService, _univerInstanceService, _shortcutService) {
3011
3095
  super(), this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._commandService = _commandService, this._layoutService = _layoutService, this._menuService = _menuService, this._uiPartsService = _uiPartsService, this._univerInstanceService = _univerInstanceService, this._shortcutService = _shortcutService, this._init();
@@ -3015,9 +3099,9 @@ let DocUIController = (_a7 = class extends Disposable {
3015
3099
  this.disposeWithMe(componentManager.register(COLOR_PICKER_COMPONENT, ColorPicker)), this.disposeWithMe(componentManager.register(FONT_FAMILY_COMPONENT, FontFamily)), this.disposeWithMe(componentManager.register(FONT_FAMILY_ITEM_COMPONENT, FontFamilyItem)), this.disposeWithMe(componentManager.register(FONT_SIZE_COMPONENT, FontSize)), this.disposeWithMe(componentManager.register(BULLET_LIST_TYPE_COMPONENT, BulletListTypePicker)), this.disposeWithMe(componentManager.register(ORDER_LIST_TYPE_COMPONENT, OrderListTypePicker)), this.disposeWithMe(componentManager.register("TodoList", TodoList));
3016
3100
  }
3017
3101
  _initUiParts() {
3018
- var _a23, _b;
3102
+ var _a22, _b;
3019
3103
  const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
3020
- (_b = (_a23 = this._config.layout) == null ? void 0 : _a23.docContainerConfig) != null && _b.footer && !workbook && this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));
3104
+ (_b = (_a22 = this._config.layout) == null ? void 0 : _a22.docContainerConfig) != null && _b.footer && !workbook && this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));
3021
3105
  }
3022
3106
  _initMenus() {
3023
3107
  const { menu = {} } = this._config;
@@ -3104,16 +3188,16 @@ let DocUIController = (_a7 = class extends Disposable {
3104
3188
  );
3105
3189
  }
3106
3190
  }, __name(_a7, "DocUIController"), _a7);
3107
- DocUIController = __decorateClass$f([
3191
+ DocUIController = __decorateClass$e([
3108
3192
  OnLifecycle(LifecycleStages.Rendered, DocUIController),
3109
- __decorateParam$f(1, Inject(Injector)),
3110
- __decorateParam$f(2, Inject(ComponentManager)),
3111
- __decorateParam$f(3, ICommandService),
3112
- __decorateParam$f(4, ILayoutService),
3113
- __decorateParam$f(5, IMenuService),
3114
- __decorateParam$f(6, IUIPartsService),
3115
- __decorateParam$f(7, IUniverInstanceService),
3116
- __decorateParam$f(8, IShortcutService)
3193
+ __decorateParam$e(1, Inject(Injector)),
3194
+ __decorateParam$e(2, Inject(ComponentManager)),
3195
+ __decorateParam$e(3, ICommandService),
3196
+ __decorateParam$e(4, ILayoutService),
3197
+ __decorateParam$e(5, IMenuService),
3198
+ __decorateParam$e(6, IUIPartsService),
3199
+ __decorateParam$e(7, IUniverInstanceService),
3200
+ __decorateParam$e(8, IShortcutService)
3117
3201
  ], DocUIController);
3118
3202
  const BreakLineShortcut = {
3119
3203
  id: EnterCommand.id,
@@ -3128,11 +3212,11 @@ const BreakLineShortcut = {
3128
3212
  preconditions: whenDocAndEditorFocused,
3129
3213
  binding: KeyCode.DELETE
3130
3214
  };
3131
- var __defProp$e = Object.defineProperty, __getOwnPropDesc$e = Object.getOwnPropertyDescriptor, __decorateClass$e = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3132
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$e(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3215
+ var __defProp$d = Object.defineProperty, __getOwnPropDesc$d = Object.getOwnPropertyDescriptor, __decorateClass$d = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3216
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$d(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3133
3217
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3134
- return kind && result && __defProp$e(target, key, result), result;
3135
- }, "__decorateClass$e"), __decorateParam$e = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$e"), _a8;
3218
+ return kind && result && __defProp$d(target, key, result), result;
3219
+ }, "__decorateClass$d"), __decorateParam$d = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$d"), _a8;
3136
3220
  let DocClipboardController = (_a8 = class extends RxDisposable {
3137
3221
  constructor(_commandService, _clipboardInterfaceService, _docClipboardService, _textSelectionRenderManager, _contextService) {
3138
3222
  super(), this._commandService = _commandService, this._clipboardInterfaceService = _clipboardInterfaceService, this._docClipboardService = _docClipboardService, this._textSelectionRenderManager = _textSelectionRenderManager, this._contextService = _contextService, this._init();
@@ -3141,30 +3225,32 @@ let DocClipboardController = (_a8 = class extends RxDisposable {
3141
3225
  [DocCopyCommand, DocCutCommand, DocPasteCommand].forEach((command) => this.disposeWithMe(this._commandService.registerMultipleCommand(command))), [InnerPasteCommand, CutContentCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command))), this._initLegacyPasteCommand();
3142
3226
  }
3143
3227
  _initLegacyPasteCommand() {
3144
- var _a23;
3145
- (_a23 = this._textSelectionRenderManager) == null || _a23.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
3146
- var _a24, _b;
3228
+ var _a22;
3229
+ (_a22 = this._textSelectionRenderManager) == null || _a22.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
3230
+ var _a23, _b;
3147
3231
  if (!whenDocOrEditor(this._contextService))
3148
3232
  return;
3149
3233
  config.event.preventDefault();
3150
- const clipboardEvent = config.event, htmlContent = (_a24 = clipboardEvent.clipboardData) == null ? void 0 : _a24.getData("text/html"), textContent = (_b = clipboardEvent.clipboardData) == null ? void 0 : _b.getData("text/plain");
3151
- this._docClipboardService.legacyPaste(htmlContent, textContent);
3234
+ const clipboardEvent = config.event;
3235
+ let htmlContent = (_a23 = clipboardEvent.clipboardData) == null ? void 0 : _a23.getData("text/html");
3236
+ const textContent = (_b = clipboardEvent.clipboardData) == null ? void 0 : _b.getData("text/plain");
3237
+ whenFocusEditor(this._contextService) && (htmlContent != null ? htmlContent : "").indexOf("</table>") > -1 && (htmlContent = ""), this._docClipboardService.legacyPaste(htmlContent, textContent);
3152
3238
  });
3153
3239
  }
3154
3240
  }, __name(_a8, "DocClipboardController"), _a8);
3155
- DocClipboardController = __decorateClass$e([
3241
+ DocClipboardController = __decorateClass$d([
3156
3242
  OnLifecycle(LifecycleStages.Rendered, DocClipboardController),
3157
- __decorateParam$e(0, ICommandService),
3158
- __decorateParam$e(1, IClipboardInterfaceService),
3159
- __decorateParam$e(2, IDocClipboardService),
3160
- __decorateParam$e(3, ITextSelectionRenderManager),
3161
- __decorateParam$e(4, IContextService)
3243
+ __decorateParam$d(0, ICommandService),
3244
+ __decorateParam$d(1, IClipboardInterfaceService),
3245
+ __decorateParam$d(2, IDocClipboardService),
3246
+ __decorateParam$d(3, ITextSelectionRenderManager),
3247
+ __decorateParam$d(4, IContextService)
3162
3248
  ], DocClipboardController);
3163
- var __defProp$d = Object.defineProperty, __getOwnPropDesc$d = Object.getOwnPropertyDescriptor, __decorateClass$d = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3164
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$d(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3249
+ var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPropertyDescriptor, __decorateClass$c = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3250
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3165
3251
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3166
- return kind && result && __defProp$d(target, key, result), result;
3167
- }, "__decorateClass$d"), __decorateParam$d = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$d"), _a9;
3252
+ return kind && result && __defProp$c(target, key, result), result;
3253
+ }, "__decorateClass$c"), __decorateParam$c = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$c"), _a9;
3168
3254
  let DocEditorBridgeController = (_a9 = class extends Disposable {
3169
3255
  constructor(_univerInstanceService, _editorService, _commandService, _textSelectionRenderManager, _renderManagerService) {
3170
3256
  super();
@@ -3182,7 +3268,7 @@ let DocEditorBridgeController = (_a9 = class extends Disposable {
3182
3268
  }), this._commandExecutedListener(), this._initialSetValue(), this._initialBlur(), this._initialFocus(), this._initialValueChange();
3183
3269
  }
3184
3270
  _resize(unitId) {
3185
- var _a23, _b, _c;
3271
+ var _a22, _b, _c;
3186
3272
  if (unitId == null)
3187
3273
  return;
3188
3274
  const editor = this._editorService.getEditor(unitId);
@@ -3191,7 +3277,7 @@ let DocEditorBridgeController = (_a9 = class extends Disposable {
3191
3277
  const editorDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
3192
3278
  if (!editorDataModel)
3193
3279
  return;
3194
- const skeleton = (_a23 = this._renderManagerService.getRenderById(editorDataModel.getUnitId())) == null ? void 0 : _a23.with(DocSkeletonManagerService).getSkeleton();
3280
+ const skeleton = (_a22 = this._renderManagerService.getRenderById(editorDataModel.getUnitId())) == null ? void 0 : _a22.with(DocSkeletonManagerService).getSkeleton();
3195
3281
  if (editor == null || editor.render == null || skeleton == null || editorDataModel == null)
3196
3282
  return;
3197
3283
  skeleton.calculate();
@@ -3224,8 +3310,8 @@ let DocEditorBridgeController = (_a9 = class extends Disposable {
3224
3310
  })
3225
3311
  ), this.disposeWithMe(
3226
3312
  this._textSelectionRenderManager.onBlur$.subscribe(() => {
3227
- var _a23;
3228
- const unitId = (_a23 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a23.getUnitId();
3313
+ var _a22;
3314
+ const unitId = (_a22 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a22.getUnitId();
3229
3315
  if (unitId == null)
3230
3316
  return;
3231
3317
  const editor = this._editorService.getEditor(unitId), focusEditor = this._editorService.getFocusEditor();
@@ -3273,8 +3359,8 @@ let DocEditorBridgeController = (_a9 = class extends Disposable {
3273
3359
  );
3274
3360
  }
3275
3361
  _valueChange() {
3276
- var _a23;
3277
- const unitId = (_a23 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a23.getUnitId();
3362
+ var _a22;
3363
+ const unitId = (_a22 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a22.getUnitId();
3278
3364
  if (unitId == null)
3279
3365
  return;
3280
3366
  const editor = this._editorService.getEditor(unitId);
@@ -3297,26 +3383,26 @@ let DocEditorBridgeController = (_a9 = class extends Disposable {
3297
3383
  );
3298
3384
  }
3299
3385
  }, __name(_a9, "DocEditorBridgeController"), _a9);
3300
- DocEditorBridgeController = __decorateClass$d([
3386
+ DocEditorBridgeController = __decorateClass$c([
3301
3387
  OnLifecycle(LifecycleStages.Rendered, DocEditorBridgeController),
3302
- __decorateParam$d(0, IUniverInstanceService),
3303
- __decorateParam$d(1, IEditorService),
3304
- __decorateParam$d(2, ICommandService),
3305
- __decorateParam$d(3, ITextSelectionRenderManager),
3306
- __decorateParam$d(4, IRenderManagerService)
3388
+ __decorateParam$c(0, IUniverInstanceService),
3389
+ __decorateParam$c(1, IEditorService),
3390
+ __decorateParam$c(2, ICommandService),
3391
+ __decorateParam$c(3, ITextSelectionRenderManager),
3392
+ __decorateParam$c(4, IRenderManagerService)
3307
3393
  ], DocEditorBridgeController);
3308
- var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPropertyDescriptor, __decorateClass$c = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3309
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3394
+ var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3395
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3310
3396
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3311
- return kind && result && __defProp$c(target, key, result), result;
3312
- }, "__decorateClass$c"), __decorateParam$c = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$c"), _a10;
3397
+ return kind && result && __defProp$b(target, key, result), result;
3398
+ }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b"), _a10;
3313
3399
  let DocRenderController = (_a10 = class extends RxDisposable {
3314
3400
  constructor(_context, _contextService, _commandService, _docSkeletonManagerService, _configService, _editorService, _renderManagerService) {
3315
3401
  super(), this._context = _context, this._contextService = _contextService, this._commandService = _commandService, this._docSkeletonManagerService = _docSkeletonManagerService, this._configService = _configService, this._editorService = _editorService, this._renderManagerService = _renderManagerService, this._addNewRender(), this._initRenderRefresh(), this._initCommandListener();
3316
3402
  }
3317
3403
  reRender(unitId) {
3318
- var _a23, _b;
3319
- const docSkeletonManagerService = (_a23 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a23.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
3404
+ var _a22, _b;
3405
+ const docSkeletonManagerService = (_a22 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a22.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
3320
3406
  if (!(!skeleton || skeleton.getViewModel().getDataModel().getSnapshot().disabled)) {
3321
3407
  if (skeleton.calculate(), this._editorService.isEditor(unitId)) {
3322
3408
  (_b = this._context.mainComponent) == null || _b.makeDirty();
@@ -3348,7 +3434,7 @@ let DocRenderController = (_a10 = class extends RxDisposable {
3348
3434
  }), this._configService.getConfig("hasScroll") !== !1 && new ScrollBar(viewMain), scene.addLayer(
3349
3435
  new Layer(scene, [], DOCS_COMPONENT_MAIN_LAYER_INDEX),
3350
3436
  new Layer(scene, [], DOCS_COMPONENT_HEADER_LAYER_INDEX)
3351
- ), this._addComponent(), unit.getShouldRenderLoopImmediately() && engine.runRenderLoop(() => {
3437
+ ), this._addComponent(), engine.runRenderLoop(() => {
3352
3438
  scene.render();
3353
3439
  });
3354
3440
  }
@@ -3382,8 +3468,8 @@ let DocRenderController = (_a10 = class extends RxDisposable {
3382
3468
  }));
3383
3469
  }
3384
3470
  _recalculateSizeBySkeleton(skeleton) {
3385
- var _a23;
3386
- const { mainComponent, scene, unitId, components } = this._context, docsComponent = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND), pages = (_a23 = skeleton.getSkeletonData()) == null ? void 0 : _a23.pages;
3471
+ var _a22;
3472
+ const { mainComponent, scene, unitId, components } = this._context, docsComponent = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND), pages = (_a22 = skeleton.getSkeletonData()) == null ? void 0 : _a22.pages;
3387
3473
  if (pages == null)
3388
3474
  return;
3389
3475
  let width = 0, height = 0;
@@ -3394,21 +3480,21 @@ let DocRenderController = (_a10 = class extends RxDisposable {
3394
3480
  docsComponent.resize(width, height), docBackground.resize(width, height), this._editorService.isEditor(unitId) || scene.resize(width, height);
3395
3481
  }
3396
3482
  }, __name(_a10, "DocRenderController"), _a10);
3397
- DocRenderController = __decorateClass$c([
3398
- __decorateParam$c(1, IContextService),
3399
- __decorateParam$c(2, ICommandService),
3400
- __decorateParam$c(3, Inject(DocSkeletonManagerService)),
3401
- __decorateParam$c(4, IConfigService),
3402
- __decorateParam$c(5, IEditorService),
3403
- __decorateParam$c(6, IRenderManagerService)
3483
+ DocRenderController = __decorateClass$b([
3484
+ __decorateParam$b(1, IContextService),
3485
+ __decorateParam$b(2, ICommandService),
3486
+ __decorateParam$b(3, Inject(DocSkeletonManagerService)),
3487
+ __decorateParam$b(4, IConfigService),
3488
+ __decorateParam$b(5, IEditorService),
3489
+ __decorateParam$b(6, IRenderManagerService)
3404
3490
  ], DocRenderController);
3405
3491
  const _DocPageLayoutService = class _DocPageLayoutService extends Disposable {
3406
3492
  constructor(_context) {
3407
3493
  super(), this._context = _context;
3408
3494
  }
3409
3495
  calculatePagePosition() {
3410
- var _a23, _b;
3411
- const docObject = neoGetDocObject(this._context), zoomRatio = (_b = (_a23 = this._context.unit.getSettings()) == null ? void 0 : _a23.zoomRatio) != null ? _b : 1, { document: docsComponent, scene, docBackground } = docObject, parent = scene == null ? void 0 : scene.getParent(), { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = docsComponent;
3496
+ var _a22, _b;
3497
+ const docObject = neoGetDocObject(this._context), zoomRatio = (_b = (_a22 = this._context.unit.getSettings()) == null ? void 0 : _a22.zoomRatio) != null ? _b : 1, { document: docsComponent, scene, docBackground } = docObject, parent = scene == null ? void 0 : scene.getParent(), { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = docsComponent;
3412
3498
  if (parent == null || docsWidth === Number.POSITIVE_INFINITY || docsHeight === Number.POSITIVE_INFINITY)
3413
3499
  return;
3414
3500
  const { width: engineWidth, height: engineHeight } = parent;
@@ -3422,11 +3508,11 @@ const _DocPageLayoutService = class _DocPageLayoutService extends Disposable {
3422
3508
  };
3423
3509
  __name(_DocPageLayoutService, "DocPageLayoutService");
3424
3510
  let DocPageLayoutService = _DocPageLayoutService;
3425
- var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3426
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3511
+ var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3512
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3427
3513
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3428
- return kind && result && __defProp$b(target, key, result), result;
3429
- }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b"), _a11;
3514
+ return kind && result && __defProp$a(target, key, result), result;
3515
+ }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a11;
3430
3516
  let DocZoomRenderController = (_a11 = class extends Disposable {
3431
3517
  constructor(_context, _contextService, _docSkeletonManagerService, _univerInstanceService, _commandService, _textSelectionManagerService, _editorService, _docPageLayoutService) {
3432
3518
  super(), this._context = _context, this._contextService = _contextService, this._docSkeletonManagerService = _docSkeletonManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._editorService = _editorService, this._docPageLayoutService = _docPageLayoutService, this._initSkeletonListener(), this._initCommandExecutedListener(), this._initRenderRefresher(), setTimeout(() => this.updateViewZoom(1, !0), 20);
@@ -3474,25 +3560,25 @@ let DocZoomRenderController = (_a11 = class extends Disposable {
3474
3560
  }));
3475
3561
  }
3476
3562
  updateViewZoom(zoomRatio, needRefreshSelection = !0) {
3477
- var _a23;
3563
+ var _a22;
3478
3564
  const docObject = neoGetDocObject(this._context);
3479
- docObject.scene.scale(zoomRatio, zoomRatio), this._docPageLayoutService.calculatePagePosition(), needRefreshSelection && !this._editorService.isEditor(this._context.unitId) && this._textSelectionManagerService.refreshSelection(), (_a23 = docObject.scene.getTransformer()) == null || _a23.clearSelectedObjects();
3565
+ docObject.scene.scale(zoomRatio, zoomRatio), this._docPageLayoutService.calculatePagePosition(), needRefreshSelection && !this._editorService.isEditor(this._context.unitId) && this._textSelectionManagerService.refreshSelection(), (_a22 = docObject.scene.getTransformer()) == null || _a22.clearSelectedObjects();
3480
3566
  }
3481
3567
  }, __name(_a11, "DocZoomRenderController"), _a11);
3482
- DocZoomRenderController = __decorateClass$b([
3483
- __decorateParam$b(1, IContextService),
3484
- __decorateParam$b(2, Inject(DocSkeletonManagerService)),
3485
- __decorateParam$b(3, IUniverInstanceService),
3486
- __decorateParam$b(4, ICommandService),
3487
- __decorateParam$b(5, Inject(TextSelectionManagerService)),
3488
- __decorateParam$b(6, IEditorService),
3489
- __decorateParam$b(7, Inject(DocPageLayoutService))
3568
+ DocZoomRenderController = __decorateClass$a([
3569
+ __decorateParam$a(1, IContextService),
3570
+ __decorateParam$a(2, Inject(DocSkeletonManagerService)),
3571
+ __decorateParam$a(3, IUniverInstanceService),
3572
+ __decorateParam$a(4, ICommandService),
3573
+ __decorateParam$a(5, Inject(TextSelectionManagerService)),
3574
+ __decorateParam$a(6, IEditorService),
3575
+ __decorateParam$a(7, Inject(DocPageLayoutService))
3490
3576
  ], DocZoomRenderController);
3491
- var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3492
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3577
+ var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3578
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3493
3579
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3494
- return kind && result && __defProp$a(target, key, result), result;
3495
- }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a12;
3580
+ return kind && result && __defProp$9(target, key, result), result;
3581
+ }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a12;
3496
3582
  let DocTextSelectionRenderController = (_a12 = class extends Disposable {
3497
3583
  constructor(_context, _commandService, _editorService, _instanceSrv, _textSelectionRenderManager, _docSkeletonManagerService, _textSelectionManagerService) {
3498
3584
  super();
@@ -3564,9 +3650,9 @@ let DocTextSelectionRenderController = (_a12 = class extends Disposable {
3564
3650
  const updateCommandList = [SetDocZoomRatioOperation.id];
3565
3651
  this.disposeWithMe(
3566
3652
  this._commandService.onCommandExecuted((command) => {
3567
- var _a23;
3653
+ var _a22;
3568
3654
  if (updateCommandList.includes(command.id)) {
3569
- const params = command.params, { unitId: documentId } = params, unitId = (_a23 = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : _a23.unitId;
3655
+ const params = command.params, { unitId: documentId } = params, unitId = (_a22 = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : _a22.unitId;
3570
3656
  if (documentId !== unitId)
3571
3657
  return;
3572
3658
  this._textSelectionManagerService.refreshSelection();
@@ -3591,19 +3677,19 @@ let DocTextSelectionRenderController = (_a12 = class extends Disposable {
3591
3677
  }));
3592
3678
  }
3593
3679
  }, __name(_a12, "DocTextSelectionRenderController"), _a12);
3594
- DocTextSelectionRenderController = __decorateClass$a([
3595
- __decorateParam$a(1, ICommandService),
3596
- __decorateParam$a(2, IEditorService),
3597
- __decorateParam$a(3, IUniverInstanceService),
3598
- __decorateParam$a(4, ITextSelectionRenderManager),
3599
- __decorateParam$a(5, Inject(DocSkeletonManagerService)),
3600
- __decorateParam$a(6, Inject(TextSelectionManagerService))
3680
+ DocTextSelectionRenderController = __decorateClass$9([
3681
+ __decorateParam$9(1, ICommandService),
3682
+ __decorateParam$9(2, IEditorService),
3683
+ __decorateParam$9(3, IUniverInstanceService),
3684
+ __decorateParam$9(4, ITextSelectionRenderManager),
3685
+ __decorateParam$9(5, Inject(DocSkeletonManagerService)),
3686
+ __decorateParam$9(6, Inject(TextSelectionManagerService))
3601
3687
  ], DocTextSelectionRenderController);
3602
- var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3603
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3688
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3689
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3604
3690
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3605
- return kind && result && __defProp$9(target, key, result), result;
3606
- }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9");
3691
+ return kind && result && __defProp$8(target, key, result), result;
3692
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8");
3607
3693
  function transformBound2OffsetBound(originBound, scene) {
3608
3694
  const topLeft = transformPosition2Offset(originBound.left, originBound.top, scene), bottomRight = transformPosition2Offset(originBound.right, originBound.bottom, scene);
3609
3695
  return {
@@ -3628,6 +3714,32 @@ function transformPosition2Offset(x, y, scene) {
3628
3714
  };
3629
3715
  }
3630
3716
  __name(transformPosition2Offset, "transformPosition2Offset");
3717
+ function transformOffset2Bound(offsetX, offsetY, scene) {
3718
+ const { scaleX, scaleY } = scene.getAncestorScale(), viewMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
3719
+ if (!viewMain)
3720
+ return {
3721
+ x: offsetX,
3722
+ y: offsetY
3723
+ };
3724
+ const { viewportScrollX: actualScrollX, viewportScrollY: actualScrollY } = viewMain, x = offsetX / scaleX + actualScrollX, y = offsetY / scaleY + actualScrollY;
3725
+ return {
3726
+ x,
3727
+ y
3728
+ };
3729
+ }
3730
+ __name(transformOffset2Bound, "transformOffset2Bound");
3731
+ const calcDocRangePositions$1 = /* @__PURE__ */ __name((range, currentRender) => {
3732
+ const { scene, mainComponent, engine } = currentRender, skeleton = currentRender.with(DocSkeletonManagerService).getSkeleton(), startPosition = skeleton.findNodePositionByCharIndex(range.startOffset, !1, range.segmentId, range.segmentPage), endPosition = skeleton.findNodePositionByCharIndex(range.endOffset, !1, range.segmentId, range.segmentPage), document = mainComponent;
3733
+ if (!endPosition || !startPosition)
3734
+ return;
3735
+ const documentOffsetConfig = document.getOffsetConfig(), { docsLeft, docsTop } = documentOffsetConfig, canvasElement = engine.getCanvasElement(), canvasClientRect = canvasElement.getBoundingClientRect(), widthOfCanvas = pxToNum(canvasElement.style.width), { top, left, width } = canvasClientRect, scaleAdjust = width / widthOfCanvas, { scaleX, scaleY } = scene.getAncestorScale(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { borderBoxPointGroup } = convertor.getRangePointData(startPosition, endPosition);
3736
+ return getLineBounding(borderBoxPointGroup).map((bound) => transformBound2OffsetBound(bound, scene)).map((i) => ({
3737
+ left: (i.left + docsLeft * scaleX) * scaleAdjust + left,
3738
+ right: (i.right + docsLeft * scaleX) * scaleAdjust + left,
3739
+ top: (i.top + docsTop * scaleY) * scaleAdjust + top,
3740
+ bottom: (i.bottom + docsTop * scaleY) * scaleAdjust + top
3741
+ }));
3742
+ }, "calcDocRangePositions$1");
3631
3743
  var _a13;
3632
3744
  let DocCanvasPopManagerService = (_a13 = class extends Disposable {
3633
3745
  constructor(_globalPopupManagerService, _renderManagerService, _univerInstanceService, _commandService) {
@@ -3662,28 +3774,17 @@ let DocCanvasPopManagerService = (_a13 = class extends Disposable {
3662
3774
  };
3663
3775
  }
3664
3776
  _createRangePositionObserver(range, currentRender) {
3665
- var _a23;
3666
- const calc = /* @__PURE__ */ __name(() => {
3667
- const { scene, mainComponent, engine } = currentRender, skeleton = currentRender.with(DocSkeletonManagerService).getSkeleton(), startPosition = skeleton.findNodePositionByCharIndex(range.startOffset), endPosition = skeleton.findNodePositionByCharIndex(range.endOffset), document = mainComponent;
3668
- if (!endPosition || !startPosition)
3669
- return;
3670
- const documentOffsetConfig = document.getOffsetConfig(), { docsLeft, docsTop } = documentOffsetConfig, canvasElement = engine.getCanvasElement(), canvasClientRect = canvasElement.getBoundingClientRect(), widthOfCanvas = pxToNum(canvasElement.style.width), { top, left, width } = canvasClientRect, scaleAdjust = width / widthOfCanvas, { scaleX, scaleY } = scene.getAncestorScale(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { contentBoxPointGroup } = convertor.getRangePointData(startPosition, endPosition);
3671
- return getLineBounding(contentBoxPointGroup).map((bound) => transformBound2OffsetBound(bound, scene)).map((i) => ({
3672
- left: (i.left + docsLeft * scaleX) * scaleAdjust + left,
3673
- right: (i.right + docsLeft * scaleX) * scaleAdjust + left,
3674
- top: (i.top + docsTop * scaleY) * scaleAdjust + top,
3675
- bottom: (i.bottom + docsTop * scaleY) * scaleAdjust + top
3676
- }));
3677
- }, "calc"), positions = (_a23 = calc()) != null ? _a23 : [], positions$ = new BehaviorSubject(positions), disposable = new DisposableCollection();
3777
+ var _a22;
3778
+ const positions = (_a22 = calcDocRangePositions$1(range, currentRender)) != null ? _a22 : [], positions$ = new BehaviorSubject(positions), disposable = new DisposableCollection();
3678
3779
  disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
3679
3780
  if (commandInfo.id === SetDocZoomRatioOperation.id) {
3680
- const position = calc();
3781
+ const position = calcDocRangePositions$1(range, currentRender);
3681
3782
  position && positions$.next(position);
3682
3783
  }
3683
3784
  }));
3684
3785
  const viewMain = currentRender.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
3685
3786
  return viewMain && disposable.add(viewMain.onScrollAfter$.subscribeEvent(() => {
3686
- const position = calc();
3787
+ const position = calcDocRangePositions$1(range, currentRender);
3687
3788
  position && positions$.next(position);
3688
3789
  })), {
3689
3790
  positions,
@@ -3743,17 +3844,17 @@ let DocCanvasPopManagerService = (_a13 = class extends Disposable {
3743
3844
  };
3744
3845
  }
3745
3846
  }, __name(_a13, "DocCanvasPopManagerService"), _a13);
3746
- DocCanvasPopManagerService = __decorateClass$9([
3747
- __decorateParam$9(0, Inject(ICanvasPopupService)),
3748
- __decorateParam$9(1, IRenderManagerService),
3749
- __decorateParam$9(2, IUniverInstanceService),
3750
- __decorateParam$9(3, ICommandService)
3847
+ DocCanvasPopManagerService = __decorateClass$8([
3848
+ __decorateParam$8(0, Inject(ICanvasPopupService)),
3849
+ __decorateParam$8(1, IRenderManagerService),
3850
+ __decorateParam$8(2, IUniverInstanceService),
3851
+ __decorateParam$8(3, ICommandService)
3751
3852
  ], DocCanvasPopManagerService);
3752
- var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3753
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3853
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3854
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3754
3855
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3755
- return kind && result && __defProp$8(target, key, result), result;
3756
- }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a14;
3856
+ return kind && result && __defProp$7(target, key, result), result;
3857
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a14;
3757
3858
  let DocsRenderService = (_a14 = class extends RxDisposable {
3758
3859
  constructor(_instanceSrv, _renderManagerService) {
3759
3860
  super(), this._instanceSrv = _instanceSrv, this._renderManagerService = _renderManagerService, this._init();
@@ -3773,16 +3874,16 @@ let DocsRenderService = (_a14 = class extends RxDisposable {
3773
3874
  this._renderManagerService.removeRender(unitId);
3774
3875
  }
3775
3876
  }, __name(_a14, "DocsRenderService"), _a14);
3776
- DocsRenderService = __decorateClass$8([
3877
+ DocsRenderService = __decorateClass$7([
3777
3878
  OnLifecycle(LifecycleStages.Ready, DocsRenderService),
3778
- __decorateParam$8(0, IUniverInstanceService),
3779
- __decorateParam$8(1, IRenderManagerService)
3879
+ __decorateParam$7(0, IUniverInstanceService),
3880
+ __decorateParam$7(1, IRenderManagerService)
3780
3881
  ], DocsRenderService);
3781
- var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3782
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3882
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3883
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3783
3884
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3784
- return kind && result && __defProp$7(target, key, result), result;
3785
- }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7");
3885
+ return kind && result && __defProp$6(target, key, result), result;
3886
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6");
3786
3887
  const SKIP_UNIT_IDS = [
3787
3888
  DEFAULT_EMPTY_DOCUMENT_VALUE,
3788
3889
  DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
@@ -3795,8 +3896,8 @@ let DocContextMenuRenderController = (_a15 = class extends Disposable {
3795
3896
  super(), this._context = _context, this._contextMenuService = _contextMenuService, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, SKIP_UNIT_IDS.includes(this._context.unitId) || (this._initPointerDown(), this._initEditChange());
3796
3897
  }
3797
3898
  _initPointerDown() {
3798
- var _a23, _b;
3799
- const documentsSubscription = ((_b = (_a23 = this._context) == null ? void 0 : _a23.mainComponent) == null ? void 0 : _b.onPointerDown$).subscribeEvent((event) => {
3899
+ var _a22, _b;
3900
+ const documentsSubscription = ((_b = (_a22 = this._context) == null ? void 0 : _a22.mainComponent) == null ? void 0 : _b.onPointerDown$).subscribeEvent((event) => {
3800
3901
  event.button === 2 && this._contextMenuService.triggerContextMenu(event, MenuPosition.CONTEXT_MENU);
3801
3902
  });
3802
3903
  this.disposeWithMe(documentsSubscription);
@@ -3809,16 +3910,16 @@ let DocContextMenuRenderController = (_a15 = class extends Disposable {
3809
3910
  );
3810
3911
  }
3811
3912
  }, __name(_a15, "DocContextMenuRenderController"), _a15);
3812
- DocContextMenuRenderController = __decorateClass$7([
3813
- __decorateParam$7(1, IContextMenuService),
3814
- __decorateParam$7(2, Inject(TextSelectionManagerService)),
3815
- __decorateParam$7(3, ICommandService)
3913
+ DocContextMenuRenderController = __decorateClass$6([
3914
+ __decorateParam$6(1, IContextMenuService),
3915
+ __decorateParam$6(2, Inject(TextSelectionManagerService)),
3916
+ __decorateParam$6(3, ICommandService)
3816
3917
  ], DocContextMenuRenderController);
3817
- var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3818
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3918
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3919
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3819
3920
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3820
- return kind && result && __defProp$6(target, key, result), result;
3821
- }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a16;
3921
+ return kind && result && __defProp$5(target, key, result), result;
3922
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a16;
3822
3923
  let DocResizeRenderController = (_a16 = class extends Disposable {
3823
3924
  constructor(_context, _docPageLayoutService, _textSelectionManagerService) {
3824
3925
  super(), this._context = _context, this._docPageLayoutService = _docPageLayoutService, this._textSelectionManagerService = _textSelectionManagerService;
@@ -3830,133 +3931,213 @@ let DocResizeRenderController = (_a16 = class extends Disposable {
3830
3931
  this.disposeWithMe(
3831
3932
  fromEventSubject(this._context.engine.onTransformChange$).pipe(
3832
3933
  filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),
3833
- throttleTime(16)
3934
+ throttleTime(0, animationFrameScheduler)
3834
3935
  ).subscribe(() => {
3835
3936
  this._docPageLayoutService.calculatePagePosition(), this._textSelectionManagerService.refreshSelection();
3836
3937
  })
3837
3938
  );
3838
3939
  }
3839
3940
  }, __name(_a16, "DocResizeRenderController"), _a16);
3840
- DocResizeRenderController = __decorateClass$6([
3841
- __decorateParam$6(1, Inject(DocPageLayoutService)),
3842
- __decorateParam$6(2, Inject(TextSelectionManagerService))
3941
+ DocResizeRenderController = __decorateClass$5([
3942
+ __decorateParam$5(1, Inject(DocPageLayoutService)),
3943
+ __decorateParam$5(2, Inject(TextSelectionManagerService))
3843
3944
  ], DocResizeRenderController);
3844
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3845
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3945
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3946
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3846
3947
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3847
- return kind && result && __defProp$5(target, key, result), result;
3848
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a17;
3849
- let DocHoverManagerService = (_a17 = class extends Disposable {
3850
- constructor(_univerInstanceService, _renderManagerService) {
3948
+ return kind && result && __defProp$4(target, key, result), result;
3949
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4");
3950
+ const calcDocRangePositions = /* @__PURE__ */ __name((range, documents, skeleton, pageIndex) => {
3951
+ var _a22, _b, _c, _d, _e;
3952
+ const startPosition = skeleton.findNodePositionByCharIndex(range.startOffset, !1, range.segmentId, pageIndex), skeletonData = skeleton.getSkeletonData();
3953
+ let end = range.endOffset;
3954
+ if (range.segmentId) {
3955
+ const root = (_e = Array.from((_b = (_a22 = skeletonData == null ? void 0 : skeletonData.skeFooters.get(range.segmentId)) == null ? void 0 : _a22.values()) != null ? _b : [])[0]) != null ? _e : Array.from((_d = (_c = skeletonData == null ? void 0 : skeletonData.skeHeaders.get(range.segmentId)) == null ? void 0 : _c.values()) != null ? _d : [])[0];
3956
+ root && (end = Math.min(root.ed, end));
3957
+ }
3958
+ const endPosition = skeleton.findNodePositionByCharIndex(end, !1, range.segmentId, pageIndex);
3959
+ if (!endPosition || !startPosition)
3960
+ return;
3961
+ const documentOffsetConfig = documents.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { borderBoxPointGroup } = convertor.getRangePointData(startPosition, endPosition);
3962
+ return getLineBounding(borderBoxPointGroup).map((rect) => ({
3963
+ top: rect.top + documentOffsetConfig.docsTop,
3964
+ bottom: rect.bottom + documentOffsetConfig.docsTop,
3965
+ left: rect.left + documentOffsetConfig.docsLeft,
3966
+ right: rect.right + documentOffsetConfig.docsLeft
3967
+ }));
3968
+ }, "calcDocRangePositions"), calcDocGlyphPosition = /* @__PURE__ */ __name((glyph, documents, skeleton, pageIndex = -1) => {
3969
+ const start = skeleton.findPositionByGlyph(glyph, pageIndex);
3970
+ if (!start)
3971
+ return;
3972
+ const documentOffsetConfig = documents.getOffsetConfig(), startPosition = { ...start, isBack: !0 }, convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { borderBoxPointGroup } = convertor.getRangePointData(startPosition, startPosition), rect = getLineBounding(borderBoxPointGroup)[0];
3973
+ return {
3974
+ top: rect.top + documentOffsetConfig.docsTop,
3975
+ bottom: rect.bottom + documentOffsetConfig.docsTop,
3976
+ left: rect.left + documentOffsetConfig.docsLeft,
3977
+ right: rect.left + documentOffsetConfig.docsLeft + glyph.width
3978
+ };
3979
+ }, "calcDocGlyphPosition");
3980
+ var _a17;
3981
+ let DocEventManagerService = (_a17 = class extends Disposable {
3982
+ constructor(_context, _docSkeletonManagerService) {
3851
3983
  super();
3852
- __publicField(this, "_activeCustomRanges$", new Subject());
3853
- __publicField(this, "activeCustomRanges$", this._activeCustomRanges$.asObservable());
3854
- __publicField(this, "_activeIndex$", new Subject());
3855
- __publicField(this, "activeIndex$", this._activeIndex$.asObservable());
3856
- __publicField(this, "_bullet$", new Subject());
3857
- __publicField(this, "bullet$", this._bullet$.asObservable());
3858
- __publicField(this, "_scrolling", !1);
3859
- this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this.disposeWithMe(() => {
3860
- this._activeCustomRanges$.complete(), this._activeIndex$.complete();
3861
- });
3984
+ __publicField(this, "_hoverCustomRanges$", new Subject());
3985
+ __publicField(this, "hoverCustomRanges$", this._hoverCustomRanges$.pipe(distinctUntilChanged((pre, aft) => pre.length === aft.length && pre.every((item, i) => aft[i].range.rangeId === item.range.rangeId && aft[i].segmentId === item.segmentId && aft[i].segmentPageIndex === item.segmentPageIndex))));
3986
+ __publicField(this, "_clickCustomRanges$", new Subject());
3987
+ __publicField(this, "clickCustomRanges$", this._clickCustomRanges$.asObservable());
3988
+ __publicField(this, "_hoverBullet$", new Subject());
3989
+ __publicField(this, "hoverBullet$", this._hoverBullet$.pipe(distinctUntilChanged((pre, aft) => (pre == null ? void 0 : pre.paragraph.startIndex) === (aft == null ? void 0 : aft.paragraph.startIndex) && (pre == null ? void 0 : pre.segmentId) === (aft == null ? void 0 : aft.segmentId) && (pre == null ? void 0 : pre.segmentPageIndex) === (aft == null ? void 0 : aft.segmentPageIndex))));
3990
+ __publicField(this, "_clickBullet$", new Subject());
3991
+ __publicField(this, "clickBullets$", this._clickBullet$.asObservable());
3992
+ __publicField(this, "_customRangeDirty", !0);
3993
+ __publicField(this, "_bulletDirty", !0);
3994
+ /**
3995
+ * cache the bounding of custom ranges,
3996
+ * it will be updated when the doc-skeleton is recalculated
3997
+ */
3998
+ __publicField(this, "_customRangeBounds", []);
3999
+ /**
4000
+ * cache the bounding of bullets,
4001
+ * it will be updated when the doc-skeleton is recalculated
4002
+ */
4003
+ __publicField(this, "_bulletBounds", []);
4004
+ this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService, this._initResetDirty(), this._initEvents(), this._initPointer();
3862
4005
  }
3863
- _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
3864
- const { documentTransform } = document.getOffsetConfig(), originCoord = viewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
3865
- if (originCoord)
3866
- return documentTransform.clone().invert().applyPoint(originCoord);
4006
+ get _skeleton() {
4007
+ return this._docSkeletonManagerService.getSkeleton();
3867
4008
  }
3868
- _calcActiveCustomRanges(offsetX, offsetY) {
3869
- var _a23, _b;
3870
- const document = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
3871
- if (!document) {
3872
- this._activeCustomRanges$.next([]);
3873
- return;
3874
- }
3875
- const currentRender = this._renderManagerService.getRenderById(document.getUnitId());
3876
- if (!currentRender)
3877
- return null;
3878
- const documentComponent = currentRender.mainComponent, skeleton = currentRender.with(DocSkeletonManagerService).getSkeleton(), { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig(), coord = this._getTransformCoordForDocumentOffset(
3879
- documentComponent,
3880
- currentRender.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN),
3881
- offsetX,
3882
- offsetY
3883
- );
3884
- if (!coord)
3885
- return;
3886
- const node = skeleton.findNodeByCoord(
3887
- coord,
3888
- pageLayoutType,
3889
- pageMarginLeft,
3890
- pageMarginTop
3891
- );
3892
- if (node && node.node) {
3893
- const left = node.node.left + pageMarginLeft, right = node.node.left + node.node.width + pageMarginLeft;
3894
- let index = node.node.parent.st + node.node.parent.glyphGroup.indexOf(node.node);
3895
- const paragraph = getParagraphByGlyph(node.node, document.getBody());
3896
- if (paragraph && paragraph.bullet && index === paragraph.paragraphStart) {
3897
- this._bullet$.next(paragraph), this._activeIndex$.next(null), this._activeCustomRanges$.next([]);
3898
- return;
3899
- }
3900
- if (coord.x < left || coord.x > right) {
3901
- this._activeIndex$.next(null), this._activeCustomRanges$.next([]), this._bullet$.next(null);
3902
- return;
3903
- }
3904
- paragraph && paragraph.bullet && (index = index - 1), this._bullet$.next(null), this._activeIndex$.next(index);
3905
- const ranges = (_b = (_a23 = document.getCustomRanges()) == null ? void 0 : _a23.filter((range) => range.startIndex <= index && range.endIndex >= index)) != null ? _b : [];
3906
- this._activeCustomRanges$.next(ranges);
3907
- }
4009
+ get _documents() {
4010
+ return this._context.mainComponent;
3908
4011
  }
3909
- onMouseMove(evt) {
3910
- if (this._scrolling)
3911
- return;
3912
- const { offsetX, offsetY } = evt;
3913
- this._calcActiveCustomRanges(offsetX, offsetY);
4012
+ dispose() {
4013
+ this._hoverCustomRanges$.complete(), this._clickCustomRanges$.complete(), super.dispose();
3914
4014
  }
3915
- startScroll() {
3916
- this._scrolling || (this._scrolling = !0);
4015
+ _initPointer() {
4016
+ let preCursor = CURSOR_TYPE.TEXT;
4017
+ this.disposeWithMe(this.hoverCustomRanges$.subscribe((ranges) => {
4018
+ ranges.length ? (preCursor = this._context.scene.getCursor(), this._context.scene.setCursor(CURSOR_TYPE.POINTER)) : this._context.scene.setCursor(preCursor);
4019
+ }));
3917
4020
  }
3918
- endScroll() {
3919
- this._scrolling = !1;
4021
+ _initResetDirty() {
4022
+ this.disposeWithMe(this._skeleton.dirty$.subscribe(() => {
4023
+ this._customRangeDirty = !0, this._bulletDirty = !0;
4024
+ })), this.disposeWithMe(
4025
+ fromEventSubject(this._context.engine.onTransformChange$).pipe(
4026
+ filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)
4027
+ ).subscribe(() => {
4028
+ this._customRangeDirty = !0, this._bulletDirty = !0;
4029
+ })
4030
+ );
3920
4031
  }
3921
- }, __name(_a17, "DocHoverManagerService"), _a17);
3922
- DocHoverManagerService = __decorateClass$5([
3923
- __decorateParam$5(0, IUniverInstanceService),
3924
- __decorateParam$5(1, IRenderManagerService)
3925
- ], DocHoverManagerService);
3926
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3927
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3928
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3929
- return kind && result && __defProp$4(target, key, result), result;
3930
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a18;
3931
- let DocHoverRenderController = (_a18 = class extends Disposable {
3932
- constructor(_context, _docHoverManagerService) {
3933
- super(), this._context = _context, this._docHoverManagerService = _docHoverManagerService, this._initPointerDown(), this._initScroll();
4032
+ _initEvents() {
4033
+ this.disposeWithMe(fromEventSubject(this._context.scene.onPointerMove$).pipe(throttleTime(0, animationFrameScheduler)).subscribe((evt) => {
4034
+ this._hoverCustomRanges$.next(
4035
+ this._calcActiveRanges(evt)
4036
+ ), this._hoverBullet$.next(
4037
+ this._calcActiveBullet(evt)
4038
+ );
4039
+ }));
4040
+ const onPointerDown$ = fromEventSubject(this._context.mainComponent.onPointerDown$), onPointerUp$ = fromEventSubject(this._context.scene.onPointerUp$);
4041
+ this.disposeWithMe(onPointerDown$.pipe(
4042
+ mergeMap((down) => onPointerUp$.pipe(take(1), map((up) => ({ down, up })))),
4043
+ filter(({ down, up }) => down.target === up.target && up.timeStamp - down.timeStamp < 300)
4044
+ // filter(({ down, up }) => down.offsetX === up.offsetX && down.offsetY === up.offsetY)
4045
+ ).subscribe(({ down }) => {
4046
+ if (down.button === 2)
4047
+ return;
4048
+ const ranges = this._calcActiveRanges(down);
4049
+ ranges.length && this._clickCustomRanges$.next(ranges.pop());
4050
+ const bullet = this._calcActiveBullet(down);
4051
+ bullet && this._clickBullet$.next(bullet);
4052
+ }));
3934
4053
  }
3935
- _initPointerDown() {
3936
- this.disposeWithMe(
3937
- fromEventSubject(this._context.scene.onPointerMove$).pipe(debounceTime(100)).subscribe((evt) => {
3938
- this._docHoverManagerService.onMouseMove(evt);
4054
+ _buildCustomRangeBoundsBySegment(segmentId, segmentPage = -1) {
4055
+ var _a22, _b, _c;
4056
+ const customRanges = (_c = (_b = (_a22 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a22.getBody()) == null ? void 0 : _b.customRanges) != null ? _c : [], layouts = [];
4057
+ return customRanges.forEach((range) => {
4058
+ const textRange = {
4059
+ startOffset: range.startIndex,
4060
+ endOffset: range.endIndex,
4061
+ collapsed: !1,
4062
+ segmentId
4063
+ }, rects = calcDocRangePositions(textRange, this._documents, this._skeleton, segmentPage);
4064
+ if (!rects)
4065
+ return null;
4066
+ layouts.push({
4067
+ customRange: range,
4068
+ rects,
4069
+ segmentId,
4070
+ segmentPageIndex: segmentPage
4071
+ });
4072
+ }), layouts;
4073
+ }
4074
+ _buildCustomRangeBounds() {
4075
+ var _a22;
4076
+ if (!this._customRangeDirty)
4077
+ return;
4078
+ this._customRangeDirty = !1;
4079
+ const customRangeBounds = [];
4080
+ customRangeBounds.push(...this._buildCustomRangeBoundsBySegment()), (_a22 = this._skeleton.getSkeletonData()) == null || _a22.pages.forEach((page, pageIndex) => {
4081
+ page.headerId && customRangeBounds.push(...this._buildCustomRangeBoundsBySegment(page.headerId, pageIndex)), page.footerId && customRangeBounds.push(...this._buildCustomRangeBoundsBySegment(page.footerId, pageIndex));
4082
+ }), this._customRangeBounds = customRangeBounds;
4083
+ }
4084
+ _calcActiveRanges(evt) {
4085
+ this._buildCustomRangeBounds();
4086
+ const { offsetX, offsetY } = evt, { x, y } = transformOffset2Bound(offsetX, offsetY, this._context.scene);
4087
+ return this._customRangeBounds.filter((layout) => layout.rects.some((rect) => {
4088
+ const { left, right, top, bottom } = rect;
4089
+ return x >= left && x <= right && y >= top && y <= bottom;
4090
+ })).map(
4091
+ (range) => ({
4092
+ segmentId: range.segmentId,
4093
+ range: range.customRange,
4094
+ segmentPageIndex: range.segmentPageIndex
3939
4095
  })
3940
4096
  );
3941
4097
  }
3942
- _initScroll() {
3943
- const viewMain = this._context.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
3944
- viewMain && (this.disposeWithMe(fromEventSubject(viewMain.onScrollAfter$).pipe(debounceTime(60)).subscribe(() => {
3945
- this._docHoverManagerService.endScroll();
3946
- })), this.disposeWithMe(viewMain.onScrollBefore$.subscribeEvent(() => {
3947
- this._docHoverManagerService.startScroll();
3948
- })));
3949
- }
3950
- }, __name(_a18, "DocHoverRenderController"), _a18);
3951
- DocHoverRenderController = __decorateClass$4([
3952
- __decorateParam$4(1, Inject(DocHoverManagerService))
3953
- ], DocHoverRenderController);
4098
+ _buildBulletBoundsBySegment(segmentId, segmentPage = -1) {
4099
+ var _a22, _b;
4100
+ const body = (_a22 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a22.getBody(), paragraphs = (_b = body == null ? void 0 : body.paragraphs) != null ? _b : [], bounds = [];
4101
+ return paragraphs.forEach((paragraph) => {
4102
+ paragraph.bullet && paragraph.bullet.listType.indexOf("CHECK_LIST") === 0 && (/* @__PURE__ */ __name((pageIndex) => {
4103
+ var _a23, _b2, _c;
4104
+ const node = this._skeleton.findNodeByCharIndex(paragraph.startIndex, segmentId, pageIndex), divide = node == null ? void 0 : node.parent, line = divide == null ? void 0 : divide.parent, column = line == null ? void 0 : line.parent, targetLine = column == null ? void 0 : column.lines.find((l2) => l2.paragraphStart && l2.paragraphIndex === paragraph.startIndex), bulletNode = (_c = (_b2 = (_a23 = targetLine == null ? void 0 : targetLine.divides) == null ? void 0 : _a23[0]) == null ? void 0 : _b2.glyphGroup) == null ? void 0 : _c[0];
4105
+ if (!bulletNode || !bulletNode)
4106
+ return;
4107
+ const rect = calcDocGlyphPosition(bulletNode, this._documents, this._skeleton, pageIndex);
4108
+ rect && bounds.push({
4109
+ rect,
4110
+ segmentId,
4111
+ segmentPageIndex: pageIndex,
4112
+ paragraph
4113
+ });
4114
+ }, "calcRect"))(segmentPage);
4115
+ }), bounds;
4116
+ }
4117
+ _buildBulletBounds() {
4118
+ var _a22;
4119
+ this._bulletDirty && (this._bulletDirty = !1, this._bulletBounds = [], this._bulletBounds.push(...this._buildBulletBoundsBySegment()), (_a22 = this._skeleton.getSkeletonData()) == null || _a22.pages.forEach((page, pageIndex) => {
4120
+ page.headerId && this._bulletBounds.push(...this._buildBulletBoundsBySegment(page.headerId, pageIndex)), page.footerId && this._bulletBounds.push(...this._buildBulletBoundsBySegment(page.footerId, pageIndex));
4121
+ }));
4122
+ }
4123
+ _calcActiveBullet(evt) {
4124
+ this._buildBulletBounds();
4125
+ const { offsetX, offsetY } = evt, { x, y } = transformOffset2Bound(offsetX, offsetY, this._context.scene);
4126
+ return this._bulletBounds.find((layout) => {
4127
+ const { left, right, top, bottom } = layout.rect;
4128
+ return x >= left && x <= right && y >= top && y <= bottom;
4129
+ });
4130
+ }
4131
+ }, __name(_a17, "DocEventManagerService"), _a17);
4132
+ DocEventManagerService = __decorateClass$4([
4133
+ __decorateParam$4(1, Inject(DocSkeletonManagerService))
4134
+ ], DocEventManagerService);
3954
4135
  var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3955
4136
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3956
4137
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3957
4138
  return kind && result && __defProp$3(target, key, result), result;
3958
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a19;
3959
- let DocAutoFormatController = (_a19 = class extends Disposable {
4139
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a18;
4140
+ let DocAutoFormatController = (_a18 = class extends Disposable {
3960
4141
  constructor(_docAutoFormatService) {
3961
4142
  super(), this._docAutoFormatService = _docAutoFormatService, this._initListTabAutoFormat(), this._initListSpaceAutoFormat(), this._initDefaultEnterFormat(), this._initExitListAutoFormat();
3962
4143
  }
@@ -3965,15 +4146,15 @@ let DocAutoFormatController = (_a19 = class extends Disposable {
3965
4146
  this._docAutoFormatService.registerAutoFormat({
3966
4147
  id: TabCommand.id,
3967
4148
  match: /* @__PURE__ */ __name((context) => {
3968
- var _a23;
4149
+ var _a22;
3969
4150
  const { selection, paragraphs, unit } = context;
3970
4151
  if (paragraphs.length === 1 && selection.startOffset === paragraphs[0].paragraphStart && paragraphs[0].bullet) {
3971
- const allParagraphs = (_a23 = unit.getBody()) == null ? void 0 : _a23.paragraphs, bulletParagraphs = allParagraphs == null ? void 0 : allParagraphs.filter((p2) => {
3972
- var _a24;
3973
- return ((_a24 = p2.bullet) == null ? void 0 : _a24.listId) === paragraphs[0].bullet.listId;
4152
+ const allParagraphs = (_a22 = unit.getBody()) == null ? void 0 : _a22.paragraphs, bulletParagraphs = allParagraphs == null ? void 0 : allParagraphs.filter((p2) => {
4153
+ var _a23;
4154
+ return ((_a23 = p2.bullet) == null ? void 0 : _a23.listId) === paragraphs[0].bullet.listId;
3974
4155
  });
3975
4156
  return (bulletParagraphs == null ? void 0 : bulletParagraphs.findIndex((p2) => p2.startIndex === paragraphs[0].startIndex)) !== 0;
3976
- } else if (paragraphs.length > 1)
4157
+ } else if (paragraphs.length > 1 && paragraphs.some((p2) => p2.bullet))
3977
4158
  return !0;
3978
4159
  return !1;
3979
4160
  }, "match"),
@@ -3986,7 +4167,26 @@ let DocAutoFormatController = (_a19 = class extends Disposable {
3986
4167
  type: params != null && params.shift ? ChangeListNestingLevelType.decrease : ChangeListNestingLevelType.increase
3987
4168
  }
3988
4169
  }];
3989
- }
4170
+ },
4171
+ priority: 100
4172
+ })
4173
+ ), this.disposeWithMe(
4174
+ this._docAutoFormatService.registerAutoFormat({
4175
+ id: TabCommand.id,
4176
+ match: /* @__PURE__ */ __name((context) => {
4177
+ const { selection } = context, { startNodePosition, endNodePosition } = selection;
4178
+ return !!(startNodePosition && endNodePosition && isInSameTableCell(startNodePosition, endNodePosition) || startNodePosition && !endNodePosition && startNodePosition.path.indexOf("cells") > -1);
4179
+ }, "match"),
4180
+ getMutations(context) {
4181
+ const params = context.commandParams;
4182
+ return [{
4183
+ id: DocTableTabCommand.id,
4184
+ params: {
4185
+ shift: !!(params != null && params.shift)
4186
+ }
4187
+ }];
4188
+ },
4189
+ priority: 99
3990
4190
  })
3991
4191
  );
3992
4192
  }
@@ -3995,16 +4195,16 @@ let DocAutoFormatController = (_a19 = class extends Disposable {
3995
4195
  this._docAutoFormatService.registerAutoFormat({
3996
4196
  id: AfterSpaceCommand.id,
3997
4197
  match: /* @__PURE__ */ __name((context) => {
3998
- var _a23;
4198
+ var _a22;
3999
4199
  const { selection, paragraphs, unit } = context;
4000
4200
  if (!selection.collapsed || paragraphs.length !== 1)
4001
4201
  return !1;
4002
- const text = (_a23 = unit.getBody()) == null ? void 0 : _a23.dataStream.slice(paragraphs[0].paragraphStart, paragraphs[0].paragraphEnd - 1);
4202
+ const text = (_a22 = unit.getBody()) == null ? void 0 : _a22.dataStream.slice(paragraphs[0].paragraphStart, paragraphs[0].paragraphEnd - 1);
4003
4203
  return !!(text && Object.keys(QuickListTypeMap).includes(text));
4004
4204
  }, "match"),
4005
4205
  getMutations(context) {
4006
- var _a23;
4007
- const { paragraphs, unit } = context, text = (_a23 = unit.getBody()) == null ? void 0 : _a23.dataStream.slice(paragraphs[0].paragraphStart, paragraphs[0].paragraphEnd - 1);
4206
+ var _a22;
4207
+ const { paragraphs, unit } = context, text = (_a22 = unit.getBody()) == null ? void 0 : _a22.dataStream.slice(paragraphs[0].paragraphStart, paragraphs[0].paragraphEnd - 1);
4008
4208
  if (text && Object.keys(QuickListTypeMap).includes(text)) {
4009
4209
  const type = QuickListTypeMap[text];
4010
4210
  return [{
@@ -4059,7 +4259,7 @@ let DocAutoFormatController = (_a19 = class extends Disposable {
4059
4259
  })
4060
4260
  );
4061
4261
  }
4062
- }, __name(_a19, "DocAutoFormatController"), _a19);
4262
+ }, __name(_a18, "DocAutoFormatController"), _a18);
4063
4263
  DocAutoFormatController = __decorateClass$3([
4064
4264
  OnLifecycle(LifecycleStages.Rendered, DocAutoFormatController),
4065
4265
  __decorateParam$3(0, Inject(DocAutoFormatService))
@@ -4068,40 +4268,22 @@ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPrope
4068
4268
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
4069
4269
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
4070
4270
  return kind && result && __defProp$2(target, key, result), result;
4071
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a20;
4072
- let DocChecklistRenderController = (_a20 = class extends Disposable {
4073
- constructor(_context, _docSkeletonManagerService, _commandService, _docHoverManagerService) {
4074
- super(), this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService, this._commandService = _commandService, this._docHoverManagerService = _docHoverManagerService, this._initPointerDownObserver(), this._initHoverCursor();
4271
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a19;
4272
+ let DocChecklistRenderController = (_a19 = class extends Disposable {
4273
+ constructor(_context, _docSkeletonManagerService, _commandService, _docEventManagerService, _textSelectionManagerService) {
4274
+ super(), this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService, this._commandService = _commandService, this._docEventManagerService = _docEventManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._initPointerDownObserver(), this._initHoverCursor();
4075
4275
  }
4076
4276
  _initPointerDownObserver() {
4077
- this.disposeWithMe(
4078
- this._context.mainComponent.onPointerDown$.subscribeEvent((evt) => {
4079
- const { offsetX, offsetY } = evt, documentComponent = this._context.mainComponent, coord = this._getTransformCoordForDocumentOffset(
4080
- documentComponent,
4081
- this._context.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN),
4082
- offsetX,
4083
- offsetY
4084
- );
4085
- if (!coord)
4086
- return;
4087
- const { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = documentComponent.getOffsetConfig(), node = this._docSkeletonManagerService.getSkeleton().findNodeByCoord(
4088
- coord,
4089
- pageLayoutType,
4090
- pageMarginLeft,
4091
- pageMarginTop
4092
- );
4093
- if (!node)
4094
- return;
4095
- const paragraph = getParagraphByGlyph(node.node, this._context.unit.getBody());
4096
- paragraph && paragraph.bullet && node.node.glyphType === GlyphType.LIST && (paragraph.bullet.listType === PresetListType.CHECK_LIST || paragraph.bullet.listType === PresetListType.CHECK_LIST_CHECKED) && this._commandService.executeCommand(ToggleCheckListCommand.id, {
4097
- index: paragraph.startIndex
4098
- });
4099
- })
4100
- );
4277
+ this._docEventManagerService.clickBullets$.subscribe((paragraph) => {
4278
+ this._commandService.executeCommand(ToggleCheckListCommand.id, {
4279
+ index: paragraph.paragraph.startIndex,
4280
+ segmentId: paragraph.segmentId
4281
+ });
4282
+ });
4101
4283
  }
4102
4284
  _initHoverCursor() {
4103
4285
  this.disposeWithMe(
4104
- this._docHoverManagerService.bullet$.subscribe((paragraph) => {
4286
+ this._docEventManagerService.hoverBullet$.subscribe((paragraph) => {
4105
4287
  paragraph ? this._context.mainComponent.setCursor(CURSOR_TYPE.POINTER) : this._context.mainComponent.setCursor(CURSOR_TYPE.TEXT);
4106
4288
  })
4107
4289
  );
@@ -4111,11 +4293,12 @@ let DocChecklistRenderController = (_a20 = class extends Disposable {
4111
4293
  if (originCoord)
4112
4294
  return documentTransform.clone().invert().applyPoint(originCoord);
4113
4295
  }
4114
- }, __name(_a20, "DocChecklistRenderController"), _a20);
4296
+ }, __name(_a19, "DocChecklistRenderController"), _a19);
4115
4297
  DocChecklistRenderController = __decorateClass$2([
4116
4298
  __decorateParam$2(1, Inject(DocSkeletonManagerService)),
4117
4299
  __decorateParam$2(2, ICommandService),
4118
- __decorateParam$2(3, Inject(DocHoverManagerService))
4300
+ __decorateParam$2(3, Inject(DocEventManagerService)),
4301
+ __decorateParam$2(4, Inject(TextSelectionManagerService))
4119
4302
  ], DocChecklistRenderController);
4120
4303
  const create = "univer-create", createItem = "univer-create-item", createLabel = "univer-create-label", createInput = "univer-create-input", styles = {
4121
4304
  create,
@@ -4171,8 +4354,8 @@ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPrope
4171
4354
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
4172
4355
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
4173
4356
  return kind && result && __defProp$1(target, key, result), result;
4174
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a21;
4175
- let DocTableController = (_a21 = class extends Disposable {
4357
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a20;
4358
+ let DocTableController = (_a20 = class extends Disposable {
4176
4359
  constructor(_commandService, _componentManager) {
4177
4360
  super(), this._commandService = _commandService, this._componentManager = _componentManager, this._initialize();
4178
4361
  }
@@ -4190,41 +4373,20 @@ let DocTableController = (_a21 = class extends Disposable {
4190
4373
  }
4191
4374
  _init() {
4192
4375
  }
4193
- }, __name(_a21, "DocTableController"), _a21);
4376
+ }, __name(_a20, "DocTableController"), _a20);
4194
4377
  DocTableController = __decorateClass$1([
4195
4378
  OnLifecycle(LifecycleStages.Rendered, DocTableController),
4196
4379
  __decorateParam$1(0, ICommandService),
4197
4380
  __decorateParam$1(1, Inject(ComponentManager))
4198
4381
  ], DocTableController);
4199
- const DocTabCommand = {
4200
- id: "doc.tab.tab-in-doc",
4201
- type: CommandType.COMMAND,
4202
- handler: /* @__PURE__ */ __name(async (accessor) => {
4203
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), commandService = accessor.get(ICommandService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle();
4204
- if (activeTextRange == null)
4205
- return !1;
4206
- const { startNodePosition, endNodePosition } = activeTextRange;
4207
- return startNodePosition && endNodePosition && isInSameTableCell(startNodePosition, endNodePosition) ? commandService.executeCommand(DocTableTabCommand.id) : !1;
4208
- }, "handler")
4209
- }, DocShiftTabCommand = {
4210
- id: "doc.tab.shift-tab-in-doc",
4211
- type: CommandType.COMMAND,
4212
- handler: /* @__PURE__ */ __name(async (accessor) => {
4213
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), commandService = accessor.get(ICommandService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle();
4214
- if (activeTextRange == null)
4215
- return !1;
4216
- const { startNodePosition, endNodePosition } = activeTextRange;
4217
- return startNodePosition && endNodePosition && isInSameTableCell(startNodePosition, endNodePosition) ? commandService.executeCommand(DocTableShiftTabCommand.id) : !1;
4218
- }, "handler")
4219
- };
4220
4382
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
4221
4383
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
4222
4384
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
4223
4385
  return kind && result && __defProp2(target, key, result), result;
4224
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a22;
4225
- let UniverDocsUIPlugin = (_a22 = class extends Plugin {
4386
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a21;
4387
+ let UniverDocsUIPlugin = (_a21 = class extends Plugin {
4226
4388
  constructor(_config, _injector, _renderManagerSrv, _commandService, _logService) {
4227
- super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._commandService = _commandService, this._logService = _logService, this._config = Tools.deepMerge({}, DefaultDocUiConfig, this._config), this._initDependencies(_injector), this._initializeShortcut(), this._initCommand(), this._registerCommands();
4389
+ super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._commandService = _commandService, this._logService = _logService, this._config = Tools.deepMerge({}, DefaultDocUiConfig, this._config), this._initDependencies(_injector), this._initializeShortcut(), this._initCommand();
4228
4390
  }
4229
4391
  onReady() {
4230
4392
  this._initRenderBasics(), this._markDocAsFocused();
@@ -4258,12 +4420,6 @@ let UniverDocsUIPlugin = (_a22 = class extends Plugin {
4258
4420
  this._injector.get(IShortcutService).registerShortcut(shortcut);
4259
4421
  });
4260
4422
  }
4261
- _registerCommands() {
4262
- [
4263
- DocTabCommand,
4264
- DocShiftTabCommand
4265
- ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
4266
- }
4267
4423
  _initDependencies(injector) {
4268
4424
  mergeOverrideWithDependencies([
4269
4425
  [DocUIController, { useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocUIController, this._config), "useFactory") }],
@@ -4275,7 +4431,6 @@ let UniverDocsUIPlugin = (_a22 = class extends Plugin {
4275
4431
  [AppUIController, { useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(AppUIController, this._config), "useFactory") }],
4276
4432
  [IDocClipboardService, { useClass: DocClipboardService }],
4277
4433
  [DocCanvasPopManagerService],
4278
- [DocHoverManagerService],
4279
4434
  [DocParagraphSettingController]
4280
4435
  ], this._config.override).forEach((d) => injector.add(d));
4281
4436
  }
@@ -4306,18 +4461,18 @@ let UniverDocsUIPlugin = (_a22 = class extends Plugin {
4306
4461
  }
4307
4462
  _initRenderModules() {
4308
4463
  [
4464
+ [DocEventManagerService],
4309
4465
  [DocBackScrollRenderController],
4310
4466
  [DocTextSelectionRenderController],
4311
4467
  [DocHeaderFooterController],
4312
4468
  [DocResizeRenderController],
4313
- [DocHoverRenderController],
4314
4469
  [DocContextMenuRenderController],
4315
4470
  [DocChecklistRenderController]
4316
4471
  ].forEach((m2) => {
4317
4472
  this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, m2);
4318
4473
  });
4319
4474
  }
4320
- }, __name(_a22, "UniverDocsUIPlugin"), __publicField(_a22, "pluginName", DOC_UI_PLUGIN_NAME), __publicField(_a22, "type", UniverInstanceType.UNIVER_DOC), _a22);
4475
+ }, __name(_a21, "UniverDocsUIPlugin"), __publicField(_a21, "pluginName", DOC_UI_PLUGIN_NAME), __publicField(_a21, "type", UniverInstanceType.UNIVER_DOC), _a21);
4321
4476
  UniverDocsUIPlugin = __decorateClass([
4322
4477
  __decorateParam(1, Inject(Injector)),
4323
4478
  __decorateParam(2, IRenderManagerService),
@@ -4361,7 +4516,7 @@ export {
4361
4516
  DocCopyCommand,
4362
4517
  DocCreateTableOperation,
4363
4518
  DocCutCommand,
4364
- DocHoverManagerService,
4519
+ DocEventManagerService,
4365
4520
  DocPasteCommand,
4366
4521
  DocRenderController,
4367
4522
  DocUIController,