diff --git a/mockdata/src/sheets/demo/default-workbook-data-demo.ts b/mockdata/src/sheets/demo/default-workbook-data-demo.ts index 0ef643cb62a..1b451590852 100644 --- a/mockdata/src/sheets/demo/default-workbook-data-demo.ts +++ b/mockdata/src/sheets/demo/default-workbook-data-demo.ts @@ -14287,6 +14287,114 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = { t: 1, }, }, + 25: { + 10: { + p: { + id: '__INTERNAL_EDITOR__ZEN_EDITOR', + documentStyle: { + pageSize: { + width: 37.2261962890625, + height: undefined, + }, + documentFlavor: 1, + marginTop: 0, + marginBottom: 2, + marginRight: 2, + marginLeft: 2, + renderConfig: { + horizontalAlign: 2, + verticalAlign: 0, + centerAngle: 0, + vertexAngle: 0, + wrapStrategy: 0, + }, + }, + drawings: {}, + drawingsOrder: [], + body: { + dataStream: '1\r\n', + textRuns: [], + paragraphs: [ + { + startIndex: 1, + paragraphStyle: { + horizontalAlign: 2, + }, + bullet: { + nestingLevel: 0, + textStyle: { + fs: 20, + }, + listType: 'CHECK_LIST_CHECKED', + listId: 'w6THUh', + }, + }, + ], + sectionBreaks: [ + { + startIndex: 2, + }, + ], + customRanges: [], + customDecorations: [], + }, + }, + s: 'idtqdi', + }, + 11: { + p: { + id: '__INTERNAL_EDITOR__ZEN_EDITOR', + documentStyle: { + pageSize: { + width: 37.2261962890625, + height: undefined, + }, + documentFlavor: 1, + marginTop: 0, + marginBottom: 2, + marginRight: 2, + marginLeft: 2, + renderConfig: { + horizontalAlign: 2, + verticalAlign: 0, + centerAngle: 0, + vertexAngle: 0, + wrapStrategy: 0, + }, + }, + drawings: {}, + drawingsOrder: [], + body: { + dataStream: '1\r\n', + textRuns: [], + paragraphs: [ + { + startIndex: 1, + paragraphStyle: { + horizontalAlign: 2, + }, + bullet: { + nestingLevel: 0, + textStyle: { + fs: 20, + }, + listType: 'CHECK_LIST', + listId: 'w6THUh', + }, + }, + ], + sectionBreaks: [ + { + startIndex: 2, + }, + ], + customRanges: [], + customDecorations: [], + }, + }, + s: 'idtqdi', + }, + }, }, freeze: { diff --git a/packages/sheets-ui/src/controllers/checkbox.controller.ts b/packages/sheets-ui/src/controllers/checkbox.controller.ts new file mode 100644 index 00000000000..9b8309aa5cf --- /dev/null +++ b/packages/sheets-ui/src/controllers/checkbox.controller.ts @@ -0,0 +1,69 @@ +/** + * Copyright 2023-present DreamNum Inc. + * + * 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 { Disposable, ICommandService, Inject, UniverInstanceType } from '@univerjs/core'; +import { CURSOR_TYPE, IRenderManagerService } from '@univerjs/engine-render'; +import { ToggleCellCheckboxCommand } from '@univerjs/sheets'; +import { HoverManagerService } from '../services/hover-manager.service'; + +export class SheetCheckboxController extends Disposable { + private _isPointer = false; + constructor( + @Inject(HoverManagerService) private _hoverManagerService: HoverManagerService, + @ICommandService private readonly _commandService: ICommandService, + @IRenderManagerService private readonly _renderManagerService: IRenderManagerService + ) { + super(); + this._initPointerEvent(); + this._initHover(); + } + + private get _mainComponent() { + return this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent; + } + + private _initHover() { + this.disposeWithMe(this._hoverManagerService.currentRichText$.subscribe((richText) => { + if (richText?.bullet) { + if (!this._isPointer) { + this._mainComponent?.setCursor(CURSOR_TYPE.POINTER); + } + this._isPointer = true; + } else { + if (this._isPointer) { + this._mainComponent?.setCursor(CURSOR_TYPE.AUTO); + } + this._isPointer = false; + } + })); + } + + private _initPointerEvent() { + this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe((cell) => { + const { location, bullet } = cell; + if (!bullet) { + return; + } + this._commandService.executeCommand(ToggleCellCheckboxCommand.id, { + unitId: location.unitId, + subUnitId: location.subUnitId, + row: location.row, + col: location.col, + paragraphIndex: bullet.startIndex, + }); + })); + } +} diff --git a/packages/sheets-ui/src/services/hover-manager.service.ts b/packages/sheets-ui/src/services/hover-manager.service.ts index ccefb120743..93fee7313e3 100644 --- a/packages/sheets-ui/src/services/hover-manager.service.ts +++ b/packages/sheets-ui/src/services/hover-manager.service.ts @@ -51,7 +51,7 @@ export interface IHoverRichTextPosition extends IHoverCellPosition { export class HoverManagerService extends Disposable { private _currentCell$ = new BehaviorSubject>(null); private _currentRichText$ = new BehaviorSubject>(null); - private _currentClickedCell$ = new Subject(); + private _currentClickedCell$ = new Subject(); // Notify when hovering over different cells currentCell$ = this._currentCell$.asObservable().pipe( @@ -163,6 +163,7 @@ export class HoverManagerService extends Disposable { if (font) { const { paddingLeft, paddingTop } = calcPadding(cell, font); const rects = calculateDocSkeletonRects(font.documentSkeleton, paddingLeft, paddingTop); + const innerX = offsetX - position.startX - leftOffset; const innerY = offsetY - position.startY - topOffset; customRange = rects.links.find((link) => link.rects.some((rect) => rect.left <= innerX && innerX <= rect.right && (rect.top) <= innerY && innerY <= (rect.bottom))); diff --git a/packages/sheets-ui/src/services/utils/doc-skeleton-util.ts b/packages/sheets-ui/src/services/utils/doc-skeleton-util.ts index dd7fb907373..a1e4aded74e 100644 --- a/packages/sheets-ui/src/services/utils/doc-skeleton-util.ts +++ b/packages/sheets-ui/src/services/utils/doc-skeleton-util.ts @@ -79,7 +79,7 @@ const calcDocGlyphPosition = (glyph: IDocumentSkeletonGlyph, skeleton: DocumentS top: rect.top, bottom: rect.bottom, left: rect.left, - right: rect.left, + right: rect.right, }; }; diff --git a/packages/sheets-ui/src/sheets-ui-plugin.ts b/packages/sheets-ui/src/sheets-ui-plugin.ts index 4b9f3af3806..03dacaf02d1 100644 --- a/packages/sheets-ui/src/sheets-ui-plugin.ts +++ b/packages/sheets-ui/src/sheets-ui-plugin.ts @@ -27,6 +27,7 @@ import { AutoFillController } from './controllers/auto-fill.controller'; import { AutoHeightController } from './controllers/auto-height.controller'; import { CellAlertRenderController } from './controllers/cell-alert.controller'; import { CellCustomRenderController } from './controllers/cell-custom-render.controller'; +import { SheetCheckboxController } from './controllers/checkbox.controller'; import { SheetClipboardController } from './controllers/clipboard/clipboard.controller'; import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema'; import { SheetsDefinedNameController } from './controllers/defined-name/defined-name.controller'; @@ -140,6 +141,7 @@ export class UniverSheetsUIPlugin extends Plugin { [AutoFillController], [FormatPainterController], [SheetsDefinedNameController], + [SheetCheckboxController], // permission [SheetPermissionPanelModel], @@ -181,6 +183,7 @@ export class UniverSheetsUIPlugin extends Plugin { [SheetsDefinedNameController], [StatusBarController], [AutoHeightController], + [SheetCheckboxController], ]); } diff --git a/packages/sheets/src/commands/commands/toggle-checkbox.command.ts b/packages/sheets/src/commands/commands/toggle-checkbox.command.ts index fee5e5a6f64..7517636313f 100644 --- a/packages/sheets/src/commands/commands/toggle-checkbox.command.ts +++ b/packages/sheets/src/commands/commands/toggle-checkbox.command.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import type { ICommand, Workbook } from '@univerjs/core'; -import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core'; +import type { ICommand, IMutationInfo, Workbook } from '@univerjs/core'; +import { BuildTextUtils, CellValueType, CommandType, DocumentDataModel, ICommandService, IUndoRedoService, IUniverInstanceService, TextX, Tools, UniverInstanceType } from '@univerjs/core'; +import { type ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; export interface IToggleCellCheckboxCommandParams { unitId: string; @@ -26,7 +27,7 @@ export interface IToggleCellCheckboxCommandParams { } export const ToggleCellCheckboxCommand: ICommand = { - id: 'toggle-cell-checkbox', + id: 'sheet.command.toggle-cell-checkbox', type: CommandType.COMMAND, handler: (accessor, params) => { if (!params) { @@ -36,6 +37,8 @@ export const ToggleCellCheckboxCommand: ICommand(unitId, UniverInstanceType.UNIVER_SHEET); const sheet = workbook?.getSheetBySheetId(subUnitId); + const undoRedoService = accessor.get(IUndoRedoService); + const commandService = accessor.get(ICommandService); if (!sheet) { return false; } @@ -43,7 +46,48 @@ export const ToggleCellCheckboxCommand: ICommand this.disposeWithMe(this._commandService.registerCommand(command))); } diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts index 1c82a9fae9b..3be4a88de1f 100644 --- a/packages/sheets/src/index.ts +++ b/packages/sheets/src/index.ts @@ -391,5 +391,5 @@ export { export { ScrollToCellOperation } from './commands/operations/scroll-to-cell.operation'; export { type ISetSelectionsOperationParams, SetSelectionsOperation } from './commands/operations/selection.operation'; export { type ISetWorksheetActiveOperationParams, SetWorksheetActiveOperation } from './commands/operations/set-worksheet-active.operation'; - +export { type IToggleCellCheckboxCommandParams, ToggleCellCheckboxCommand } from './commands/commands/toggle-checkbox.command'; // #endregion