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(sheets-hyper-link-ui): sheet link menu display wrong in cell editing (#3825)
zhangwdbcdcba9a42c
diff --git a/packages/core/src/docs/data-model/text-x/build-utils/__test__/custom-range.spec.ts b/packages/core/src/docs/data-model/text-x/build-utils/__test__/custom-range.spec.tsindex 00fc1327b9..99c84b5839 100644--- a/packages/core/src/docs/data-model/text-x/build-utils/__test__/custom-range.spec.ts+++ b/packages/core/src/docs/data-model/text-x/build-utils/__test__/custom-range.spec.ts@@ -15,7 +15,7 @@*/import type { ITextRange } from '../../../../../sheets/typedef';-import { describe, expect, it } from 'vitest'; // 替换为你的文件路径+import { describe, expect, it } from 'vitest';import { CustomRangeType, type ICustomRange } from '../../../../../types/interfaces';import { DataStreamTreeTokenType } from '../../../types';import { excludePointsFromRange, getCustomRangesInterestsWithSelection, shouldDeleteCustomRange } from '../custom-range';diff --git a/packages/sheets-data-validation-ui/src/views/components/date-dropdown/index.tsx b/packages/sheets-data-validation-ui/src/views/components/date-dropdown/index.tsxindex c9b02d3921..589a21413d 100644--- a/packages/sheets-data-validation-ui/src/views/components/date-dropdown/index.tsx+++ b/packages/sheets-data-validation-ui/src/views/components/date-dropdown/index.tsx@@ -94,6 +94,7 @@ export function DateDropdown(props: IDropdownComponentProps) {t: CellValueType.NUMBER,}, rule))) {+ hideFn();await commandService.executeCommand(SetCellEditVisibleOperation.id, {visible: false,eventType: DeviceInputEventType.Keyboard,@@ -124,7 +125,6 @@ export function DateDropdown(props: IDropdownComponentProps) {},},});- hideFn();} else {rejectInputController.showReject(validator.getRuleFinalError(rule));}diff --git a/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx b/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsxindex d6202263ea..8b594a6b50 100644--- a/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx+++ b/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx@@ -232,18 +232,20 @@ export function ListDropDown(props: IDropdownComponentProps) {unitId,});}-- await commandService.executeCommand(SetCellEditVisibleOperation.id, {- visible: false,- eventType: DeviceInputEventType.Keyboard,- unitId,- keycode: KeyCode.ESC,- } as IEditorBridgeServiceVisibleParam);- commandService.executeCommand(SetRangeValuesCommand.id, params);setLocalValue(str);if (!multiple) {hideFn();}++ if (editorBridgeService.isVisible().visible) {+ await commandService.executeCommand(SetCellEditVisibleOperation.id, {+ visible: false,+ eventType: DeviceInputEventType.Keyboard,+ unitId,+ keycode: KeyCode.ESC,+ } as IEditorBridgeServiceVisibleParam);+ }+ commandService.executeCommand(SetRangeValuesCommand.id, params);}}options={options}onEdit={handleEdit}diff --git a/packages/sheets-formula-ui/src/views/range-selector/index.tsx b/packages/sheets-formula-ui/src/views/range-selector/index.tsxindex 6614e7f4c6..ecc23901c8 100644--- a/packages/sheets-formula-ui/src/views/range-selector/index.tsx+++ b/packages/sheets-formula-ui/src/views/range-selector/index.tsx@@ -234,7 +234,7 @@ export function RangeSelector(props: IRangeSelectorProps) {useEffect(() => {const d1 = commandService.beforeCommandExecuted((info) => {- if (info.id === SetWorksheetActiveOperation.id) {+ if (info.id === SetWorksheetActiveOperation.id && !isSupportAcrossSheet) {isFocusSet(false);onBlur();// Refresh the component@@ -253,7 +253,7 @@ export function RangeSelector(props: IRangeSelectorProps) {d1.dispose();d2.dispose();};- }, []);+ }, [isSupportAcrossSheet]);useEffect(() => {isFocusSet(_isFocus);diff --git a/packages/sheets-hyper-link-ui/src/controllers/menu.ts b/packages/sheets-hyper-link-ui/src/controllers/menu.tsindex d12573580c..d138cb48bb 100644--- a/packages/sheets-hyper-link-ui/src/controllers/menu.ts+++ b/packages/sheets-hyper-link-ui/src/controllers/menu.ts@@ -14,21 +14,52 @@* limitations under the License.*/-import type { IAccessor, Workbook } from '@univerjs/core';+import type { IAccessor, Nullable, Workbook } from '@univerjs/core';+import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';import type { IMenuItem, IShortcutItem } from '@univerjs/ui';-import { DOCS_ZEN_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';+import { DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { DocSelectionManagerService } from '@univerjs/docs';import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';import { getCurrentRangeDisable$, IEditorBridgeService, whenSheetEditorFocused } from '@univerjs/sheets-ui';import { getMenuHiddenObservable, KeyCode, MenuGroup, MenuItemType, MenuPosition, MetaKeys } from '@univerjs/ui';-import { map, mergeMap, Observable } from 'rxjs';+import { map, mergeMap, Observable, of } from 'rxjs';import { InsertHyperLinkOperation, InsertHyperLinkToolbarOperation } from '../commands/operations/popup.operations';import { getShouldDisableCellLink, shouldDisableAddLink } from '../utils';+const getZenLinkDisable$ = (accessor: IAccessor, unitId = DOCS_ZEN_EDITOR_UNIT_ID_KEY) => {+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const textSelectionManagerService = accessor.get(DocSelectionManagerService);++ return textSelectionManagerService.textSelection$.pipe(+ map((selection) => {+ if (!selection || selection.unitId !== unitId) {+ return true;+ }+ const editorBridgeService = accessor.get(IEditorBridgeService);+ const state = editorBridgeService.getEditCellState();+ if (!state) {+ return true;+ }+ const target = getSheetCommandTarget(univerInstanceService, { unitId: state.unitId, subUnitId: state.sheetId });+ if (!target?.worksheet) {+ return true;+ }++ if (getShouldDisableCellLink(target.worksheet, state.row, state.column)) {+ return true;+ }++ return shouldDisableAddLink(accessor);+ })+ );+};+const getLinkDisable$ = (accessor: IAccessor) => {const disableRange$ = getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }, true);const univerInstanceService = accessor.get(IUniverInstanceService);const sheetSelectionService = accessor.get(SheetsSelectionsService);+ const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;+const disableCell$ = univerInstanceService.focused$.pipe(map((focused) => {if (!focused) {@@ -56,44 +87,26 @@ const getLinkDisable$ = (accessor: IAccessor) => {}const row = selections[0].range.startRow;const col = selections[0].range.startColumn;- return getShouldDisableCellLink(sheet, row, col);- })- );-- return disableRange$.pipe(mergeMap(((disableRange) => disableCell$.pipe(map((disableCell) => disableRange || disableCell)))));-};--const getZenLinkDisable$ = (accessor: IAccessor) => {- const univerInstanceService = accessor.get(IUniverInstanceService);- return univerInstanceService.focused$.pipe(- mergeMap((focused) => {- if (!focused || focused !== DOCS_ZEN_EDITOR_UNIT_ID_KEY) {- return new Observable<null>((sub) => sub.next(null));- }- const textSelectionManagerService = accessor.get(DocSelectionManagerService);- return textSelectionManagerService.textSelection$;+ return {+ sheet,+ row,+ col,+ };}),- map((selection) => {- if (!selection || selection.unitId !== DOCS_ZEN_EDITOR_UNIT_ID_KEY) {- return true;- }- const editorBridgeService = accessor.get(IEditorBridgeService);- const state = editorBridgeService.getEditCellState();- if (!state) {- return true;- }- const target = getSheetCommandTarget(univerInstanceService, { unitId: state.unitId, subUnitId: state.sheetId });- if (!target?.worksheet) {- return true;+ mergeMap((editingCell) => {+ if (editingCell === true) {+ return of(true);}+ const { sheet, row, col } = editingCell;- if (getShouldDisableCellLink(target.worksheet, state.row, state.column)) {- return true;- }+ const isEditing$ = (editorBridgeService ? editorBridgeService.visible$ : of<Nullable<IEditorBridgeServiceVisibleParam>>(null))+ .pipe(map((visible) => visible?.visible ? DOCS_NORMAL_EDITOR_UNIT_ID_KEY : undefined));- return shouldDisableAddLink(accessor);+ return editorBridgeService ? isEditing$.pipe(mergeMap((editing) => (editing ? getZenLinkDisable$(accessor, editing) : of(getShouldDisableCellLink(sheet, row, col))))) : of(getShouldDisableCellLink(sheet, row, col));}));++ return disableRange$.pipe(mergeMap(((disableRange) => disableCell$.pipe(map((disableCell) => disableRange || disableCell)))));};const linkMenu = {diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsxindex fc75672b73..4f5d81b8e8 100644--- a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx@@ -229,8 +229,6 @@ export const CellLinkEdit = () => {}}, [type, isFocusRangeSelector, showLabel, editorBridgeService]);- const payloadInitial = useMemo(() => payload, [type]);-useEffect(() => {const render = editing?.type === HyperLinkEditSourceType.ZEN_EDITOR ?renderManagerService.getRenderById(DOCS_ZEN_EDITOR_UNIT_ID_KEY) :@@ -249,7 +247,7 @@ export const CellLinkEdit = () => {editorBridgeService.disableForceKeepVisible();disposeCollection.dispose();};- }, [editorBridgeService, renderManagerService]);+ }, [editing?.type, editorBridgeService, renderManagerService]);useEffect(() => {popupService.setIsKeepVisible(isFocusRangeSelector);@@ -472,7 +470,7 @@ export const CellLinkEdit = () => {subUnitId={subUnitId}isOnlyOneRangeisSupportAcrossSheet- initValue={payloadInitial}+ initValue={payload}onChange={handleRangeChange}isFocus={isFocusRangeSelector}onBlur={() => { isFocusRangeSelectorSet(false); }}diff --git a/packages/thread-comment/src/commands/mutations/comment.mutation.ts b/packages/thread-comment/src/commands/mutations/comment.mutation.tsindex 28c4021007..30119cba13 100644--- a/packages/thread-comment/src/commands/mutations/comment.mutation.ts+++ b/packages/thread-comment/src/commands/mutations/comment.mutation.ts@@ -15,8 +15,8 @@*/import type { ICommand, IDocumentBody } from '@univerjs/core';-import { CommandType } from '@univerjs/core';import type { IThreadComment } from '../../types/interfaces/i-thread-comment';+import { CommandType } from '@univerjs/core';import { ThreadCommentModel } from '../../models/thread-comment.model';export interface IAddCommentMutationParams {