@univerjs/docs-ui 1.2.0 → 1.3.0

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/index.js CHANGED
@@ -3,9 +3,9 @@ import { CreateHeaderFooterCommand, DeleteTextCommand, DocBlockMoveValidatorServ
3
3
  import * as EngineRender from "@univerjs/engine-render";
4
4
  import { BaseObject, CURSOR_TYPE, DRAWING_OBJECT_UPPER_LAYER_INDEX, DeviceInputEventType, DocBackground, DocumentEditArea, DocumentSkeletonPageType, DocumentViewModel, Documents, GlyphType, IRenderManagerService, Layer, LineType, Liquid, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, PageLayoutType, Path, RENDER_CLASS_TYPE, Rect, RegularPolygon, ScrollBar, ScrollTimer, Shape, TRANSFORM_CHANGE_OBSERVABLE_TYPE, UniverRenderEnginePlugin, Vector2, Viewport, compareDocumentSkeletonNestedPagePathOrder, documentSkeletonLineIterator, documentSkeletonTableIterator, getColor, getDocsTableRenderViewport, getDocsTableViewportLeft, getDocumentSkeletonColumnPagePathInfo, getDocumentSkeletonNestedPageOffset, getLastColumn, getNextWheelZoomRatio, getNumberUnitValue, getOffsetRectForDom, getPageFromPath, getParagraphByGlyph, getSystemHighlightColor, getTableIdAndSliceIndex, getTopmostDocsTableHit, hasListGlyph, isFirstGlyph, isIndentByGlyph, parseDataStreamToTree, pixelToPt, ptToPixel, pxToNum, registerDocumentLayoutPresentation } from "@univerjs/engine-render";
5
5
  import { Button, Checkbox, Dialog, Dropdown, DropdownMenu, InputNumber, MessageType, MobileColorPicker, MobileDropdown, MobileSelect, Popup, Select, Separator, Tooltip, borderClassName, clsx, resetButtonClassName, scrollbarClassName, selectClassName, useMobileKeyboardViewportLayout } from "@univerjs/design";
6
- import { BuiltInUIPart, COLOR_PICKER_COMPONENT, COMMON_LABEL_COMPONENT, ComponentManager, ContextMenuGroup, ContextMenuPanel, ContextMenuPosition, CopyCommand, CutCommand, EMOJI_PICKER_COMPONENT, FILE_PNG_CLIPBOARD_MIME_TYPE, FILE__BMP_CLIPBOARD_MIME_TYPE, FILE__JPEG_CLIPBOARD_MIME_TYPE, FILE__WEBP_CLIPBOARD_MIME_TYPE, FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT, FONT_SIZE_COMPONENT, FONT_SIZE_LIST, FormatPainterSessionService, HEADING_ITEM_COMPONENT, HEADING_LIST, HTML_CLIPBOARD_MIME_TYPE, ICanvasPopupService, IClipboardInterfaceService, IContextMenuService, ILayoutService, IMenuManagerService, IMessageService, IRibbonService, IShortcutService, ISidebarService, IUIPartsService, IWorkbenchService, IconManager, KeyCode, MOBILE_UI_MODE, MenuItemType, MenuManagerPosition, MetaKeys, MobileDrawer, MobileKeyboardInsetContext, MobileMenu, MobileZoomIndicator, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, PasteCommand, RectPopup, RibbonInsertGroup, RibbonStartGroup, RibbonViewGroup, SYMBOL_PICKER_COMPONENT, Slider, ToggleFullscreenOperation, ToolbarButton, ToolbarItem, UniverMobileUIPlugin, bindFormatPainterCanvas, connectInjector, getMenuHiddenObservable, getMobileCanvasPanDelta, imageMimeTypeSet, objectPermissionMenuItemFactory, openObjectPermissionDialog, openObjectPermissionPanel, preventBrowserZoomInContainers, useConfigValue, useDependency, useEvent, useInjector, useMobileCanvasPanel, useMobileCanvasViewport, useObservable } from "@univerjs/ui";
6
+ import { BuiltInUIPart, COLOR_PICKER_COMPONENT, COMMON_LABEL_COMPONENT, ComponentManager, ContextMenuGroup, ContextMenuPanel, ContextMenuPosition, CopyCommand, CutCommand, DISABLE_AUTO_FOCUS_KEY, EMOJI_PICKER_COMPONENT, FILE_PNG_CLIPBOARD_MIME_TYPE, FILE__BMP_CLIPBOARD_MIME_TYPE, FILE__JPEG_CLIPBOARD_MIME_TYPE, FILE__WEBP_CLIPBOARD_MIME_TYPE, FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT, FONT_SIZE_COMPONENT, FONT_SIZE_LIST, FormatPainterSessionService, HEADING_ITEM_COMPONENT, HEADING_LIST, HTML_CLIPBOARD_MIME_TYPE, ICanvasPopupService, IClipboardInterfaceService, IContextMenuService, ILayoutService, IMenuManagerService, IMessageService, IRibbonService, IShortcutService, ISidebarService, IUIPartsService, IWorkbenchService, IconManager, KeyCode, MOBILE_UI_MODE, MenuItemType, MenuManagerPosition, MetaKeys, MobileDrawer, MobileKeyboardInsetContext, MobileMenu, MobileZoomIndicator, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, PasteCommand, RectPopup, RibbonInsertGroup, RibbonStartGroup, RibbonViewGroup, SYMBOL_PICKER_COMPONENT, Slider, ToggleFullscreenOperation, ToolbarButton, ToolbarItem, UniverMobileUIPlugin, bindFormatPainterCanvas, connectInjector, getMenuHiddenObservable, getMobileCanvasPanDelta, imageMimeTypeSet, objectPermissionMenuItemFactory, openObjectPermissionDialog, openObjectPermissionPanel, preventBrowserZoomInContainers, useConfigValue, useDependency, useEvent, useInjector, useMobileCanvasPanel, useMobileCanvasViewport, useObservable } from "@univerjs/ui";
7
7
  import { UnitAction, UnitObject } from "@univerjs/protocol";
8
- import { BehaviorSubject, EMPTY, Observable, Subject, animationFrameScheduler, auditTime, combineLatest, debounceTime, distinctUntilChanged, filter, first, fromEvent, map, merge as merge$1, observeOn, of, shareReplay, startWith, switchMap, take, takeUntil, tap, throttleTime } from "rxjs";
8
+ import { BehaviorSubject, EMPTY, Observable, Subject, Subscription, animationFrameScheduler, auditTime, combineLatest, debounceTime, distinctUntilChanged, filter, fromEvent, map, merge as merge$1, observeOn, of, shareReplay, skip, startWith, switchMap, take, takeUntil, tap, throttleTime } from "rxjs";
9
9
  import { bufferTime, filter as filter$1, map as map$1 } from "rxjs/operators";
10
10
  import { createElement, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -3244,7 +3244,7 @@ let DocSelectionRenderService = class DocSelectionRenderService extends RxDispos
3244
3244
  get canFocusing() {
3245
3245
  const ownerDocument = this._getOwnerDocument();
3246
3246
  const activeElement = ownerDocument.activeElement;
3247
- return !this._shouldPreserveExternalFocus() && !this._isAnotherEditorFocused() && (this.isFocusing || activeElement === ownerDocument.body || activeElement === null || activeElement instanceof HTMLElement && this._containsCurrentEmbedRuntimeElement(activeElement));
3247
+ return !this._isInUnfocusedFrame() && !this._shouldPreserveExternalFocus() && !this._isAnotherEditorFocused() && (this.isFocusing || activeElement === ownerDocument.body || activeElement === null || activeElement instanceof HTMLElement && this._containsCurrentEmbedRuntimeElement(activeElement));
3248
3248
  }
3249
3249
  cancelPointerSelection() {
3250
3250
  if (!this._onPointerEvent) return;
@@ -3975,7 +3975,7 @@ let DocSelectionRenderService = class DocSelectionRenderService extends RxDispos
3975
3975
  const activeRangeInstance = this._getActiveRangeInstance();
3976
3976
  const anchor = activeRangeInstance === null || activeRangeInstance === void 0 ? void 0 : activeRangeInstance.getAnchor();
3977
3977
  if (!anchor || anchor && !anchor.visible || this.activeViewPort == null) {
3978
- if (preserveFocus || this._shouldPreserveExternalFocus() || !forceFocus && this._isAnotherEditorFocused()) return;
3978
+ if (preserveFocus || this._shouldPreserveExternalFocus() || !forceFocus && (this._isInUnfocusedFrame() || this._isAnotherEditorFocused())) return;
3979
3979
  this.focus();
3980
3980
  return;
3981
3981
  }
@@ -4253,6 +4253,11 @@ let DocSelectionRenderService = class DocSelectionRenderService extends RxDispos
4253
4253
  if (activeElement instanceof HTMLElement && this._containsCurrentLayoutElement(activeElement)) return false;
4254
4254
  return ((_this$_embedInteracti2 = this._embedInteractionBoundaryService) === null || _this$_embedInteracti2 === void 0 || (_this$_embedInteracti3 = _this$_embedInteracti2.hasRecentInteractionFor) === null || _this$_embedInteracti3 === void 0 ? void 0 : _this$_embedInteracti3.call(_this$_embedInteracti2, currentEmbedOwner, ownerDocument)) === true;
4255
4255
  }
4256
+ _isInUnfocusedFrame() {
4257
+ const ownerDocument = this._getOwnerDocument();
4258
+ const ownerWindow = ownerDocument.defaultView;
4259
+ return ownerWindow != null && ownerWindow.parent !== ownerWindow && !ownerDocument.hasFocus();
4260
+ }
4256
4261
  _isAnotherEditorFocused() {
4257
4262
  const activeElement = this._getOwnerDocument().activeElement;
4258
4263
  return activeElement instanceof HTMLElement && activeElement !== this._input && activeElement.dataset.uComp === this._input.dataset.uComp;
@@ -9005,12 +9010,11 @@ let DocClipboardService = class DocClipboardService extends Disposable {
9005
9010
  }
9006
9011
  }
9007
9012
  async _setClipboardData(documentList, needCache = true, plainTextList) {
9008
- var _documentList$0$body;
9009
9013
  const copyId = generateRandomId(6);
9010
- const text = (plainTextList ? plainTextList.join("\n") : documentList.length > 1 ? documentList.map((doc) => {
9014
+ const text = (plainTextList ?? documentList.map((doc) => {
9011
9015
  var _doc$body3;
9012
9016
  return ((_doc$body3 = doc.body) === null || _doc$body3 === void 0 ? void 0 : _doc$body3.dataStream) || "";
9013
- }).join("\n") : ((_documentList$0$body = documentList[0].body) === null || _documentList$0$body === void 0 ? void 0 : _documentList$0$body.dataStream) || "").replaceAll(DataStreamTreeTokenType.TABLE_START, "").replaceAll(DataStreamTreeTokenType.TABLE_END, "").replaceAll(DataStreamTreeTokenType.TABLE_ROW_START, "").replaceAll(DataStreamTreeTokenType.TABLE_ROW_END, "").replaceAll(DataStreamTreeTokenType.TABLE_CELL_START, "").replaceAll(DataStreamTreeTokenType.TABLE_CELL_END, "").replaceAll(DataStreamTreeTokenType.BLOCK_START, "").replaceAll(DataStreamTreeTokenType.BLOCK_END, "").replaceAll("\r\n", " ").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
9017
+ })).join("\n").replaceAll(DataStreamTreeTokenType.TABLE_START, "").replaceAll(DataStreamTreeTokenType.TABLE_END, "").replaceAll(DataStreamTreeTokenType.TABLE_ROW_START, "").replaceAll(DataStreamTreeTokenType.TABLE_ROW_END, "").replaceAll(DataStreamTreeTokenType.TABLE_CELL_START, "").replaceAll(DataStreamTreeTokenType.TABLE_CELL_END, "").replaceAll(DataStreamTreeTokenType.BLOCK_START, "").replaceAll(DataStreamTreeTokenType.BLOCK_END, "").replaceAll("\r\n", " ").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
9014
9018
  let html = this._umdToHtml.convert(documentList);
9015
9019
  let internalJson = "";
9016
9020
  let internalDocData = null;
@@ -9068,7 +9072,6 @@ let DocClipboardService = class DocClipboardService extends Disposable {
9068
9072
  const snapshot = docDataModel.getSnapshot();
9069
9073
  if (body == null) return;
9070
9074
  for (const range of allRanges) {
9071
- var _docDataModel$getSelf2, _docBody$tables;
9072
9075
  const { startOffset, endOffset, collapsed, rangeType } = range;
9073
9076
  if (collapsed || startOffset == null || endOffset == null) continue;
9074
9077
  if (rangeType === DOC_RANGE_TYPE.RECT) {
@@ -9078,20 +9081,9 @@ let DocClipboardService = class DocClipboardService extends Disposable {
9078
9081
  plainTextResults.push(bodySlice.dataStream);
9079
9082
  continue;
9080
9083
  }
9081
- const deleteRange = {
9082
- startOffset,
9083
- endOffset,
9084
- collapsed
9085
- };
9086
- const docBody = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
9087
- if (docBody == null) continue;
9088
- if ((_docBody$tables = docBody.tables) === null || _docBody$tables === void 0 ? void 0 : _docBody$tables.length) {
9089
- var _body$tables2;
9090
- const completeTableIds = new Set((_body$tables2 = body.tables) === null || _body$tables2 === void 0 ? void 0 : _body$tables2.filter((table) => table.startIndex >= startOffset && table.endIndex <= endOffset).map((table) => table.tableId));
9091
- docBody.tables = docBody.tables.filter((table) => completeTableIds.has(table.tableId));
9092
- }
9084
+ const docBody = getBodySliceForTextXAction(body, startOffset, endOffset, false, sliceType);
9093
9085
  results.push(docBody);
9094
- plainTextResults.push((copyContentHook === null || copyContentHook === void 0 ? void 0 : copyContentHook(deleteRange.startOffset, deleteRange.endOffset, {
9086
+ plainTextResults.push((copyContentHook === null || copyContentHook === void 0 ? void 0 : copyContentHook(startOffset, endOffset, {
9095
9087
  body,
9096
9088
  segmentId,
9097
9089
  unitId: docDataModel.getUnitId()
@@ -12981,7 +12973,7 @@ let DocPageLayoutService = class DocPageLayoutService extends Disposable {
12981
12973
  sceneWidth = docsWidth + horizontalMargin * 2;
12982
12974
  scrollToX = 0;
12983
12975
  }
12984
- if (engineHeight > docsHeight) sceneHeight = (engineHeight - pageMarginTop * 2) / viewScale;
12976
+ if (engineHeight > (docsHeight + pageMarginTop * 2) * viewScale) sceneHeight = (engineHeight - pageMarginTop * 2) / viewScale;
12985
12977
  else sceneHeight = docsHeight + pageMarginTop * 2;
12986
12978
  sceneHeight = this.resolveSceneHeight(sceneHeight);
12987
12979
  scene.transformByState({
@@ -16704,6 +16696,28 @@ const DocOpenPageSettingCommand = {
16704
16696
  }
16705
16697
  };
16706
16698
 
16699
+ //#endregion
16700
+ //#region src/views/EditorColorPicker.tsx
16701
+ function EditorColorPicker(props) {
16702
+ const containerRef = useRef(null);
16703
+ const ColorPickerComponent = useDependency(ComponentManager).get(COLOR_PICKER_COMPONENT);
16704
+ useEffect(() => {
16705
+ const container = containerRef.current;
16706
+ const view = container === null || container === void 0 ? void 0 : container.ownerDocument.defaultView;
16707
+ if (!container || !view) return;
16708
+ const preserveComposition = (event) => {
16709
+ if (event.isComposing && (event.key === "Enter" || event.key === "Escape") && event.target instanceof view.HTMLInputElement && container.contains(event.target)) event.stopPropagation();
16710
+ };
16711
+ view.addEventListener("keydown", preserveComposition, true);
16712
+ return () => view.removeEventListener("keydown", preserveComposition, true);
16713
+ }, []);
16714
+ return /* @__PURE__ */ jsx("div", {
16715
+ ref: containerRef,
16716
+ children: /* @__PURE__ */ jsx(ColorPickerComponent, { ...props })
16717
+ });
16718
+ }
16719
+ EditorColorPicker.componentKey = "docs.editor-color-picker";
16720
+
16707
16721
  //#endregion
16708
16722
  //#region src/views/const.ts
16709
16723
  /**
@@ -17507,7 +17521,7 @@ function TextColorSelectorMenuItemFactory(accessor) {
17507
17521
  type: MenuItemType.BUTTON_SELECTOR,
17508
17522
  selections: [{
17509
17523
  label: {
17510
- name: COLOR_PICKER_COMPONENT,
17524
+ name: EditorColorPicker.componentKey,
17511
17525
  hoverable: false,
17512
17526
  selectable: false
17513
17527
  },
@@ -17936,7 +17950,7 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
17936
17950
  icon: "PaintBucketDoubleIcon",
17937
17951
  selections: [{
17938
17952
  label: {
17939
- name: COLOR_PICKER_COMPONENT,
17953
+ name: EditorColorPicker.componentKey,
17940
17954
  hoverable: false,
17941
17955
  selectable: false
17942
17956
  },
@@ -21524,7 +21538,7 @@ function resolveDocsCustomBlockRenderViewport(params) {
21524
21538
  //#endregion
21525
21539
  //#region package.json
21526
21540
  var name = "@univerjs/docs-ui";
21527
- var version = "1.2.0";
21541
+ var version = "1.3.0";
21528
21542
 
21529
21543
  //#endregion
21530
21544
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -24783,6 +24797,7 @@ let MobileComponentsController = class MobileComponentsController extends Dispos
24783
24797
  }));
24784
24798
  }
24785
24799
  _registerComponents() {
24800
+ this.disposeWithMe(this._componentManager.register(EditorColorPicker.componentKey, EditorColorPicker));
24786
24801
  this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_HEADER_FOOTER_PANEL, MobileHeaderFooterPanel));
24787
24802
  this.disposeWithMe(this._componentManager.register("doc_ui_paragraph-setting-panel", MobileParagraphSettings));
24788
24803
  this.disposeWithMe(this._componentManager.register(DOC_SECTION_SETTING_COMPONENT, MobileSectionSettings));
@@ -25315,8 +25330,10 @@ let DocMobileUIController = class DocMobileUIController extends Disposable {
25315
25330
  this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.HEADER_MENU, () => connectInjector(MobileDocEditDoneButton, this._injector)));
25316
25331
  }
25317
25332
  _initMenus() {
25333
+ const { [ContextMenuPosition.MAIN_AREA]: mainAreaMenu, ...rootMenus } = mobileMenuSchema;
25318
25334
  this._menuManagerService.mergeMenu(menuSchema);
25319
- this._menuManagerService.appendRootMenu(mobileMenuSchema);
25335
+ this._menuManagerService.mergeMenu({ [ContextMenuPosition.MAIN_AREA]: mainAreaMenu });
25336
+ this._menuManagerService.appendRootMenu(rootMenus);
25320
25337
  }
25321
25338
  _initFocusHandler() {
25322
25339
  this.disposeWithMe(this._layoutService.registerFocusHandler(UniverInstanceType.UNIVER_DOC, () => {}));
@@ -26124,6 +26141,9 @@ let DocResizeRenderController = class DocResizeRenderController extends Disposab
26124
26141
  this._initResize();
26125
26142
  }
26126
26143
  _initResize() {
26144
+ this.disposeWithMe(this._context.activated$.pipe(observeOn(animationFrameScheduler)).subscribe((activated) => {
26145
+ if (activated) this._refreshLayoutAndSelection();
26146
+ }));
26127
26147
  this.disposeWithMe(fromEventSubject(this._context.engine.onTransformChange$).pipe(throttleTime(0, animationFrameScheduler)).subscribe(() => this._refreshLayoutAndSelection()));
26128
26148
  this.disposeWithMe(this._sidebarService.sidebarOptions$.pipe(observeOn(animationFrameScheduler)).subscribe(() => this._refreshLayoutAndSelection()));
26129
26149
  }
@@ -27381,7 +27401,7 @@ let DocFloatMenuService = class DocFloatMenuService extends Disposable {
27381
27401
  this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe((selection) => {
27382
27402
  const { unitId, textRanges } = selection;
27383
27403
  if (unitId !== this._context.unitId) return;
27384
- if (this._suppressed || this._embedSuppressed || this._contextService.getContextValue(FOCUSING_COMMON_DRAWINGS)) {
27404
+ if (selection.isEditing || this._suppressed || this._embedSuppressed || this._contextService.getContextValue(FOCUSING_COMMON_DRAWINGS)) {
27385
27405
  this._hideFloatMenu();
27386
27406
  return;
27387
27407
  }
@@ -27668,6 +27688,10 @@ let MobileDocSelectionRenderService = class MobileDocSelectionRenderService exte
27668
27688
  this.disposeWithMe(this.textSelectionInner$.subscribe(() => this._syncMobileSelectionVisuals()));
27669
27689
  this._initMobileKeyboardViewport();
27670
27690
  }
27691
+ focus() {
27692
+ if ((this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || this._context.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && this.isFocusing) return;
27693
+ super.focus();
27694
+ }
27671
27695
  cancelPointerSelection() {
27672
27696
  this._handleDragDisposables.dispose();
27673
27697
  super.cancelPointerSelection();
@@ -27708,10 +27732,11 @@ let MobileDocSelectionRenderService = class MobileDocSelectionRenderService exte
27708
27732
  }
27709
27733
  _syncMobileSelectionVisuals() {
27710
27734
  const activeRange = this._getActiveRangeInstance();
27735
+ const isInternalEditor = isInternalEditorID(this._context.unitId);
27711
27736
  this._selectionVisuals.hide();
27712
27737
  for (const range of this._rangeList) {
27713
27738
  const caret = range.getAnchor();
27714
- if (this.isEditing && range === activeRange) caret === null || caret === void 0 || caret.show();
27739
+ if ((this.isEditing || isInternalEditor) && range === activeRange) caret === null || caret === void 0 || caret.show();
27715
27740
  else caret === null || caret === void 0 || caret.hide();
27716
27741
  }
27717
27742
  if (!activeRange || activeRange.collapsed || this.isEditing) return;
@@ -27745,6 +27770,10 @@ let MobileDocSelectionRenderService = class MobileDocSelectionRenderService exte
27745
27770
  });
27746
27771
  }
27747
27772
  _handleInputBlur(event) {
27773
+ if (isInternalEditorID(this._context.unitId)) {
27774
+ super._handleInputBlur(event);
27775
+ return;
27776
+ }
27748
27777
  if (this.isEditing) {
27749
27778
  this._pendingBlurEvent = event;
27750
27779
  return;
@@ -28492,6 +28521,20 @@ const LIST_ICON_MAP = {
28492
28521
  [PresetListType.CHECK_LIST]: "TodoListDoubleIcon",
28493
28522
  [PresetListType.CHECK_LIST_CHECKED]: "TodoListDoubleIcon"
28494
28523
  };
28524
+ const PASSIVE_PARAGRAPH_MENU_KEYS = /* @__PURE__ */ new Set([
28525
+ "ArrowLeft",
28526
+ "ArrowRight",
28527
+ "ArrowUp",
28528
+ "ArrowDown",
28529
+ "Home",
28530
+ "End",
28531
+ "PageUp",
28532
+ "PageDown",
28533
+ "Shift",
28534
+ "Control",
28535
+ "Alt",
28536
+ "Meta"
28537
+ ]);
28495
28538
  let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28496
28539
  get activeParagraph() {
28497
28540
  var _this$_paragraphMenu;
@@ -28507,8 +28550,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28507
28550
  }
28508
28551
  setBlockMenuDragging(isDragging) {
28509
28552
  this._isBlockMenuDragging = isDragging;
28510
- if (isDragging) this._dragInteraction ??= this._docLayoutInteractionService.beginInteraction();
28511
- else {
28553
+ if (isDragging) {
28554
+ this._cancelParagraphMenuHide();
28555
+ this._dragInteraction ??= this._docLayoutInteractionService.beginInteraction();
28556
+ } else {
28512
28557
  var _this$_dragInteractio;
28513
28558
  (_this$_dragInteractio = this._dragInteraction) === null || _this$_dragInteractio === void 0 || _this$_dragInteractio.dispose();
28514
28559
  this._dragInteraction = null;
@@ -28530,6 +28575,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28530
28575
  this._docLayoutInteractionService = _docLayoutInteractionService;
28531
28576
  this._contextService = _contextService;
28532
28577
  _defineProperty(this, "_paragraphMenu", null);
28578
+ _defineProperty(this, "_paragraphMenuHideTimer", null);
28533
28579
  _defineProperty(this, "_activeTarget$", new BehaviorSubject(null));
28534
28580
  _defineProperty(this, "activeTarget$", this._activeTarget$.asObservable());
28535
28581
  _defineProperty(this, "_focusedTableMenu", null);
@@ -28555,13 +28601,6 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28555
28601
  if (this._focusedTableMenu && !this._canEditDocument(this._focusedTableMenu.target.menuRange)) this.hideFocusedTableMenu();
28556
28602
  }));
28557
28603
  }
28558
- _isCursorInActiveParagraph() {
28559
- if (!this._paragraphMenu) return false;
28560
- const activeTextRange = this._docSelectionManagerService.getActiveTextRange();
28561
- if (!(activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.collapsed)) return false;
28562
- if (!(activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.collapsed) || activeTextRange.startOffset < this._paragraphMenu.paragraph.paragraphStart || activeTextRange.startOffset > this._paragraphMenu.paragraph.paragraphEnd) return false;
28563
- return true;
28564
- }
28565
28604
  _getExpandedSelectionState(ranges) {
28566
28605
  return ranges.reduce((state, range) => {
28567
28606
  if (range.rangeType === DOC_RANGE_TYPE.RECT) {
@@ -28591,6 +28630,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28591
28630
  }
28592
28631
  setParagraphMenuActive(active, focusedTable = false) {
28593
28632
  var _this$_paragraphMenu3, _this$_focusedTableMe2;
28633
+ if (active && !focusedTable) this._cancelParagraphMenuHide();
28594
28634
  const menu = focusedTable ? this._focusedTableMenu : this._paragraphMenu;
28595
28635
  if (menu) menu.active = active;
28596
28636
  if (((_this$_paragraphMenu3 = this._paragraphMenu) === null || _this$_paragraphMenu3 === void 0 ? void 0 : _this$_paragraphMenu3.active) || ((_this$_focusedTableMe2 = this._focusedTableMenu) === null || _this$_focusedTableMe2 === void 0 ? void 0 : _this$_focusedTableMe2.active)) this._menuInteraction ??= this._docLayoutInteractionService.beginInteraction();
@@ -28605,10 +28645,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28605
28645
  var _this$_focusedTableMe3;
28606
28646
  if (this._isBlockMenuDragging) return;
28607
28647
  if ((_this$_focusedTableMe3 = this._focusedTableMenu) === null || _this$_focusedTableMe3 === void 0 ? void 0 : _this$_focusedTableMe3.active) return;
28608
- if (this._docSelectionRenderService.isOnPointerEvent) {
28609
- this.hideParagraphMenu(true);
28610
- return;
28611
- }
28648
+ if (this._docSelectionRenderService.isOnPointerEvent) return;
28612
28649
  const selectionState = this._getExpandedSelectionState(this._docSelectionManagerService.getDocRanges());
28613
28650
  if (selectionState.hasExpandedTextRange) {
28614
28651
  this.hideParagraphMenu(true);
@@ -28635,6 +28672,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28635
28672
  this.showTableMenu(tableBound);
28636
28673
  return;
28637
28674
  }
28675
+ this._scheduleParagraphMenuHide();
28676
+ return;
28638
28677
  }
28639
28678
  this.hideParagraphMenu(true);
28640
28679
  };
@@ -28649,6 +28688,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28649
28688
  handleHoverTarget(p ?? left, table);
28650
28689
  }));
28651
28690
  this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(() => {
28691
+ this._cancelParagraphMenuHide();
28692
+ }));
28693
+ this.disposeWithMe(this._docSelectionRenderService.movingSelection$.subscribe(() => {
28652
28694
  this.hideParagraphMenu(true);
28653
28695
  }));
28654
28696
  this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(({ textRanges, rectRanges }) => {
@@ -28658,13 +28700,13 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28658
28700
  }));
28659
28701
  let lastScrollY = 0;
28660
28702
  this.disposeWithMe(this._context.scene.getViewport("viewMain").onScrollAfter$.subscribeEvent((e) => {
28661
- var _this$_paragraphMenu7;
28703
+ var _this$_paragraphMenu7, _this$_paragraphMenu8;
28662
28704
  if (lastScrollY === e.scrollY) return;
28663
28705
  lastScrollY = e.scrollY;
28664
28706
  this._focusedTableMenuDismiss$.next();
28665
28707
  if ((_this$_paragraphMenu7 = this._paragraphMenu) === null || _this$_paragraphMenu7 === void 0 ? void 0 : _this$_paragraphMenu7.blockRange) return;
28666
28708
  if (this._isBlockMenuDragging) return;
28667
- this.hideParagraphMenu(true);
28709
+ if ((_this$_paragraphMenu8 = this._paragraphMenu) === null || _this$_paragraphMenu8 === void 0 ? void 0 : _this$_paragraphMenu8.active) this.hideParagraphMenu(true);
28668
28710
  }));
28669
28711
  this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(() => {
28670
28712
  if (this._isBlockMenuDragging) return;
@@ -28674,6 +28716,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28674
28716
  if (this._isBlockMenuDragging) return;
28675
28717
  if (this._handleSlashMenuKeydown(config)) return;
28676
28718
  this._focusedTableMenuDismiss$.next();
28719
+ if (PASSIVE_PARAGRAPH_MENU_KEYS.has(config.event.key)) return;
28677
28720
  this.hideParagraphMenu(true);
28678
28721
  }));
28679
28722
  this.disposeWithMe(this._docSelectionRenderService.onInputBefore$.subscribe((config) => {
@@ -28729,10 +28772,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28729
28772
  return null;
28730
28773
  }
28731
28774
  _getSlashMenuParagraph(config) {
28732
- var _this$_paragraphMenu8;
28775
+ var _this$_paragraphMenu9;
28733
28776
  const activeRange = this._getCollapsedTextRange(config);
28734
28777
  const offset = activeRange === null || activeRange === void 0 ? void 0 : activeRange.startOffset;
28735
- const activeParagraph = ((_this$_paragraphMenu8 = this._paragraphMenu) === null || _this$_paragraphMenu8 === void 0 ? void 0 : _this$_paragraphMenu8.paragraph) ?? null;
28778
+ const activeParagraph = ((_this$_paragraphMenu9 = this._paragraphMenu) === null || _this$_paragraphMenu9 === void 0 ? void 0 : _this$_paragraphMenu9.paragraph) ?? null;
28736
28779
  if (activeParagraph && offset != null && offset >= activeParagraph.paragraphStart && offset <= activeParagraph.paragraphEnd) return activeParagraph;
28737
28780
  if (activeParagraph && offset == null) return activeParagraph;
28738
28781
  if (offset == null) return null;
@@ -28753,7 +28796,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28753
28796
  }
28754
28797
  }
28755
28798
  showParagraphMenu(paragraph) {
28756
- var _this$_paragraphMenu9;
28799
+ var _this$_paragraphMenu10;
28757
28800
  if (this._hasExpandedSelection()) {
28758
28801
  this.hideParagraphMenu(true);
28759
28802
  return;
@@ -28763,8 +28806,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28763
28806
  this.hideParagraphMenu(true);
28764
28807
  return;
28765
28808
  }
28766
- if (((_this$_paragraphMenu9 = this._paragraphMenu) === null || _this$_paragraphMenu9 === void 0 ? void 0 : _this$_paragraphMenu9.target.key) === target.key) return;
28767
- this.hideParagraphMenu(true);
28809
+ this._cancelParagraphMenuHide();
28810
+ if (((_this$_paragraphMenu10 = this._paragraphMenu) === null || _this$_paragraphMenu10 === void 0 ? void 0 : _this$_paragraphMenu10.target.key) === target.key) return;
28768
28811
  const targetParagraph = target.paragraph ?? paragraph;
28769
28812
  const blockRange = target.blockRange;
28770
28813
  const getFirstLine = () => {
@@ -28779,33 +28822,11 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28779
28822
  if (!target.cellRange) return menuAnchor;
28780
28823
  return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, menuAnchor);
28781
28824
  };
28782
- const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
28783
- componentKey: DOC_PARAGRAPH_MENU_COMPONENT_KEY,
28784
- constrainToCanvas: true,
28785
- requiresStableLayout: false,
28786
- direction: "left-center",
28787
- onClickOutside: () => {
28788
- if (this._isSlashMenuActive) {
28789
- this.hideParagraphMenu(true);
28790
- return;
28791
- }
28792
- this._docSelectionManagerService.textSelection$.pipe(first()).subscribe(() => {
28793
- if (!this._isCursorInActiveParagraph()) this.hideParagraphMenu(true);
28794
- });
28795
- },
28796
- zIndex: 101
28797
- }, this._context.unitId);
28798
- this._paragraphMenu = {
28799
- paragraph: targetParagraph,
28800
- target,
28801
- blockRange,
28802
- disposable,
28803
- active: false
28804
- };
28805
- this._activeTarget$.next(target);
28825
+ this._showHoverMenu(targetParagraph, target, getFirstLine);
28806
28826
  }
28807
28827
  showTableMenu(tableBound, focused = false) {
28808
- var _this$_focusedTableMe4, _body$tables, _this$_paragraphMenu10;
28828
+ var _this$_focusedTableMe4, _body$tables, _this$_paragraphMenu11;
28829
+ if (!focused) this._cancelParagraphMenuHide();
28809
28830
  if (!focused && ((_this$_focusedTableMe4 = this._focusedTableMenu) === null || _this$_focusedTableMe4 === void 0 || (_this$_focusedTableMe4 = _this$_focusedTableMe4.target.table) === null || _this$_focusedTableMe4 === void 0 ? void 0 : _this$_focusedTableMe4.tableId) === tableBound.tableId) return;
28810
28831
  if (!focused && this._hasExpandedTextSelection()) {
28811
28832
  this.hideParagraphMenu(true);
@@ -28843,7 +28864,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28843
28864
  return;
28844
28865
  }
28845
28866
  if (!focused && this._shouldKeepCurrentCellMenuForTable(table)) return;
28846
- if (!focused && ((_this$_paragraphMenu10 = this._paragraphMenu) === null || _this$_paragraphMenu10 === void 0 ? void 0 : _this$_paragraphMenu10.target.key) === target.key) return;
28867
+ if (!focused && ((_this$_paragraphMenu11 = this._paragraphMenu) === null || _this$_paragraphMenu11 === void 0 ? void 0 : _this$_paragraphMenu11.target.key) === target.key) return;
28847
28868
  const anchorRect = getTableAnchorRect(tableBound);
28848
28869
  const paragraph = {
28849
28870
  rect: tableBound.rect,
@@ -28859,31 +28880,47 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28859
28880
  this._showFocusedTableMenu(tableBound, target);
28860
28881
  return;
28861
28882
  }
28862
- this._showHoverTableMenu(tableBound, target, paragraph);
28863
- }
28864
- _showHoverTableMenu(tableBound, target, paragraph) {
28865
- this.hideParagraphMenu(true);
28866
28883
  const getFirstLine = () => getTableAnchorRect(this._docEventManagerService.tableBounds.get(tableBound.tableId) ?? tableBound);
28867
- const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
28868
- componentKey: DOC_TABLE_BLOCK_MENU_COMPONENT_KEY,
28884
+ this._showHoverMenu(paragraph, target, getFirstLine);
28885
+ }
28886
+ _showHoverMenu(paragraph, target, getAnchor) {
28887
+ const menu = this._paragraphMenu;
28888
+ if ((menu === null || menu === void 0 ? void 0 : menu.active) && menu.target.kind === DocumentBlockType.TABLE !== (target.kind === DocumentBlockType.TABLE)) this.hideParagraphMenu(true);
28889
+ if (this._paragraphMenu) {
28890
+ this._paragraphMenu.paragraph = paragraph;
28891
+ this._paragraphMenu.target = target;
28892
+ this._paragraphMenu.blockRange = target.blockRange;
28893
+ this._paragraphMenu.getAnchor = getAnchor;
28894
+ this._activeTarget$.next(target);
28895
+ return;
28896
+ }
28897
+ const disposable = this._docPopupManagerService.attachPopupToRect(() => {
28898
+ var _this$_paragraphMenu12;
28899
+ return ((_this$_paragraphMenu12 = this._paragraphMenu) === null || _this$_paragraphMenu12 === void 0 ? void 0 : _this$_paragraphMenu12.getAnchor()) ?? getAnchor();
28900
+ }, {
28901
+ direction: target.kind === DocumentBlockType.TABLE ? "top-right" : "left-center",
28902
+ offset: target.kind === DocumentBlockType.TABLE ? [0, 0] : [8, 0],
28903
+ componentKey: DOC_PARAGRAPH_MENU_COMPONENT_KEY,
28904
+ positionChanges$: this.activeTarget$,
28869
28905
  constrainToCanvas: true,
28870
28906
  requiresStableLayout: false,
28871
- direction: "top-right",
28872
28907
  onClickOutside: () => {
28873
- this.hideParagraphMenu(true);
28908
+ if (this._isSlashMenuActive) this.hideParagraphMenu(true);
28874
28909
  },
28875
28910
  zIndex: 101
28876
28911
  }, this._context.unitId);
28877
28912
  this._paragraphMenu = {
28878
28913
  paragraph,
28879
28914
  target,
28915
+ blockRange: target.blockRange,
28880
28916
  disposable,
28881
- active: false
28917
+ active: false,
28918
+ getAnchor
28882
28919
  };
28883
28920
  this._activeTarget$.next(target);
28884
28921
  }
28885
28922
  _showFocusedTableMenu(tableBound, target) {
28886
- var _this$_focusedTableMe5, _this$_paragraphMenu11;
28923
+ var _this$_focusedTableMe5, _this$_paragraphMenu13;
28887
28924
  if (((_this$_focusedTableMe5 = this._focusedTableMenu) === null || _this$_focusedTableMe5 === void 0 ? void 0 : _this$_focusedTableMe5.target.key) === target.key) {
28888
28925
  this._focusedTableMenu.target = target;
28889
28926
  this._focusedTableMenu.bound = tableBound;
@@ -28891,7 +28928,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28891
28928
  return;
28892
28929
  }
28893
28930
  this.hideFocusedTableMenu();
28894
- if (((_this$_paragraphMenu11 = this._paragraphMenu) === null || _this$_paragraphMenu11 === void 0 ? void 0 : _this$_paragraphMenu11.target.key) === target.key) this.hideParagraphMenu(true);
28931
+ if (((_this$_paragraphMenu13 = this._paragraphMenu) === null || _this$_paragraphMenu13 === void 0 ? void 0 : _this$_paragraphMenu13.target.key) === target.key) this.hideParagraphMenu(true);
28895
28932
  const getFocusedAnchor = () => {
28896
28933
  var _this$_focusedTableMe6;
28897
28934
  return getTableAnchorRect(this._docEventManagerService.tableBounds.get(tableBound.tableId) ?? ((_this$_focusedTableMe6 = this._focusedTableMenu) === null || _this$_focusedTableMe6 === void 0 ? void 0 : _this$_focusedTableMe6.bound) ?? tableBound);
@@ -28914,8 +28951,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28914
28951
  this._focusedTableTarget$.next(target);
28915
28952
  }
28916
28953
  _shouldKeepCurrentCellMenuForTable(table) {
28917
- var _this$_paragraphMenu12;
28918
- const target = (_this$_paragraphMenu12 = this._paragraphMenu) === null || _this$_paragraphMenu12 === void 0 ? void 0 : _this$_paragraphMenu12.target;
28954
+ var _this$_paragraphMenu14;
28955
+ const target = (_this$_paragraphMenu14 = this._paragraphMenu) === null || _this$_paragraphMenu14 === void 0 ? void 0 : _this$_paragraphMenu14.target;
28919
28956
  if (!target || target.kind === DocumentBlockType.TABLE || !target.cellRange) return false;
28920
28957
  return target.cellRange.startOffset >= table.startIndex && target.cellRange.startOffset <= table.endIndex;
28921
28958
  }
@@ -28955,7 +28992,21 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28955
28992
  }
28956
28993
  };
28957
28994
  }
28995
+ _cancelParagraphMenuHide() {
28996
+ if (this._paragraphMenuHideTimer != null) {
28997
+ clearTimeout(this._paragraphMenuHideTimer);
28998
+ this._paragraphMenuHideTimer = null;
28999
+ }
29000
+ }
29001
+ _scheduleParagraphMenuHide() {
29002
+ if (!this._paragraphMenu || this._paragraphMenu.active || this._paragraphMenuHideTimer != null) return;
29003
+ this._paragraphMenuHideTimer = setTimeout(() => {
29004
+ this._paragraphMenuHideTimer = null;
29005
+ this.hideParagraphMenu();
29006
+ }, 200);
29007
+ }
28958
29008
  hideParagraphMenu(force = false) {
29009
+ this._cancelParagraphMenuHide();
28959
29010
  if (this._isBlockMenuDragging) return;
28960
29011
  if (this._paragraphMenu && (this._paragraphMenu.disposable.canDispose() || force)) {
28961
29012
  this._paragraphMenu.disposable.dispose();
@@ -28981,6 +29032,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
28981
29032
  this._isBlockMenuDragging = false;
28982
29033
  this.hideFocusedTableMenu();
28983
29034
  this.hideParagraphMenu(true);
29035
+ this._activeTarget$.complete();
28984
29036
  this._focusedTableTarget$.complete();
28985
29037
  this._focusedTableMenuDismiss$.complete();
28986
29038
  (_this$_menuInteractio2 = this._menuInteraction) === null || _this$_menuInteractio2 === void 0 || _this$_menuInteractio2.dispose();
@@ -29259,6 +29311,74 @@ function getBlockRangeAnchorRect(docEventManagerService, blockRange, fallbackPar
29259
29311
  };
29260
29312
  }
29261
29313
 
29314
+ //#endregion
29315
+ //#region src/views/paragraph-menu/paragraph-menu-position.ts
29316
+ function observeParagraphMenuPosition(element, popup, targets$) {
29317
+ let anchor;
29318
+ let table = false;
29319
+ let previousPosition;
29320
+ let disposed = false;
29321
+ const previousTransition = element.style.transition;
29322
+ const updatePosition = () => {
29323
+ var _window$matchMedia, _window;
29324
+ if (disposed || !anchor || element.style.visibility === "hidden") return;
29325
+ const gap = table ? 0 : 8;
29326
+ const boundary = popup.canvasElement.getBoundingClientRect();
29327
+ const containerLeft = Math.max(boundary.left, 0);
29328
+ const containerTop = Math.max(boundary.top, 0);
29329
+ const position = RectPopup.calcPopupPosition({
29330
+ position: {
29331
+ ...anchor,
29332
+ left: anchor.left - gap,
29333
+ right: anchor.right + gap
29334
+ },
29335
+ width: element.clientWidth,
29336
+ height: element.clientHeight,
29337
+ direction: table ? "top-right" : "left-center",
29338
+ containerLeft,
29339
+ containerTop,
29340
+ containerWidth: Math.max(0, Math.min(boundary.right, window.innerWidth) - containerLeft),
29341
+ containerHeight: Math.max(0, Math.min(boundary.bottom, window.innerHeight) - containerTop),
29342
+ boundaryInsets: popup.boundaryInsets,
29343
+ noPushMinimumGap: popup.noPushMinimumGap
29344
+ });
29345
+ if ((previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.top) === position.top && previousPosition.left === position.left && element.style.top === previousPosition.styleTop && element.style.left === previousPosition.styleLeft) return;
29346
+ element.style.transition = previousPosition && !((_window$matchMedia = (_window = window).matchMedia) === null || _window$matchMedia === void 0 ? void 0 : _window$matchMedia.call(_window, "(prefers-reduced-motion: reduce)").matches) ? "top 100ms ease-out, left 100ms ease-out" : "";
29347
+ element.style.top = `${position.top}px`;
29348
+ element.style.left = `${position.left}px`;
29349
+ previousPosition = {
29350
+ ...position,
29351
+ styleTop: element.style.top,
29352
+ styleLeft: element.style.left
29353
+ };
29354
+ };
29355
+ const mutationObserver = new MutationObserver(updatePosition);
29356
+ mutationObserver.observe(element, {
29357
+ attributes: true,
29358
+ attributeFilter: ["style"]
29359
+ });
29360
+ const resizeObserver = new ResizeObserver(updatePosition);
29361
+ resizeObserver.observe(element);
29362
+ resizeObserver.observe(popup.canvasElement);
29363
+ const subscription = new Subscription();
29364
+ subscription.add(targets$.subscribe((target) => {
29365
+ table = (target === null || target === void 0 ? void 0 : target.kind) === DocumentBlockType.TABLE;
29366
+ updatePosition();
29367
+ }));
29368
+ subscription.add(popup.anchorRect$.subscribe((rect) => {
29369
+ anchor = rect;
29370
+ updatePosition();
29371
+ }));
29372
+ return () => {
29373
+ if (disposed) return;
29374
+ disposed = true;
29375
+ subscription.unsubscribe();
29376
+ mutationObserver.disconnect();
29377
+ resizeObserver.disconnect();
29378
+ element.style.transition = previousTransition;
29379
+ };
29380
+ }
29381
+
29262
29382
  //#endregion
29263
29383
  //#region src/views/ParagraphMenu.tsx
29264
29384
  function getParagraphMenuPopupDirection(anchorLeft, menuWidth = 212, viewportPadding = 8, options = {}) {
@@ -29272,26 +29392,9 @@ const PARAGRAPH_MENU_HOVER_OPEN_DELAY = 800;
29272
29392
  const PARAGRAPH_MENU_HOVER_HIDE_DELAY = 240;
29273
29393
  const PARAGRAPH_MENU_HOVER_BRIDGE_EDGE_OVERLAP = 12;
29274
29394
  const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;
29275
- function getParagraphMenuIconSizeClass(iconKey) {
29276
- return iconKey === "TextTypeIcon" ? "univer-size-3" : "univer-size-4";
29277
- }
29278
29395
  function shouldExecuteParagraphMenuMove(validatorService, context) {
29279
29396
  return validatorService.canMoveBlock(context);
29280
29397
  }
29281
- function getParagraphMenuTriggerIconKey(namedStyleType) {
29282
- switch (namedStyleType) {
29283
- case NamedStyleType.HEADING_1: return "H1Icon";
29284
- case NamedStyleType.HEADING_2: return "H2Icon";
29285
- case NamedStyleType.HEADING_3: return "H3Icon";
29286
- case NamedStyleType.HEADING_4: return "H4Icon";
29287
- case NamedStyleType.HEADING_5: return "H5Icon";
29288
- case NamedStyleType.TITLE: return "TitleTypeIcon";
29289
- case NamedStyleType.SUBTITLE: return "SubtitleTypeIcon";
29290
- case NamedStyleType.NORMAL_TEXT:
29291
- case NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED:
29292
- default: return "TextTypeIcon";
29293
- }
29294
- }
29295
29398
  function createParagraphMenuHoverOpenScheduler(openMenu, delay = 800) {
29296
29399
  let openTimer = null;
29297
29400
  const cancel = () => {
@@ -29430,9 +29533,6 @@ const PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS = /* @__PURE__ */ new Set([
29430
29533
  SetInlineFormatTextBackgroundColorCommand.id,
29431
29534
  ResetInlineFormatTextBackgroundColorCommand.id
29432
29535
  ]);
29433
- function shouldRestoreParagraphMenuSelectionAfterCommand(commandId) {
29434
- return !!commandId && PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS.has(commandId);
29435
- }
29436
29536
  function getParagraphMenuCommand(params, targetRange) {
29437
29537
  const commandId = params.commandId ?? params.id ?? (typeof params.label === "string" ? params.label : void 0);
29438
29538
  if (commandId && targetRange && commandId in HEADING_COMMAND_VALUES) return {
@@ -29474,28 +29574,11 @@ function getParagraphMenuCommandParams(commandId, commandParams, target, unitId)
29474
29574
  blockRange: target.blockRange
29475
29575
  };
29476
29576
  }
29477
- function getParagraphMenuType(target, emptyMode) {
29478
- if ((target === null || target === void 0 ? void 0 : target.kind) === "table") return DOC_TABLE_BLOCK_MENU_ID;
29479
- if (emptyMode) return DOC_PARAGRAPH_T_INSERT_MENU_ID;
29480
- if ((target === null || target === void 0 ? void 0 : target.icon) === "ReduceIcon") return DOC_PARAGRAPH_T_DIVIDER_MENU_ID;
29481
- return DOC_PARAGRAPH_T_EDIT_MENU_ID;
29482
- }
29483
- function getParagraphMenuActiveItemIds(target, namedStyleType) {
29484
- if ((target === null || target === void 0 ? void 0 : target.kind) === "blockRange") {
29485
- var _target$blockRange;
29486
- const commandId = getParagraphMenuBlockRangeCommandId((_target$blockRange = target.blockRange) === null || _target$blockRange === void 0 ? void 0 : _target$blockRange.blockType);
29487
- return commandId && PARAGRAPH_MENU_BLOCK_RANGE_COMMAND_IDS.has(commandId) ? [commandId] : [];
29488
- }
29489
- const activeIds = [getParagraphMenuActiveHeadingCommandId(namedStyleType)];
29490
- const listCommandId = (target === null || target === void 0 ? void 0 : target.icon) ? LIST_ICON_TO_COMMAND_ID[target.icon] : void 0;
29491
- if (listCommandId) activeIds.push(listCommandId);
29492
- return activeIds;
29493
- }
29494
29577
  function getParagraphMenuHiddenItemIds(menuType, target, namedStyleType) {
29495
- var _target$blockRange2;
29578
+ var _target$blockRange;
29496
29579
  if (menuType === "doc.menu.paragraph-t.insert") return [];
29497
29580
  const hiddenIds = [...getParagraphMenuHiddenHeadingCommandIds(namedStyleType)];
29498
- const blockType = (target === null || target === void 0 ? void 0 : target.kind) === "blockRange" ? (_target$blockRange2 = target.blockRange) === null || _target$blockRange2 === void 0 ? void 0 : _target$blockRange2.blockType : void 0;
29581
+ const blockType = (target === null || target === void 0 ? void 0 : target.kind) === "blockRange" ? (_target$blockRange = target.blockRange) === null || _target$blockRange === void 0 ? void 0 : _target$blockRange.blockType : void 0;
29499
29582
  if ((target === null || target === void 0 ? void 0 : target.kind) !== "blockRange") hiddenIds.push(DocPasteCommand.id);
29500
29583
  if (blockType === DocumentBlockRangeType.CALLOUT) hiddenIds.push(getParagraphMenuBlockRangeCommandId(DocumentBlockRangeType.CODE), getParagraphMenuBlockRangeCommandId(DocumentBlockRangeType.QUOTE));
29501
29584
  else if (blockType === DocumentBlockRangeType.QUOTE || blockType === DocumentBlockRangeType.CODE) hiddenIds.push(getParagraphMenuBlockRangeCommandId(DocumentBlockRangeType.CALLOUT));
@@ -29759,6 +29842,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29759
29842
  const doc = univerInstanceService.getUnit(popup.unitId, UniverInstanceType.UNIVER_DOC);
29760
29843
  const docParagraphMenuService = renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocParagraphMenuService);
29761
29844
  const docEventManagerService = renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocEventManagerService);
29845
+ const docSelectionRenderService = renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocSelectionRenderService);
29762
29846
  const isFocusedTableMenu = ((_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.focusedTableMenu) === true;
29763
29847
  const activeTarget = useObservable(isFocusedTableMenu ? docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.focusedTableTarget$ : docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget$);
29764
29848
  const slashMenuRequest = useObservable(docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.slashMenuRequest$);
@@ -29772,7 +29856,8 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29772
29856
  docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setParagraphMenuActive(active, isFocusedTableMenu);
29773
29857
  };
29774
29858
  const rawActiveTarget = getActiveTarget();
29775
- const currentActiveTarget = (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" === tableBlockOnly ? rawActiveTarget : null;
29859
+ const isTableMenu = tableBlockOnly || (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table";
29860
+ const currentActiveTarget = (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" === isTableMenu ? rawActiveTarget : null;
29776
29861
  const activeParagraphBound = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.paragraph) ?? (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeParagraph) ?? paragraph ?? paragraphLeft;
29777
29862
  const startIndex = activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.startIndex;
29778
29863
  const dataStream = (doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.dataStream) ?? "";
@@ -29782,11 +29867,38 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29782
29867
  }, [doc, startIndex]);
29783
29868
  const isEmptyParagraph = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.emptyMode) ?? isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);
29784
29869
  const namedStyleType = paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra === void 0 ? void 0 : _paragraphObj$paragra.namedStyleType;
29870
+ const getParagraphMenuTriggerIconKey = () => {
29871
+ switch (namedStyleType) {
29872
+ case NamedStyleType.HEADING_1: return "H1Icon";
29873
+ case NamedStyleType.HEADING_2: return "H2Icon";
29874
+ case NamedStyleType.HEADING_3: return "H3Icon";
29875
+ case NamedStyleType.HEADING_4: return "H4Icon";
29876
+ case NamedStyleType.HEADING_5: return "H5Icon";
29877
+ case NamedStyleType.TITLE: return "TitleTypeIcon";
29878
+ case NamedStyleType.SUBTITLE: return "SubtitleTypeIcon";
29879
+ default: return "TextTypeIcon";
29880
+ }
29881
+ };
29785
29882
  const isModernHeading = (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) === DocumentFlavor.MODERN && startIndex != null && (renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocSkeletonManagerService).getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === startIndex && heading.startOffset < heading.endOffset));
29786
- const targetIconKey = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ?? getParagraphMenuTriggerIconKey(namedStyleType);
29883
+ const targetIconKey = isEmptyParagraph ? "IncreaseIcon" : (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ?? getParagraphMenuTriggerIconKey();
29787
29884
  const TargetIcon = iconManager.get(targetIconKey);
29788
- const paragraphMenuType = useMemo(() => getParagraphMenuType(currentActiveTarget, isEmptyParagraph), [currentActiveTarget, isEmptyParagraph]);
29789
- const paragraphMenuActiveItemIds = useMemo(() => getParagraphMenuActiveItemIds(currentActiveTarget, namedStyleType), [currentActiveTarget, namedStyleType]);
29885
+ const paragraphMenuType = useMemo(() => {
29886
+ if ((currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.kind) === "table") return DOC_TABLE_BLOCK_MENU_ID;
29887
+ if (isEmptyParagraph) return DOC_PARAGRAPH_T_INSERT_MENU_ID;
29888
+ if ((currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) === "ReduceIcon") return DOC_PARAGRAPH_T_DIVIDER_MENU_ID;
29889
+ return DOC_PARAGRAPH_T_EDIT_MENU_ID;
29890
+ }, [currentActiveTarget, isEmptyParagraph]);
29891
+ const paragraphMenuActiveItemIds = useMemo(() => {
29892
+ if ((currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.kind) === "blockRange") {
29893
+ var _currentActiveTarget$;
29894
+ const commandId = getParagraphMenuBlockRangeCommandId((_currentActiveTarget$ = currentActiveTarget.blockRange) === null || _currentActiveTarget$ === void 0 ? void 0 : _currentActiveTarget$.blockType);
29895
+ return commandId && PARAGRAPH_MENU_BLOCK_RANGE_COMMAND_IDS.has(commandId) ? [commandId] : [];
29896
+ }
29897
+ const activeIds = [getParagraphMenuActiveHeadingCommandId(namedStyleType)];
29898
+ const listCommandId = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ? LIST_ICON_TO_COMMAND_ID[currentActiveTarget.icon] : void 0;
29899
+ if (listCommandId) activeIds.push(listCommandId);
29900
+ return activeIds;
29901
+ }, [currentActiveTarget, namedStyleType]);
29790
29902
  const paragraphMenuHiddenItemIds = useMemo(() => (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.kind) === "table" ? [] : getParagraphMenuHiddenItemIds(paragraphMenuType, currentActiveTarget, namedStyleType), [
29791
29903
  currentActiveTarget,
29792
29904
  namedStyleType,
@@ -29826,6 +29938,17 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29826
29938
  if (activeElement === focusedElement || !focusedElement.isConnected && activeElement === body) layoutService.focus();
29827
29939
  }, [layoutService]);
29828
29940
  useLayoutEffect(() => restoreMenuFocus, [restoreMenuFocus]);
29941
+ useLayoutEffect(() => {
29942
+ var _anchorRef$current3;
29943
+ if (isFocusedTableMenu || !docParagraphMenuService) return;
29944
+ const popupElement = (_anchorRef$current3 = anchorRef.current) === null || _anchorRef$current3 === void 0 ? void 0 : _anchorRef$current3.closest("[data-u-comp=\"rect-popup\"]");
29945
+ if (!popupElement) return;
29946
+ return observeParagraphMenuPosition(popupElement, popup, docParagraphMenuService.activeTarget$);
29947
+ }, [
29948
+ docParagraphMenuService,
29949
+ isFocusedTableMenu,
29950
+ popup
29951
+ ]);
29829
29952
  const handleHideMenu = useCallback(() => {
29830
29953
  hoverOpenSchedulerRef.current.cancel();
29831
29954
  restoreMenuFocus();
@@ -29838,6 +29961,16 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29838
29961
  isFocusedTableMenu,
29839
29962
  restoreMenuFocus
29840
29963
  ]);
29964
+ useEffect(() => {
29965
+ if (!visible || isFocusedTableMenu || !docSelectionRenderService) return;
29966
+ const subscription = docSelectionRenderService.onSelectionStart$.pipe(skip(1)).subscribe(handleHideMenu);
29967
+ return () => subscription.unsubscribe();
29968
+ }, [
29969
+ docSelectionRenderService,
29970
+ handleHideMenu,
29971
+ isFocusedTableMenu,
29972
+ visible
29973
+ ]);
29841
29974
  useEffect(() => {
29842
29975
  if (!isFocusedTableMenu || !docParagraphMenuService) return;
29843
29976
  const subscription = docParagraphMenuService.focusedTableMenuDismiss$.subscribe(handleHideMenu);
@@ -29877,7 +30010,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
29877
30010
  };
29878
30011
  const handleOpenMenu = (mode = "pointer") => {
29879
30012
  clearHideTimer();
29880
- if (openMode === "slash") return;
30013
+ if (openMode === "slash" || isDraggingRef.current) return;
29881
30014
  const latestTarget = getActiveTarget();
29882
30015
  setMenuInteractionActive(true);
29883
30016
  const targetRange = latestTarget ? {
@@ -30032,7 +30165,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
30032
30165
  finishParagraphMenuCommand(docParagraphMenuService, handleHideMenu);
30033
30166
  return;
30034
30167
  }
30035
- const previousTextRanges = shouldRestoreParagraphMenuSelectionAfterCommand(commandId) ? getCurrentTextRangesSnapshot() : null;
30168
+ const previousTextRanges = commandId && PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS.has(commandId) ? getCurrentTextRangesSnapshot() : null;
30036
30169
  if (commandId && shouldUseInsertBelowRange(commandId, option) && (latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.moveRange)) docContentInsertService.setInsertRange({
30037
30170
  unitId: popup.unitId,
30038
30171
  startOffset: latestTarget.moveRange.endOffset,
@@ -30064,21 +30197,21 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
30064
30197
  docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setParagraphMenuActive(false, isFocusedTableMenu);
30065
30198
  }, [docParagraphMenuService, isFocusedTableMenu]);
30066
30199
  useEffect(() => {
30067
- if (tableBlockOnly || !slashMenuRequest || handledSlashRequestNonceRef.current >= slashMenuRequest.nonce) return;
30200
+ if (isTableMenu || !slashMenuRequest || handledSlashRequestNonceRef.current >= slashMenuRequest.nonce) return;
30068
30201
  handledSlashRequestNonceRef.current = slashMenuRequest.nonce;
30069
30202
  hoverOpenSchedulerRef.current.cancel();
30070
30203
  clearHideTimer();
30071
30204
  isMouseOver.current = false;
30072
30205
  handleOpenSlashMenu(slashMenuRequest);
30073
- }, [slashMenuRequest, tableBlockOnly]);
30206
+ }, [slashMenuRequest, isTableMenu]);
30074
30207
  if (!currentActiveTarget) return null;
30075
30208
  return /* @__PURE__ */ jsxs(Fragment, { children: [
30076
30209
  /* @__PURE__ */ jsxs("div", {
30077
30210
  "data-u-comp": "paragraph-menu",
30078
- "data-u-table-menu": tableBlockOnly ? "true" : void 0,
30211
+ "data-u-table-menu": isTableMenu ? "true" : void 0,
30079
30212
  "data-u-focused-table-menu": isFocusedTableMenu ? "true" : void 0,
30080
30213
  ref: anchorRef,
30081
- className: clsx("univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-px-2 univer-py-0 univer-shadow-sm univer-transition-colors hover:univer-bg-gray-50 hover:univer-shadow-md dark:!univer-border-gray-600 dark:!univer-bg-gray-900 dark:hover:!univer-bg-gray-800", {
30214
+ className: clsx("univer-inline-flex univer-h-7 univer-cursor-pointer univer-select-none univer-items-center univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-px-2 univer-py-0 univer-shadow-sm univer-transition-colors hover:univer-bg-gray-50 hover:univer-shadow-md dark:!univer-border-gray-600 dark:!univer-bg-gray-900 dark:hover:!univer-bg-gray-800", {
30082
30215
  "univer-mr-1": !isModernHeading,
30083
30216
  "univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800": visible
30084
30217
  }),
@@ -30100,7 +30233,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
30100
30233
  isMouseOver.current = true;
30101
30234
  hoverOpenSchedulerRef.current.openNow();
30102
30235
  },
30103
- children: [/* @__PURE__ */ jsx(TargetIcon, { className: clsx(getParagraphMenuIconSizeClass(targetIconKey), "univer-shrink-0 univer-text-gray-700 dark:!univer-text-gray-0") }), (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.draggable) && /* @__PURE__ */ jsx("button", {
30236
+ children: [/* @__PURE__ */ jsx(TargetIcon, { className: clsx(targetIconKey === "TextTypeIcon" ? "univer-size-3" : "univer-size-4", "univer-shrink-0 univer-text-gray-700 dark:!univer-text-gray-0") }), !isEmptyParagraph && (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.draggable) && /* @__PURE__ */ jsx("button", {
30104
30237
  type: "button",
30105
30238
  className: "univer-group univer-flex univer-h-4 univer-w-2.5 univer-cursor-grab univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 active:univer-cursor-grabbing",
30106
30239
  "aria-label": localeService.t("docs-ui.doc.blockMenu.dragBlock"),
@@ -30117,6 +30250,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
30117
30250
  isMouseOver.current = true;
30118
30251
  isDraggingRef.current = true;
30119
30252
  docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.setBlockMenuDragging(true);
30253
+ handleHideMenu();
30120
30254
  dragRangeRef.current = moveRange;
30121
30255
  dragTargetOffsetRef.current = null;
30122
30256
  setDropRect(null);
@@ -30176,7 +30310,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
30176
30310
  }),
30177
30311
  visible && hoverBridgeStyle && /* @__PURE__ */ jsx("div", {
30178
30312
  "aria-hidden": "true",
30179
- className: "univer-fixed univer-z-[1019] univer-bg-transparent",
30313
+ className: "univer-fixed univer-z-[1019] univer-select-none univer-bg-transparent",
30180
30314
  style: hoverBridgeStyle,
30181
30315
  onMouseEnter: (e) => {
30182
30316
  var _popup$onPointerEnter2;
@@ -30195,6 +30329,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
30195
30329
  anchorRect$,
30196
30330
  direction: menuDirection,
30197
30331
  children: /* @__PURE__ */ jsx("section", {
30332
+ className: "univer-select-none",
30198
30333
  onFocusCapture: (event) => {
30199
30334
  focusedMenuElementRef.current = event.target;
30200
30335
  },
@@ -30454,6 +30589,7 @@ let ComponentsController = class ComponentsController extends Disposable {
30454
30589
  [DOC_PARAGRAPH_MENU_COMPONENT_KEY, ParagraphMenu],
30455
30590
  [DOC_TABLE_BLOCK_MENU_COMPONENT_KEY, TableBlockMenu],
30456
30591
  [FLOAT_MENU_COMPONENT_KEY, FloatToolbar],
30592
+ [EditorColorPicker.componentKey, EditorColorPicker],
30457
30593
  [PAGE_SETTING_COMPONENT_ID, PageSettings],
30458
30594
  [DOC_LAYOUT_RECOVERY_COMPONENT, DocLayoutRecovery]
30459
30595
  ].forEach(([key, comp]) => {
@@ -32044,18 +32180,30 @@ function isSheetFormulaEditor(editorUnitId, univerInstanceService) {
32044
32180
  }
32045
32181
  function executeEditorUndoRedoCommand(options) {
32046
32182
  var _univerInstanceServic;
32047
- const { commandId, commandService, editorUnitId, univerInstanceService } = options;
32183
+ const { commandId, commandService, contextService, editorUnitId, preserveHostFocus, univerInstanceService } = options;
32048
32184
  const shouldUseSheetEditorContext = editorUnitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || editorUnitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
32049
32185
  if (isSheetFormulaEditor(editorUnitId, univerInstanceService)) return;
32050
32186
  const previousFocusedUnitId = ((_univerInstanceServic = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId()) ?? null;
32051
32187
  const shouldRestoreFocus = !shouldUseSheetEditorContext && previousFocusedUnitId !== null && previousFocusedUnitId !== editorUnitId;
32052
32188
  if (!shouldUseSheetEditorContext && previousFocusedUnitId !== editorUnitId) univerInstanceService.focusUnit(editorUnitId);
32053
32189
  commandService.executeCommand(commandId).finally(() => {
32054
- if (shouldRestoreFocus) univerInstanceService.focusUnit(previousFocusedUnitId);
32190
+ var _univerInstanceServic2;
32191
+ if (!shouldRestoreFocus || ((_univerInstanceServic2 = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getUnitId()) !== editorUnitId) return;
32192
+ if (!preserveHostFocus || !contextService) {
32193
+ univerInstanceService.focusUnit(previousFocusedUnitId);
32194
+ return;
32195
+ }
32196
+ const previousDisableAutoFocus = contextService.getContextValue(DISABLE_AUTO_FOCUS_KEY);
32197
+ contextService.setContextValue(DISABLE_AUTO_FOCUS_KEY, true);
32198
+ try {
32199
+ univerInstanceService.focusUnit(previousFocusedUnitId);
32200
+ } finally {
32201
+ contextService.setContextValue(DISABLE_AUTO_FOCUS_KEY, previousDisableAutoFocus);
32202
+ }
32055
32203
  });
32056
32204
  }
32057
32205
  function createEditorUndoRedoKeyboardConfig(options) {
32058
- const { commandService, editorUnitId, handler, keyCodes = [], univerInstanceService } = options;
32206
+ const { commandService, contextService, editorUnitId, handler, keyCodes = [], preserveHostFocus, univerInstanceService } = options;
32059
32207
  const ctrlCommand = MetaKeys.CTRL_COMMAND;
32060
32208
  const ctrlCommandShift = MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT;
32061
32209
  return {
@@ -32080,7 +32228,9 @@ function createEditorUndoRedoKeyboardConfig(options) {
32080
32228
  executeEditorUndoRedoCommand({
32081
32229
  commandId: UndoCommand.id,
32082
32230
  commandService,
32231
+ contextService,
32083
32232
  editorUnitId,
32233
+ preserveHostFocus,
32084
32234
  univerInstanceService
32085
32235
  });
32086
32236
  return;
@@ -32089,7 +32239,9 @@ function createEditorUndoRedoKeyboardConfig(options) {
32089
32239
  executeEditorUndoRedoCommand({
32090
32240
  commandId: RedoCommand.id,
32091
32241
  commandService,
32242
+ contextService,
32092
32243
  editorUnitId,
32244
+ preserveHostFocus,
32093
32245
  univerInstanceService
32094
32246
  });
32095
32247
  return;
@@ -32535,6 +32687,7 @@ const useResize = (editor, isSingle = true, autoScrollbar, autoScroll, layoutSiz
32535
32687
  const RichTextEditor = (props) => {
32536
32688
  const { className, autoFocus, onFocusChange: _onFocusChange, initialValue, onClickOutside: _onClickOutside, preserveHostFocus, cancelDefaultResizeListener, documentLayoutSize, autoScroll = true, autoScrollbar = true, emitSelectionWhileDragging, keyboardEventsOnSelection = false, keyboardEventConfig, layoutSize, pixelRatio, moveCursor = true, style, isSingle, editorId: propsEditorId, onHeightChange, onChange: _onChange, defaultHeight = 32, maxHeight = 32, icon, editorRef, placeholder, noStyle, canvasStyle, renderConfig } = props;
32537
32689
  const commandService = useDependency(ICommandService);
32690
+ const contextService = useDependency(IContextService);
32538
32691
  const univerInstanceService = useDependency(IUniverInstanceService);
32539
32692
  const localeService = useDependency(LocaleService);
32540
32693
  const onFocusChange = useEvent(_onFocusChange);
@@ -32602,14 +32755,18 @@ const RichTextEditor = (props) => {
32602
32755
  useEditorClickOutside(editorId, sheetEmbeddingRef, onClickOutside);
32603
32756
  const resolvedKeyboardEventConfig = useMemo(() => createEditorUndoRedoKeyboardConfig({
32604
32757
  commandService,
32758
+ contextService,
32605
32759
  univerInstanceService,
32606
32760
  editorUnitId: editorId,
32761
+ preserveHostFocus,
32607
32762
  keyCodes: keyboardEventConfig === null || keyboardEventConfig === void 0 ? void 0 : keyboardEventConfig.keyCodes,
32608
32763
  handler: keyboardEventConfig === null || keyboardEventConfig === void 0 ? void 0 : keyboardEventConfig.handler
32609
32764
  }), [
32610
32765
  commandService,
32766
+ contextService,
32611
32767
  editorId,
32612
32768
  keyboardEventConfig,
32769
+ preserveHostFocus,
32613
32770
  univerInstanceService
32614
32771
  ]);
32615
32772
  useLeftAndRightArrow(isFocusing && moveCursor, false, editor);
@@ -32759,4 +32916,4 @@ function MobileRichTextEditor(props) {
32759
32916
  }
32760
32917
 
32761
32918
  //#endregion
32762
- export { AfterSpaceCommand, AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignMenuItemFactory, AlignOperationCommand, AlignRightCommand, BackgroundColorSelectorMenuItemFactory, BoldMenuItemFactory, BreakLineCommand, BulletListCommand, BulletListTypePicker, ChangeListNestingLevelCommand, ChangeListNestingLevelType, ChangeListTypeCommand, CheckListCommand, CoverContentCommand, CreateDocTableCommand, CutContentCommand, DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_UI_PLUGIN_CONFIG_KEY, DOCS_VIEW_KEY, DOC_CONTENT_INSERT_MENU_ID, DOC_CUSTOM_RANGE_CHROME_BACKGROUND_ALPHA, DOC_CUSTOM_RANGE_CHROME_RADIUS, DOC_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE, DOC_PARAGRAPH_T_ALIGN_MENU_ID, DOC_PARAGRAPH_T_COLORS_MENU_ID, DOC_PARAGRAPH_T_DIVIDER_MENU_ID, DOC_PARAGRAPH_T_EDIT_MENU_ID, DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID, DOC_PARAGRAPH_T_INSERT_MENU_ID, DOC_TABLE_BLOCK_MENU_ID, DOC_VERTICAL_PADDING, DeleteCurrentParagraphCommand, DeleteCustomBlockCommand, DeleteLeftCommand, DeleteRightCommand, DocAutoFormatService, DocBackScrollRenderController, DocCanvasPopManagerService, DocClipboardPasteAdapterService, DocContextualRibbonService, DocCopyCommand, DocCreateTableOperation, DocCutCommand, DocEventManagerService, DocFloatMenuService, DocHtmlExportService, DocIMEInputManagerService, DocLayoutInteractionService, DocMobileElementMenuService, DocPageLayoutService, DocParagraphMenuService, DocParagraphPlaceholderRenderController, DocPasteCommand, DocPrintInterceptorService, DocRenderController, DocSelectAllCommand, DocSelectionRenderService, DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand, DocTableInsertColumnCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertRowCommand, DocTableTabCommand, DocUIController, DocViewScaleService, DocsRenderService, menuSchema as DocsUIMenuSchema, EMPTY_PARAGRAPH_MENU_ID, Editor, EditorService, EnterCommand, FLOAT_TEXT_STYLE_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, FloatTextStyleMenuItemFactory, FontFamilySelectorMenuItemFactory, FontSizeSelectorMenuItemFactory, HorizontalLineCommand, IDocClipboardPasteAdapterService, IDocClipboardService, IDocEmbedInteractionBoundaryService, IDocEmbedRuntimeFocusCoordinator, IEditorService, IMEInputCommand, INSERT_BELLOW_MENU_ID, InnerPasteCommand, InsertCustomRangeCommand, ItalicMenuItemFactory, ListOperationCommand, MOBILE_DOC_ELEMENT_MENU, MergeTwoParagraphCommand, MobileDocElementMenu, MobileRichTextEditor, MobileRichTextToolbar, MoveCursorOperation, MoveDocBlockCommand, MoveSelectionOperation, NORMAL_TEXT_SELECTION_PLUGIN_NAME, NodePositionConvertToCursor, NodePositionConvertToRectRange, OrderListCommand, OrderListTypePicker, ParagraphMenuInsertBelowSubmenuItemFactory, ParagraphSettingMenuFactory, LarkPastePlugin as PastePluginLark, UniverPastePlugin as PastePluginUniver, WordPastePlugin as PastePluginWord, QuickListCommand, RectRange, ReplaceSelectionCommand, ReplaceSnapshotCommand, ReplaceTextRunsCommand, ResetInlineFormatTextBackgroundColorCommand, ResetInlineFormatTextColorCommand, RichTextEditor, SetDocInputStyleCommand, SetDocZoomRatioCommand, SetDocZoomRatioOperation, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatTextFillCommand, SetInlineFormatUnderlineCommand, SetParagraphNamedStyleCommand, StrikeThroughMenuItemFactory, SwitchDocModeCommand, TEXT_RANGE_LAYER_INDEX, TabCommand, TextColorSelectorMenuItemFactory, TextRange, ToggleCheckListCommand, UnderlineMenuItemFactory, UniverDocsMobileUIPlugin, UniverDocsUIPlugin, VIEWPORT_KEY, addCustomDecorationBySelectionFactory, addCustomDecorationFactory, buildMoveDocBlockActions, calcDocFitToWidthScale, calcDocRangePositions, captureTextFormat, collectDocsTableLikeEmbedChildUnitIds, convertBodyToHtml, convertClipboardHtmlToDocumentData, convertClipboardRtfToPlainText, convertPositionsToRectRanges, createDefaultDocsTableLikeCustomBlockBleedViewport, createDocsCustomBlockSizeRefreshScheduler, createEditorUndoRedoKeyboardConfig, deleteCustomDecorationFactory, disableMenuWhenHeaderFooterEditing, disableMenuWithoutDocumentUnitPermission, drawDocCustomRangeChrome, executeEditorUndoRedoCommand, findDocRangeNodePositions, genTableSource, generateParagraphs, getAnchorBounding, getCanvasOffsetByEngine, getCommandSkeleton, getCursorWhenDelete, getCutActionsFromDocRanges, getDocBlockRangeMenuId, getDocObjectById, getEditorRuntimeConfig, getEmptyTableCell, getEmptyTableRow, getLineBounding, getListMarkerFallbackBound, getListParagraphContextMenuHit, getOneTextSelectionRange, getStyleInTextRange, getTableColumn, getTextRangeFromCharIndex, hasParagraphInTable, hideMenuWhenSelectionInBlockRange, isInSameTableCell, isTextRangeInAnyBlockRange, isValidRectRange, neoGetDocObject, normalizeDocFitToWidthOptions, registerEditorRuntimeConfig, removeClipboardHtmlImages, resolveDocCustomRangeChromeTheme, resolveDocFitBaseWidth, resolveDocViewScale, resolveDocsCustomBlockRenderViewport, resolveDocsTableLikeCustomBlockBleedViewport, resolveDocsTableLikeCustomBlockContentHeight, resolveDocsTableLikeCustomBlockContentWidth, scrollDocsTableLikeCustomBlockLive, shouldRefreshDocsCustomBlockSizeForCommand, useEditor, useEditorClickOutside, useIsFocusing, useKeyboardEvent, useLeftAndRightArrow, useOnChange, useResize, whenDocAndEditorFocused };
32919
+ export { AfterSpaceCommand, AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignMenuItemFactory, AlignOperationCommand, AlignRightCommand, BackgroundColorSelectorMenuItemFactory, BoldMenuItemFactory, BreakLineCommand, BulletListCommand, BulletListTypePicker, ChangeListNestingLevelCommand, ChangeListNestingLevelType, ChangeListTypeCommand, CheckListCommand, CoverContentCommand, CreateDocTableCommand, CutContentCommand, DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_UI_PLUGIN_CONFIG_KEY, DOCS_VIEW_KEY, DOC_CONTENT_INSERT_MENU_ID, DOC_CUSTOM_RANGE_CHROME_BACKGROUND_ALPHA, DOC_CUSTOM_RANGE_CHROME_RADIUS, DOC_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE, DOC_PARAGRAPH_T_ALIGN_MENU_ID, DOC_PARAGRAPH_T_COLORS_MENU_ID, DOC_PARAGRAPH_T_DIVIDER_MENU_ID, DOC_PARAGRAPH_T_EDIT_MENU_ID, DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID, DOC_PARAGRAPH_T_INSERT_MENU_ID, DOC_TABLE_BLOCK_MENU_ID, DOC_VERTICAL_PADDING, DeleteCurrentParagraphCommand, DeleteCustomBlockCommand, DeleteLeftCommand, DeleteRightCommand, DocAutoFormatService, DocBackScrollRenderController, DocCanvasPopManagerService, DocClipboardPasteAdapterService, DocContextualRibbonService, DocCopyCommand, DocCreateTableOperation, DocCutCommand, DocEventManagerService, DocFloatMenuService, DocHtmlExportService, DocIMEInputManagerService, DocLayoutInteractionService, DocMobileElementMenuService, DocPageLayoutService, DocParagraphMenuService, DocParagraphPlaceholderRenderController, DocPasteCommand, DocPrintInterceptorService, DocRenderController, DocSelectAllCommand, DocSelectionRenderService, DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand, DocTableInsertColumnCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertRowCommand, DocTableTabCommand, DocUIController, DocViewScaleService, DocsRenderService, menuSchema as DocsUIMenuSchema, EMPTY_PARAGRAPH_MENU_ID, Editor, EditorColorPicker, EditorService, EnterCommand, FLOAT_TEXT_STYLE_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, FloatTextStyleMenuItemFactory, FontFamilySelectorMenuItemFactory, FontSizeSelectorMenuItemFactory, HorizontalLineCommand, IDocClipboardPasteAdapterService, IDocClipboardService, IDocEmbedInteractionBoundaryService, IDocEmbedRuntimeFocusCoordinator, IEditorService, IMEInputCommand, INSERT_BELLOW_MENU_ID, InnerPasteCommand, InsertCustomRangeCommand, ItalicMenuItemFactory, ListOperationCommand, MOBILE_DOC_ELEMENT_MENU, MergeTwoParagraphCommand, MobileDocElementMenu, MobileRichTextEditor, MobileRichTextToolbar, MoveCursorOperation, MoveDocBlockCommand, MoveSelectionOperation, NORMAL_TEXT_SELECTION_PLUGIN_NAME, NodePositionConvertToCursor, NodePositionConvertToRectRange, OrderListCommand, OrderListTypePicker, ParagraphMenuInsertBelowSubmenuItemFactory, ParagraphSettingMenuFactory, LarkPastePlugin as PastePluginLark, UniverPastePlugin as PastePluginUniver, WordPastePlugin as PastePluginWord, QuickListCommand, RectRange, ReplaceSelectionCommand, ReplaceSnapshotCommand, ReplaceTextRunsCommand, ResetInlineFormatTextBackgroundColorCommand, ResetInlineFormatTextColorCommand, RichTextEditor, SetDocInputStyleCommand, SetDocZoomRatioCommand, SetDocZoomRatioOperation, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatTextFillCommand, SetInlineFormatUnderlineCommand, SetParagraphNamedStyleCommand, StrikeThroughMenuItemFactory, SwitchDocModeCommand, TEXT_RANGE_LAYER_INDEX, TabCommand, TextColorSelectorMenuItemFactory, TextRange, ToggleCheckListCommand, UnderlineMenuItemFactory, UniverDocsMobileUIPlugin, UniverDocsUIPlugin, VIEWPORT_KEY, addCustomDecorationBySelectionFactory, addCustomDecorationFactory, buildMoveDocBlockActions, calcDocFitToWidthScale, calcDocRangePositions, captureTextFormat, collectDocsTableLikeEmbedChildUnitIds, convertBodyToHtml, convertClipboardHtmlToDocumentData, convertClipboardRtfToPlainText, convertPositionsToRectRanges, createDefaultDocsTableLikeCustomBlockBleedViewport, createDocsCustomBlockSizeRefreshScheduler, createEditorUndoRedoKeyboardConfig, deleteCustomDecorationFactory, disableMenuWhenHeaderFooterEditing, disableMenuWithoutDocumentUnitPermission, drawDocCustomRangeChrome, executeEditorUndoRedoCommand, findDocRangeNodePositions, genTableSource, generateParagraphs, getAnchorBounding, getCanvasOffsetByEngine, getCommandSkeleton, getCursorWhenDelete, getCutActionsFromDocRanges, getDocBlockRangeMenuId, getDocObjectById, getEditorRuntimeConfig, getEmptyTableCell, getEmptyTableRow, getLineBounding, getListMarkerFallbackBound, getListParagraphContextMenuHit, getOneTextSelectionRange, getStyleInTextRange, getTableColumn, getTextRangeFromCharIndex, hasParagraphInTable, hideMenuWhenSelectionInBlockRange, isInSameTableCell, isTextRangeInAnyBlockRange, isValidRectRange, neoGetDocObject, normalizeDocFitToWidthOptions, registerEditorRuntimeConfig, removeClipboardHtmlImages, resolveDocCustomRangeChromeTheme, resolveDocFitBaseWidth, resolveDocViewScale, resolveDocsCustomBlockRenderViewport, resolveDocsTableLikeCustomBlockBleedViewport, resolveDocsTableLikeCustomBlockContentHeight, resolveDocsTableLikeCustomBlockContentWidth, scrollDocsTableLikeCustomBlockLive, shouldRefreshDocsCustomBlockSizeForCommand, useEditor, useEditorClickOutside, useIsFocusing, useKeyboardEvent, useLeftAndRightArrow, useOnChange, useResize, whenDocAndEditorFocused };