Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
108 lines
4.0 KiB
TypeScript
108 lines
4.0 KiB
TypeScript
/**
|
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import type { ICommand } from '@univerjs/core';
|
|
import type { ISheetCommandSharedParams } from '@univerjs/sheets';
|
|
import { CommandType, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
import { getSheetCommandTarget, SheetsSelectionsService } from '@univerjs/sheets';
|
|
import { IEditorBridgeService } from '@univerjs/sheets-ui';
|
|
import { ISheetsHyperLinkPopupService } from '../../services/popup.service';
|
|
import { HyperLinkEditSourceType } from '../../types/enums/edit-source';
|
|
import { getShouldDisableCurrentCellLink } from '../../utils';
|
|
|
|
export interface IOpenHyperLinkEditPanelOperationParams extends ISheetCommandSharedParams {
|
|
row: number;
|
|
col: number;
|
|
customRangeId?: string;
|
|
type: HyperLinkEditSourceType;
|
|
}
|
|
|
|
export const OpenHyperLinkEditPanelOperation: ICommand<IOpenHyperLinkEditPanelOperationParams> = {
|
|
type: CommandType.OPERATION,
|
|
id: 'sheet.operation.open-hyper-link-edit-panel',
|
|
handler(accessor, params) {
|
|
if (!params) {
|
|
return false;
|
|
}
|
|
|
|
const popupService = accessor.get(ISheetsHyperLinkPopupService);
|
|
if (!params.customRangeId) {
|
|
popupService.startAddEditing(params);
|
|
} else {
|
|
popupService.startEditing(params as Required<IOpenHyperLinkEditPanelOperationParams>);
|
|
}
|
|
return true;
|
|
},
|
|
};
|
|
|
|
export const CloseHyperLinkPopupOperation: ICommand = {
|
|
type: CommandType.OPERATION,
|
|
id: 'sheet.operation.close-hyper-link-popup',
|
|
handler(accessor) {
|
|
const popupService = accessor.get(ISheetsHyperLinkPopupService);
|
|
|
|
popupService.endEditing();
|
|
return true;
|
|
},
|
|
};
|
|
|
|
export const InsertHyperLinkOperation: ICommand = {
|
|
type: CommandType.OPERATION,
|
|
id: 'sheet.operation.insert-hyper-link',
|
|
handler(accessor) {
|
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
const target = getSheetCommandTarget(univerInstanceService);
|
|
const editorBridgeService = accessor.get(IEditorBridgeService);
|
|
if (!target) {
|
|
return false;
|
|
}
|
|
const commandService = accessor.get(ICommandService);
|
|
const selectionManagerService = accessor.get(SheetsSelectionsService);
|
|
const selection = selectionManagerService.getCurrentLastSelection();
|
|
if (!selection) {
|
|
return false;
|
|
}
|
|
|
|
const row = selection.range.startRow;
|
|
const col = selection.range.startColumn;
|
|
const visible = editorBridgeService.isVisible();
|
|
return commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
|
|
unitId: target.unitId,
|
|
subUnitId: target.subUnitId,
|
|
row,
|
|
col,
|
|
type: visible.visible ? HyperLinkEditSourceType.EDITING : HyperLinkEditSourceType.VIEWING,
|
|
});
|
|
},
|
|
};
|
|
|
|
export const InsertHyperLinkToolbarOperation: ICommand = {
|
|
type: CommandType.OPERATION,
|
|
id: 'sheet.operation.insert-hyper-link-toolbar',
|
|
handler(accessor) {
|
|
if (getShouldDisableCurrentCellLink(accessor)) {
|
|
return false;
|
|
}
|
|
const commandService = accessor.get(ICommandService);
|
|
const popupService = accessor.get(ISheetsHyperLinkPopupService);
|
|
if (popupService.currentEditing) {
|
|
return commandService.executeCommand(CloseHyperLinkPopupOperation.id);
|
|
} else {
|
|
return commandService.executeCommand(InsertHyperLinkOperation.id);
|
|
}
|
|
},
|
|
};
|