Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(docs-ui): optimize paragraph-menu and float-menu interact (#4954)
ZhangWeib66db5423ffd
diff --git a/packages/design/src/components/side-menu/index.tsx b/packages/design/src/components/side-menu/index.tsxindex f02fccf29e..31d57ed923 100644--- a/packages/design/src/components/side-menu/index.tsx+++ b/packages/design/src/components/side-menu/index.tsx@@ -133,20 +133,11 @@ export const SideMenu = forwardRef<ISideMenuInstance, ISideMenuProps>((props, repaddingRight: mode === 'float' ? undefined : 0,}}>- {/* <div- className={`- univer-text-xs univer-font-semibold univer-leading-[150%] univer-text-gray-400 univer-font-inter- univer-mb-2- `}- >- contents- </div> */}<divref={containerRef}className={`- univer-flex-1 univer-overflow-y-auto univer-overflow-x-hidden univer-scrollbar- univer-scrollbar-thin univer-scrollbar-track-transparent univer-scrollbar-thumb-[#73737366]- univer-scrollbar-gutter-stable+ univer-flex-1 univer-overflow-y-auto univer-overflow-x-hidden univer-scrollbar-none+ [&::-webkit-scrollbar]:univer-hidden`}>{menus?.map((menu) => (diff --git a/packages/docs-ui/src/components/paragraph-menu/index.tsx b/packages/docs-ui/src/components/paragraph-menu/index.tsxindex 81dfbee408..7935dfcf11 100644--- a/packages/docs-ui/src/components/paragraph-menu/index.tsx+++ b/packages/docs-ui/src/components/paragraph-menu/index.tsx@@ -58,20 +58,21 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {setVisible(false);docParagraphMenuService?.hideParagraphMenu(true);};- if (!activeParagraph) return null;- const paragraphDataStream = dataStream.slice(activeParagraph.paragraphStart, activeParagraph.paragraphEnd);+ const paragraphDataStream = activeParagraph ? dataStream.slice(activeParagraph.paragraphStart, activeParagraph.paragraphEnd) : '';const isOnlyImage = paragraphDataStream === '\b';- if (isOnlyImage) return null;+ const shouldHidden = isOnlyImage || !activeParagraph;return (<><div+ref={anchorRef}className={`univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1univer-rounded-full univer-bg-[#EEEFF1] univer-px-2.5 univer-py-0+ ${shouldHidden ? 'univer-pointer-events-none univer-opacity-0' : ''}`}onMouseEnter={(e) => {popup.onPointerEnter?.(e);diff --git a/packages/docs-ui/src/docs-ui-plugin.ts b/packages/docs-ui/src/docs-ui-plugin.tsindex 3abad462cd..a2f5211ed6 100644--- a/packages/docs-ui/src/docs-ui-plugin.ts+++ b/packages/docs-ui/src/docs-ui-plugin.ts@@ -100,7 +100,6 @@ import { DocMoveCursorController } from './controllers/doc-move-cursor.controlleimport { DocParagraphSettingController } from './controllers/doc-paragraph-setting.controller';import { DocTableController } from './controllers/doc-table.controller';import { DocUIController } from './controllers/doc-ui.controller';-import { FloatMenuController } from './controllers/float-menu.controller';import { DocBackScrollRenderController } from './controllers/render-controllers/back-scroll.render-controller';import { DocChecklistRenderController } from './controllers/render-controllers/doc-checklist.render-controller';import { DocClipboardController } from './controllers/render-controllers/doc-clipboard.controller';@@ -123,6 +122,7 @@ import { DocCanvasPopManagerService } from './services/doc-popup-manager.serviceimport { DocStateChangeManagerService } from './services/doc-state-change-manager.service';import { DocsRenderService } from './services/docs-render.service';import { EditorService, IEditorService } from './services/editor/editor-manager.service';+import { DocFloatMenuService } from './services/float-menu.service';import { IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';import { DocSelectionRenderService } from './services/selection/doc-selection-render.service';import { BreakLineShortcut, DeleteLeftShortcut, DeleteRightShortcut } from './shortcuts/core-editing.shortcut';@@ -194,7 +194,6 @@ export class UniverDocsUIPlugin extends Plugin {// FIXME: LifecycleStages.Rendered must be used, otherwise the menu cannot be added to the DOM, but the sheet ui// plugin can be added in LifecycleStages.Ready[DocUIController],- [FloatMenuController],]);}@@ -330,7 +329,7 @@ export class UniverDocsUIPlugin extends Plugin {[DocStateChangeManagerService],[DocAutoFormatService],[DocMenuStyleService],- [FloatMenuController],+], this._config.override);dependencies.forEach((d) => injector.add(d));}@@ -372,6 +371,7 @@ export class UniverDocsUIPlugin extends Plugin {private _initRenderModules(): void {([[DocEventManagerService],+ [DocFloatMenuService],[DocParagraphMenuService],[DocBackScrollRenderController],[DocSelectionRenderController],diff --git a/packages/docs-ui/src/services/doc-event-manager.service.ts b/packages/docs-ui/src/services/doc-event-manager.service.tsindex b6ef935724..81da74b4d6 100644--- a/packages/docs-ui/src/services/doc-event-manager.service.ts+++ b/packages/docs-ui/src/services/doc-event-manager.service.ts@@ -317,6 +317,17 @@ export class DocEventManagerService extends Disposable implements IRenderModuleprivate _initEvents() {this.disposeWithMe(fromEventSubject(this._context.scene.onPointerMove$).pipe(throttleTime(30)).subscribe((evt) => {+ if (evt.buttons > 0) {+ this._hoverBullet$.next(null);+ this._hoverCustomRanges$.next([]);+ this._hoverParagraph$.next(null);+ this._hoverParagraphLeft$.next(null);+ this._hoverTableCell$.next(null);+ this._hoverTable$.next(null);++ return;+ }+const { x, y } = transformOffset2Bound(evt.offsetX, evt.offsetY, this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({ x, y })diff --git a/packages/docs-ui/src/services/doc-paragraph-menu.service.ts b/packages/docs-ui/src/services/doc-paragraph-menu.service.tsindex 539544e1e3..2aaa051705 100644--- a/packages/docs-ui/src/services/doc-paragraph-menu.service.ts+++ b/packages/docs-ui/src/services/doc-paragraph-menu.service.ts@@ -24,6 +24,7 @@ import { combineLatest, first, throttleTime } from 'rxjs';import { VIEWPORT_KEY } from '../basics/docs-view-key';import { DocEventManagerService } from './doc-event-manager.service';import { DocCanvasPopManagerService } from './doc-popup-manager.service';+import { DocFloatMenuService } from './float-menu.service';export class DocParagraphMenuService extends Disposable implements IRenderModule {private _paragrahMenu: {@@ -41,7 +42,8 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule@Inject(DocSelectionManagerService) private _docSelectionManagerService: DocSelectionManagerService,@Inject(DocEventManagerService) private _docEventManagerService: DocEventManagerService,@Inject(DocCanvasPopManagerService) private _docPopupManagerService: DocCanvasPopManagerService,- @Inject(DocSkeletonManagerService) private _docSkeletonManagerService: DocSkeletonManagerService+ @Inject(DocSkeletonManagerService) private _docSkeletonManagerService: DocSkeletonManagerService,+ @Inject(DocFloatMenuService) private _floatMenuService: DocFloatMenuService) {super();@@ -88,7 +90,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModuleprivate _init() {const handleHoverParagraph = (paragraph: Nullable<IMutiPageParagraphBound>) => {const viewModel = this._docSkeletonManagerService.getViewModel();- if (viewModel.getEditArea() === DocumentEditArea.BODY) {+ if (viewModel.getEditArea() === DocumentEditArea.BODY && !this._floatMenuService.floatMenu) {if (this._paragrahMenu?.active) {return;}diff --git a/packages/docs-ui/src/controllers/float-menu.controller.ts b/packages/docs-ui/src/services/float-menu.service.tssimilarity index 83%rename from packages/docs-ui/src/controllers/float-menu.controller.tsrename to packages/docs-ui/src/services/float-menu.service.tsindex 7557b0edb4..fbf963e0cb 100644--- a/packages/docs-ui/src/controllers/float-menu.controller.ts+++ b/packages/docs-ui/src/services/float-menu.service.ts@@ -15,12 +15,13 @@*/import type { DocumentDataModel, IDisposable, ITextRangeParam, Nullable } from '@univerjs/core';-import type { INodePosition, ITextRangeWithStyle } from '@univerjs/engine-render';+import type { INodePosition, IRenderContext, IRenderModule, ITextRangeWithStyle } from '@univerjs/engine-render';import { DataStreamTreeTokenType, deepCompare, Disposable, Inject, isInternalEditorID, IUniverInstanceService, toDisposable, UniverInstanceType } from '@univerjs/core';import { DocSelectionManagerService } from '@univerjs/docs';import { ComponentManager } from '@univerjs/ui';import { FloatToolbar } from '../components/float-toolbar/FloatToolbar';-import { DocCanvasPopManagerService } from '../services/doc-popup-manager.service';+import { DocCanvasPopManagerService } from './doc-popup-manager.service';+import { DocSelectionRenderService } from './selection/doc-selection-render.service';const FLOAT_MENU_COMPONENT_KEY = 'univer.doc.float-menu';@@ -39,16 +40,22 @@ const SKIP_SYMBOLS: string[] = [DataStreamTreeTokenType.PARAGRAPH,];-export class FloatMenuController extends Disposable {+export class DocFloatMenuService extends Disposable implements IRenderModule {private _floatMenu: Nullable<{ disposable: IDisposable; start: number; end: number }> = null;constructor(+ private _context: IRenderContext<DocumentDataModel>,@Inject(DocSelectionManagerService) private readonly _docSelectionManagerService: DocSelectionManagerService,@Inject(DocCanvasPopManagerService) private readonly _docCanvasPopManagerService: DocCanvasPopManagerService,@Inject(ComponentManager) private readonly _componentManager: ComponentManager,- @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService+ @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService,+ @Inject(DocSelectionRenderService) private readonly _docSelectionRenderService: DocSelectionRenderService) {super();++ if (isInternalEditorID(this._context.unitId)) {+ return;+ }this._registerFloatMenu();this._initSelectionChange();@@ -57,16 +64,22 @@ export class FloatMenuController extends Disposable {});}+ get floatMenu() {+ return this._floatMenu;+ }+private _registerFloatMenu() {this.disposeWithMe(this._componentManager.register(FLOAT_MENU_COMPONENT_KEY, FloatToolbar));}private _initSelectionChange() {+ this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(() => {+ this._hideFloatMenu();+ }));+this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe((selection) => {const { unitId, textRanges } = selection;-- if (isInternalEditorID(unitId)) {- this._hideFloatMenu();+ if (unitId !== this._context.unitId) {return;}