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
fix(docs-ui): disable link & comment on header footer (#2700)
zhangwf93a2294eae3
diff --git a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.tsindex fbf7a39c9c..ea5a7af831 100644--- a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts+++ b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts@@ -16,18 +16,25 @@import type { DocumentDataModel, ICommand } from '@univerjs/core';import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';-import { TextSelectionManagerService } from '@univerjs/docs';+import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';import type { IAccessor } from '@wendellhu/redi';+import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';export const shouldDisableAddLink = (accessor: IAccessor) => {const textSelectionService = accessor.get(TextSelectionManagerService);const univerInstanceService = accessor.get(IUniverInstanceService);const activeRange = textSelectionService.getActiveRange();+ const renderManagerService = accessor.get(IRenderManagerService);+ const render = renderManagerService.getCurrent();+ const skeleton = render?.with(DocSkeletonManagerService).getSkeleton();+ const editArea = skeleton?.getViewModel().getEditArea();+ if (editArea === DocumentEditArea.FOOTER || editArea === DocumentEditArea.HEADER) {+ return true;+ }const doc = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);if (!doc || !activeRange || activeRange.collapsed) {return (true);- return;}const paragraphs = doc.getBody()?.paragraphs;diff --git a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.tsindex 4cd02461d2..8669d31e3a 100644--- a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts+++ b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts@@ -17,8 +17,9 @@import type { DocumentDataModel } from '@univerjs/core';import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';import type { ISetTextSelectionsOperationParams } from '@univerjs/docs';-import { SetTextSelectionsOperation } from '@univerjs/docs';+import { DocSkeletonManagerService, SetTextSelectionsOperation } from '@univerjs/docs';import { Inject } from '@wendellhu/redi';+import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';import { DocHyperLinkPopupService } from '../services/hyper-link-popup.service';@OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController)@@ -26,7 +27,8 @@ export class DocHyperLinkSelectionController extends Disposable {constructor(@ICommandService private readonly _commandService: ICommandService,@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,- @Inject(DocHyperLinkPopupService) private readonly _docHyperLinkService: DocHyperLinkPopupService+ @Inject(DocHyperLinkPopupService) private readonly _docHyperLinkService: DocHyperLinkPopupService,+ @IRenderManagerService private readonly _renderMangerService: IRenderManagerService) {super();@@ -39,6 +41,15 @@ export class DocHyperLinkSelectionController extends Disposable {if (commandInfo.id === SetTextSelectionsOperation.id) {const params = commandInfo.params as ISetTextSelectionsOperationParams;const { unitId, ranges } = params;+ const render = this._renderMangerService.getRenderById(unitId);+ const skeleton = render?.with(DocSkeletonManagerService).getSkeleton();+ const editArea = skeleton?.getViewModel().getEditArea();+ if (editArea !== DocumentEditArea.BODY) {+ this._docHyperLinkService.hideInfoPopup();+ this._docHyperLinkService.hideEditPopup();+ return;+ }+const doc = this._univerInstanceService.getUnit<DocumentDataModel>(unitId, UniverInstanceType.UNIVER_DOC);const primary = ranges[0];if (primary && doc) {diff --git a/packages/docs-thread-comment-ui/src/controllers/menu.ts b/packages/docs-thread-comment-ui/src/controllers/menu.tsindex 4dd3728f1c..ecb33aac7c 100644--- a/packages/docs-thread-comment-ui/src/controllers/menu.ts+++ b/packages/docs-thread-comment-ui/src/controllers/menu.ts@@ -18,8 +18,23 @@ import type { IAccessor } from '@wendellhu/redi';import { UniverInstanceType } from '@univerjs/core';import type { IMenuButtonItem } from '@univerjs/ui';import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';+import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';+import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';+import { debounceTime, Observable } from 'rxjs';import { StartAddCommentOperation } from '../commands/operations/show-comment-panel.operation';+export const shouldDisableAddComment = (accessor: IAccessor) => {+ const renderManagerService = accessor.get(IRenderManagerService);+ const render = renderManagerService.getCurrent();+ const skeleton = render?.with(DocSkeletonManagerService).getSkeleton();+ const editArea = skeleton?.getViewModel().getEditArea();+ if (editArea === DocumentEditArea.FOOTER || editArea === DocumentEditArea.HEADER) {+ return true;+ }++ return false;+};+export function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {id: StartAddCommentOperation.id,@@ -30,5 +45,15 @@ export function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonIttooltip: 'threadCommentUI.panel.addComment',positions: [MenuPosition.TOOLBAR_START, MenuPosition.CONTEXT_MENU],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),+ disabled$: new Observable(function (subscribe) {+ const textSelectionService = accessor.get(TextSelectionManagerService);+ const observer = textSelectionService.textSelection$.pipe(debounceTime(16)).subscribe(() => {+ subscribe.next(shouldDisableAddComment(accessor));+ });++ return () => {+ observer.unsubscribe();+ };+ }),};}