diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.ts index 770df7651e0..e0be1249e73 100644 --- a/packages/core/src/sheets/worksheet.ts +++ b/packages/core/src/sheets/worksheet.ts @@ -121,6 +121,15 @@ export class Worksheet { return this._spanModel; } + getStyleDataByHash(hash: string): Nullable { + const data = this._styles.get(hash); + return { ...data }; + } + + setStyleData(style: IStyleData): Nullable { + return this._styles.setValue(style); + } + /** * Get the style of the column. * @param {number} column The column index diff --git a/packages/engine-formula/src/basics/date.ts b/packages/engine-formula/src/basics/date.ts index bac205af5f1..33a2a63a2de 100644 --- a/packages/engine-formula/src/basics/date.ts +++ b/packages/engine-formula/src/basics/date.ts @@ -257,7 +257,7 @@ export function countWorkingDays(startDateSerialNumber: number, endDateSerialNum workingDays++; } - return end > start ? workingDays : -workingDays; + return end >= start ? workingDays : -workingDays; } export function getDateSerialNumberByWorkingDays(startDateSerialNumber: number, workingDays: number, weekend: number | string = 1, holidays?: number[]): (number | ErrorValueObject) { diff --git a/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.ts index 98e83994631..9a0efbcd2a5 100644 --- a/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.ts @@ -16,12 +16,13 @@ import { describe, expect, it } from 'vitest'; +import { ErrorType } from '../../../../basics/error-type'; +import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object'; +import { ErrorValueObject } from '../../../../engine/value-object/base-value-object'; +import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object'; +import { getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_DATE } from '../../function-names'; import { NetworkdaysIntl } from '../index'; -import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object'; -import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object'; -import { ErrorValueObject } from '../../../../engine/value-object/base-value-object'; -import { ErrorType } from '../../../../basics/error-type'; describe('Test networkdays.intl function', () => { const testFunction = new NetworkdaysIntl(FUNCTION_NAMES_DATE.NETWORKDAYS); @@ -31,12 +32,12 @@ describe('Test networkdays.intl function', () => { const startDate = StringValueObject.create('2012-10-1'); const endDate = StringValueObject.create('2013-3-1'); const result = testFunction.calculate(startDate, endDate); - expect(result.getValue()).toStrictEqual(110); + expect(getObjectValue(result)).toStrictEqual(110); const weekend2 = NumberValueObject.create(6); const holidays2 = StringValueObject.create('2012-11-22'); const result2 = testFunction.calculate(startDate, endDate, weekend2, holidays2); - expect(result2.getValue()).toStrictEqual(108); + expect(getObjectValue(result2)).toStrictEqual(108); const weekend3 = StringValueObject.create('0011001'); const holidays3 = ArrayValueObject.create({ @@ -53,114 +54,114 @@ describe('Test networkdays.intl function', () => { column: 0, }); const result3 = testFunction.calculate(startDate, endDate, weekend3, holidays3); - expect(result3.getValue()).toStrictEqual(85); + expect(getObjectValue(result3)).toStrictEqual(85); }); it('Value is number or date string', () => { const startDate = NumberValueObject.create(45122); const endDate = StringValueObject.create('2013-3-1'); const result = testFunction.calculate(startDate, endDate); - expect(result.getValue()).toStrictEqual(-2706); + expect(getObjectValue(result)).toStrictEqual(-2706); }); it('Value is not date string', () => { const startDate = StringValueObject.create('test'); const endDate = StringValueObject.create('2013-3-1'); const result = testFunction.calculate(startDate, endDate); - expect(result.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE); const startDate2 = StringValueObject.create('2012-10-1'); const endDate2 = StringValueObject.create('test'); const result2 = testFunction.calculate(startDate2, endDate2); - expect(result2.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE); const startDate3 = StringValueObject.create('2012-10-1'); const endDate3 = StringValueObject.create('2013-3-1'); const weekend3 = StringValueObject.create('test'); const result3 = testFunction.calculate(startDate3, endDate3, weekend3); - expect(result3.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE); const startDate4 = StringValueObject.create('2012-10-1'); const endDate4 = StringValueObject.create('2013-3-1'); const weekend4 = StringValueObject.create('1110001'); const holidays4 = StringValueObject.create('test'); const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4); - expect(result4.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE); }); it('Value is blank cell', () => { const startDate = NullValueObject.create(); const endDate = StringValueObject.create('2013-3-1'); const result = testFunction.calculate(startDate, endDate); - expect(result.getValue()).toStrictEqual(29525); + expect(getObjectValue(result)).toStrictEqual(29525); const startDate2 = StringValueObject.create('2012-10-1'); const endDate2 = NullValueObject.create(); const result2 = testFunction.calculate(startDate2, endDate2); - expect(result2.getValue()).toStrictEqual(-29416); + expect(getObjectValue(result2)).toStrictEqual(-29416); const startDate3 = StringValueObject.create('2012-10-1'); const endDate3 = StringValueObject.create('2013-3-1'); const weekend3 = NullValueObject.create(); const result3 = testFunction.calculate(startDate3, endDate3, weekend3); - expect(result3.getValue()).toStrictEqual(ErrorType.NUM); + expect(getObjectValue(result3)).toStrictEqual(ErrorType.NUM); const startDate4 = StringValueObject.create('2012-10-1'); const endDate4 = StringValueObject.create('2013-3-1'); const weekend4 = NumberValueObject.create(5); const holidays4 = NullValueObject.create(); const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4); - expect(result4.getValue()).toStrictEqual(108); + expect(getObjectValue(result4)).toStrictEqual(108); }); it('Value is boolean', () => { const startDate = BooleanValueObject.create(true); const endDate = StringValueObject.create('2013-3-1'); const result = testFunction.calculate(startDate, endDate); - expect(result.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE); const startDate2 = StringValueObject.create('2012-10-1'); const endDate2 = BooleanValueObject.create(false); const result2 = testFunction.calculate(startDate2, endDate2); - expect(result2.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE); const startDate3 = StringValueObject.create('2012-10-1'); const endDate3 = StringValueObject.create('2013-3-1'); const weekend3 = BooleanValueObject.create(true); const result3 = testFunction.calculate(startDate3, endDate3, weekend3); - expect(result3.getValue()).toStrictEqual(110); + expect(getObjectValue(result3)).toStrictEqual(110); const startDate4 = StringValueObject.create('2012-10-1'); const endDate4 = StringValueObject.create('2013-3-1'); const weekend4 = NumberValueObject.create(1); const holidays4 = BooleanValueObject.create(true); const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4); - expect(result4.getValue()).toStrictEqual(ErrorType.VALUE); + expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE); }); it('Value is error', () => { const startDate = ErrorValueObject.create(ErrorType.NAME); const endDate = StringValueObject.create('2013-3-1'); const result = testFunction.calculate(startDate, endDate); - expect(result.getValue()).toStrictEqual(ErrorType.NAME); + expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME); const startDate2 = StringValueObject.create('2012-10-1'); const endDate2 = ErrorValueObject.create(ErrorType.NAME); const result2 = testFunction.calculate(startDate2, endDate2); - expect(result2.getValue()).toStrictEqual(ErrorType.NAME); + expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME); const startDate3 = StringValueObject.create('2012-10-1'); const endDate3 = StringValueObject.create('2013-3-1'); const weekend3 = ErrorValueObject.create(ErrorType.NAME); const result3 = testFunction.calculate(startDate3, endDate3, weekend3); - expect(result3.getValue()).toStrictEqual(ErrorType.NAME); + expect(getObjectValue(result3)).toStrictEqual(ErrorType.NAME); const startDate4 = StringValueObject.create('2012-10-1'); const endDate4 = StringValueObject.create('2013-3-1'); const weekend4 = NumberValueObject.create(1); const holidays4 = ErrorValueObject.create(ErrorType.NAME); const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4); - expect(result4.getValue()).toStrictEqual(ErrorType.NAME); + expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME); }); it('Weekend value is array', () => { @@ -194,12 +195,29 @@ describe('Test networkdays.intl function', () => { column: 0, }); const result = testFunction.calculate(startDate, endDate, weekend, holidays); - expect(transformToValue(result.getArrayValue())).toStrictEqual([ + expect(getObjectValue(result)).toStrictEqual([ [107, ErrorType.NUM, ErrorType.NUM], [ErrorType.VALUE, ErrorType.NUM, ErrorType.NUM], [106, ErrorType.NUM, ErrorType.NUM], [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM], ]); }); + + it('More test', () => { + const startDate = StringValueObject.create('2024-11-25'); + const endDate = StringValueObject.create('2024-11-25'); + const result = testFunction.calculate(startDate, endDate); + expect(getObjectValue(result)).toBe(1); + + const startDate2 = StringValueObject.create('2024-11-24'); + const endDate2 = StringValueObject.create('2024-11-25'); + const result2 = testFunction.calculate(startDate2, endDate2); + expect(getObjectValue(result2)).toBe(1); + + const startDate3 = StringValueObject.create('2024-11-25'); + const endDate3 = StringValueObject.create('2024-11-26'); + const result3 = testFunction.calculate(startDate3, endDate3); + expect(getObjectValue(result3)).toBe(2); + }); }); }); diff --git a/packages/sheets-data-validation-ui/src/controllers/dv-auto-fill.controller.ts b/packages/sheets-data-validation-ui/src/controllers/dv-auto-fill.controller.ts index 0535e65f8a7..65bef57f0d0 100644 --- a/packages/sheets-data-validation-ui/src/controllers/dv-auto-fill.controller.ts +++ b/packages/sheets-data-validation-ui/src/controllers/dv-auto-fill.controller.ts @@ -24,7 +24,7 @@ import { APPLY_TYPE, getAutoFillRepeatRange, IAutoFillService, virtualizeDiscret export class DataValidationAutoFillController extends Disposable { constructor( @IAutoFillService private readonly _autoFillService: IAutoFillService, - @Inject(SheetDataValidationModel) private readonly _dataValidationModel: SheetDataValidationModel, + @Inject(SheetDataValidationModel) private readonly _sheetDataValidationModel: SheetDataValidationModel, @Inject(Injector) private readonly _injector: Injector ) { super(); @@ -37,7 +37,7 @@ export class DataValidationAutoFillController extends Disposable { const generalApplyFunc = (location: IAutoFillLocation, applyType: APPLY_TYPE) => { const { source: sourceRange, target: targetRange, unitId, subUnitId } = location; - const ruleMatrixCopy = this._dataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone(); + const ruleMatrixCopy = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone(); const virtualRange = virtualizeDiscreteRanges([sourceRange, targetRange]); const [vSourceRange, vTargetRange] = virtualRange.ranges; @@ -75,27 +75,26 @@ export class DataValidationAutoFillController extends Disposable { sourceRange ); const { row: sourceRow, col: sourceCol } = mapFunc(sourcePositionRange.startRow, sourcePositionRange.startColumn); - const ruleId = this._dataValidationModel.getRuleIdByLocation(unitId, subUnitId, sourceRow, sourceCol); - if (ruleId) { - const targetPositionRange = Rectangle.getPositionRange( - { - startRow: row, - startColumn: col, - endColumn: col, - endRow: row, - }, - targetRange - ); - const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn); + // if ruleId exists, set more dv rules, if not, clear dv rules. + const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, sourceRow, sourceCol) || ''; + const targetPositionRange = Rectangle.getPositionRange( + { + startRow: row, + startColumn: col, + endColumn: col, + endRow: row, + }, + targetRange + ); + const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn); - additionMatrix.setValue(targetRow, targetCol, ruleId); - additionRules.add(ruleId); - } + additionMatrix.setValue(targetRow, targetCol, ruleId); + additionRules.add(ruleId); }); }); const additions = Array.from(additionRules).map((id) => ({ id, ranges: queryObjectMatrix(additionMatrix, (value) => value === id) })); ruleMatrixCopy.addRangeRules(additions); - const diffs = ruleMatrixCopy.diff(this._dataValidationModel.getRules(unitId, subUnitId)); + const diffs = ruleMatrixCopy.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)); const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, 'patched', applyType === APPLY_TYPE.ONLY_FORMAT); return { undos: undoMutations, @@ -111,7 +110,7 @@ export class DataValidationAutoFillController extends Disposable { const { source: sourceRange, unitId, subUnitId } = location; for (const row of sourceRange.rows) { for (const col of sourceRange.cols) { - const dv = this._dataValidationModel.getRuleByLocation(unitId, subUnitId, row, col); + const dv = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col); if (dv && disabledDataVallation.indexOf(dv.type) > -1) { this._autoFillService.setDisableApplyType(APPLY_TYPE.SERIES, true); return; diff --git a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts index c5d4c5ece3f..4f4c6d6c6a5 100644 --- a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts +++ b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts @@ -159,6 +159,34 @@ export function getDataValidationDiffMutations( }, } as IUpdateDataValidationMutationParams, }); + } else { + redoMutations.push({ + id: UpdateDataValidationMutation.id, + params: { + unitId, + subUnitId, + ruleId: diff.ruleId, + payload: { + type: UpdateRuleType.RANGE, + payload: diff.newRanges, + }, + source, + } as IUpdateDataValidationMutationParams, + }); + + undoMutations.unshift({ + id: UpdateDataValidationMutation.id, + params: { + unitId, + subUnitId, + ruleId: diff.ruleId, + payload: { + type: UpdateRuleType.RANGE, + payload: diff.oldRanges, + }, + source, + } as IUpdateDataValidationMutationParams, + }); } } else { redoMutations.push({ diff --git a/packages/sheets-data-validation/src/utils/formula.ts b/packages/sheets-data-validation/src/utils/formula.ts index 72ae10b038c..ffd87963b49 100644 --- a/packages/sheets-data-validation/src/utils/formula.ts +++ b/packages/sheets-data-validation/src/utils/formula.ts @@ -33,5 +33,13 @@ export function isLegalFormulaResult(res: string) { * Judge if the data-validation's formula need to be offseted by ranges */ export function isCustomFormulaType(type: DataValidationType) { - return type !== DataValidationType.LIST && type !== DataValidationType.LIST_MULTIPLE && type !== DataValidationType.CHECKBOX && type !== DataValidationType.ANY; + // types not in this list is formula type + const invalidTypes = [ + DataValidationType.LIST, + DataValidationType.LIST_MULTIPLE, + DataValidationType.CHECKBOX, + DataValidationType.ANY, + ]; + + return !invalidTypes.includes(type); } diff --git a/packages/sheets-formula-ui/src/controllers/prompt.controller.ts b/packages/sheets-formula-ui/src/controllers/prompt.controller.ts index a5a3df46c14..4ae77684e71 100644 --- a/packages/sheets-formula-ui/src/controllers/prompt.controller.ts +++ b/packages/sheets-formula-ui/src/controllers/prompt.controller.ts @@ -935,9 +935,7 @@ export class PromptController extends Disposable { const refSelections: IRefSelection[] = []; const themeColorMap = new Map(); let refColorIndex = 0; - const offset = this._getCurrentBodyDataStreamAndOffset()?.offset || 0; - for (let i = 0, len = sequenceNodes.length; i < len; i++) { const node = sequenceNodes[i]; if (typeof node === 'string' || this._descriptionService.hasDefinedNameDescription(node.token.trim())) { @@ -1002,6 +1000,7 @@ export class PromptController extends Disposable { * Draw the referenced selection text based on the style and token. * @param refSelections */ + private _refreshSelectionForReference(refSelectionRenderService: RefSelectionsRenderService, refSelections: IRefSelection[]) { // const [unitId, sheetId] = refSelectionRenderService.getLocation(); const { unitId, sheetId } = this._editorBridgeService.getEditCellState()!; @@ -1028,28 +1027,23 @@ export class PromptController extends Disposable { */ const range = setEndForRange(rawRange, worksheet.getRowCount(), worksheet.getColumnCount()); - if (refUnitId != null && refUnitId.length > 0 && unitId !== refUnitId) { - continue; - } + if (refUnitId != null && refUnitId.length > 0 && unitId !== refUnitId) continue; // sheet name is designed to be unique. const refSheetId = this._getSheetIdByName(unitId, sheetName.trim()); - if (!isSelfSheet && refSheetId !== selfSheetId) { // Cross sheet operation - continue; - } + // Cross sheet operation + if (!isSelfSheet && refSheetId !== selfSheetId) continue; - if (isSelfSheet && sheetName.length !== 0 && refSheetId !== sheetId) { // Current sheet operation - continue; - } + // Current sheet operation + if (isSelfSheet && sheetName.length !== 0 && refSheetId !== sheetId) continue; - if (this._exceedCurrentRange(range, worksheet.getRowCount(), worksheet.getColumnCount())) { - continue; - } + if (this._exceedCurrentRange(range, worksheet.getRowCount(), worksheet.getColumnCount())) continue; const lastRangeCopy = this._getPrimary(range, themeColor, refIndex); if (lastRangeCopy) { lastRange = lastRangeCopy; + selectionWithStyle.push(lastRange); continue; } @@ -1073,9 +1067,10 @@ export class PromptController extends Disposable { }); } - if (lastRange) { - selectionWithStyle.push(lastRange); - } + // why add lastRange after all? that would changes selection sequence !!! why ??? + // if (lastRange) { + // selectionWithStyle.push(lastRange); + // } if (selectionWithStyle.length) { this._refSelectionsService.addSelections(unitId, sheetId, selectionWithStyle); @@ -1083,7 +1078,7 @@ export class PromptController extends Disposable { } private _getPrimary(range: IRange, themeColor: string, refIndex: number) { - const primary = this._insertSelections.find((selection) => { + const matchedInsertSelection = this._insertSelections.find((selection) => { const { startRow, startColumn, endRow, endColumn } = selection.range; if ( startRow === range.startRow && @@ -1103,9 +1098,9 @@ export class PromptController extends Disposable { } return false; - })?.primary; + }); - if (primary == null) { + if (matchedInsertSelection?.primary == null) { return; } @@ -1116,7 +1111,7 @@ export class PromptController extends Disposable { endRow: mergeEndRow, startColumn: mergeStartColumn, endColumn: mergeEndColumn, - } = primary; + } = matchedInsertSelection.primary; if ( (isMerged || isMergedMainCell) && @@ -1131,7 +1126,7 @@ export class PromptController extends Disposable { return { range, - primary, + primary: matchedInsertSelection.primary, style: genFormulaRefSelectionStyle(this._themeService, themeColor, refIndex.toString()), }; } @@ -1411,21 +1406,21 @@ export class PromptController extends Disposable { } const refString = this._generateRefString(currentSelection); - this._formulaPromptService.setSequenceNodes(insertNodes); - this._formulaPromptService.insertSequenceRef(this._previousInsertRefStringIndex, refString); - this._syncToEditor(insertNodes, this._previousInsertRefStringIndex + refString.length); - - const selectionDatas = this._selectionRenderService.getSelectionDataWithStyle(); - + const selectionsWithStyle = this._selectionRenderService.getSelectionDataWithStyle() || []; this._insertSelections = []; - selectionDatas.forEach((currentSelection) => { - const range = convertSelectionDataToRange(currentSelection); + // selectionsWithStyle.forEach((currentSelection) => { + // const range = convertSelectionDataToRange(currentSelection); + // this._insertSelections.push(range); + // }); + const lastSelectionWithStyle = selectionsWithStyle[selectionsWithStyle.length - 1]; + if (lastSelectionWithStyle) { + const range = convertSelectionDataToRange(lastSelectionWithStyle); this._insertSelections.push(range); - }); + } } /** diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts index 120f91fd3d3..7b2fb49b7a1 100644 --- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts +++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts @@ -22,7 +22,8 @@ import type { IExecutionInProgressParams, IFormulaDirtyData, ISetFormulaCalculationNotificationMutation, - ISetFormulaCalculationStartMutation } from '@univerjs/engine-formula'; + ISetFormulaCalculationStartMutation, +} from '@univerjs/engine-formula'; import type { ISetRangeValuesMutationParams } from '@univerjs/sheets'; import type { IUniverSheetsFormulaBaseConfig } from './config.schema'; import { Disposable, ICommandService, IConfigService, ILogService, Inject, LocaleService } from '@univerjs/core'; @@ -33,7 +34,8 @@ import { IActiveDirtyManagerService, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, - SetFormulaCalculationStopMutation } from '@univerjs/engine-formula'; + SetFormulaCalculationStopMutation, +} from '@univerjs/engine-formula'; import { ClearSelectionFormatCommand, SetBorderCommand, @@ -301,9 +303,9 @@ export class TriggerCalculationController extends Disposable { const { startRow: existingStartRow, startColumn: existingStartColumn, endRow: existingEndRow, endColumn: existingEndColumn } = existingRange.range; if ( startRow === existingStartRow && - startColumn === existingStartColumn && - endRow === existingEndRow && - endColumn === existingEndColumn + startColumn === existingStartColumn && + endRow === existingEndRow && + endColumn === existingEndColumn ) { isDuplicate = true; break; @@ -366,31 +368,6 @@ export class TriggerCalculationController extends Disposable { if (forceCalculation) { this._forceCalculating = true; } - - // In NO_CALCULATION mode, the following processes will not be triggered, so there is no need to start - if (this._calculationMode === CalculationMode.NO_CALCULATION) { - return; - } - - // When calculations are started multiple times in succession, only the first time is recognized - if (calculationProcessCount === 0) { - this._startExecutionTime = performance.now(); - } - - // Increment the calculation process count and assign a new ID - calculationProcessCount++; - - // Clear any existing timer to prevent duplicate executions - if (startDependencyTimer !== null) { - clearTimeout(startDependencyTimer); - startDependencyTimer = null; - } - - // If the total calculation time exceeds 1s, a progress bar is displayed. - startDependencyTimer = setTimeout(() => { - startDependencyTimer = null; - this._startProgress(); - }, 1000); } else if (command.id === SetFormulaCalculationStopMutation.id) { this.clearProgress(); } @@ -406,7 +383,32 @@ export class TriggerCalculationController extends Disposable { stage, } = params.stageInfo; - if (stage === FormulaExecuteStageType.CURRENTLY_CALCULATING) { + if (stage === FormulaExecuteStageType.START) { + // In NO_CALCULATION mode, the following processes will not be triggered, so there is no need to start + if (this._calculationMode === CalculationMode.NO_CALCULATION) { + return; + } + + // When calculations are started multiple times in succession, only the first time is recognized + if (calculationProcessCount === 0) { + this._startExecutionTime = performance.now(); + } + + // Increment the calculation process count and assign a new ID + calculationProcessCount++; + + // Clear any existing timer to prevent duplicate executions + if (startDependencyTimer !== null) { + clearTimeout(startDependencyTimer); + startDependencyTimer = null; + } + + // If the total calculation time exceeds 1s, a progress bar is displayed. + startDependencyTimer = setTimeout(() => { + startDependencyTimer = null; + this._startProgress(); + }, 1000); + } else if (stage === FormulaExecuteStageType.CURRENTLY_CALCULATING) { this._executionInProgressParams = params.stageInfo; if (startDependencyTimer === null) { diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts index ac93b15abfe..38dc2f63f88 100644 --- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts +++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts @@ -14,6 +14,22 @@ * limitations under the License. */ +import type { + ICellData, IDisposable, + IMutationInfo, + IRange, + Nullable, Workbook, Worksheet, +} from '@univerjs/core'; +import type { ISetSelectionsOperationParams } from '@univerjs/sheets'; +import type { IDiscreteRange } from '../../controllers/utils/range-tools'; +import type { + ICellDataWithSpanInfo, + IClipboardPropertyItem, + IPasteTarget, + ISheetClipboardHook, + ISheetDiscreteRangeLocation, + IUniverSheetCopyDataModel, +} from './type'; import { createIdentifier, Disposable, ErrorService, extractPureTextFromCell, ICommandService, ILogService, @@ -29,6 +45,7 @@ import { UniverInstanceType, } from '@univerjs/core'; import { IRenderManagerService } from '@univerjs/engine-render'; + import { getPrimaryForRange, SetSelectionsOperation, @@ -36,36 +53,19 @@ import { } from '@univerjs/sheets'; import { HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, INotificationService, IPlatformService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE } from '@univerjs/ui'; import { BehaviorSubject } from 'rxjs'; -import type { - ICellData, IDisposable, - IMutationInfo, - IRange, - Nullable, Workbook, Worksheet, -} from '@univerjs/core'; - -import type { ISetSelectionsOperationParams } from '@univerjs/sheets'; import { rangeToDiscreteRange, virtualizeDiscreteRanges } from '../../controllers/utils/range-tools'; import { IMarkSelectionService } from '../mark-selection/mark-selection.service'; import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service'; import { createCopyPasteSelectionStyle } from '../utils/selection-util'; import { CopyContentCache, extractId, genId } from './copy-content-cache'; + import { HtmlToUSMService } from './html-to-usm/converter'; import { LarkPastePlugin } from './html-to-usm/paste-plugins/plugin-lark'; - import { UniverPastePlugin } from './html-to-usm/paste-plugins/plugin-univer'; import { WordPastePlugin } from './html-to-usm/paste-plugins/plugin-word'; import { COPY_TYPE } from './type'; import { USMToHtmlService } from './usm-to-html/convertor'; import { clipboardItemIsFromExcel, convertTextToTable, discreteRangeContainsRange, mergeSetRangeValues, rangeIntersectWithDiscreteRange } from './utils'; -import type { IDiscreteRange } from '../../controllers/utils/range-tools'; -import type { - ICellDataWithSpanInfo, - IClipboardPropertyItem, - IPasteTarget, - ISheetClipboardHook, - ISheetDiscreteRangeLocation, - IUniverSheetCopyDataModel, -} from './type'; export const PREDEFINED_HOOK_NAME = { DEFAULT_COPY: 'default-copy', diff --git a/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts index d49cf488294..0d140256f33 100644 --- a/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts @@ -15,6 +15,7 @@ */ import type { ICellData, Injector, IRange, IStyleData, Nullable, Univer } from '@univerjs/core'; +import type { ISetRangeValuesCommandParams } from '../set-range-values.command'; import { CellValueType, ICommandService, @@ -23,11 +24,11 @@ import { RedoCommand, UndoCommand, } from '@univerjs/core'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { MergeCellController } from '../../../controllers/merge-cell.controller'; import { RefRangeService } from '../../../services/ref-range/ref-range.service'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation'; import { RemoveWorksheetMergeMutation } from '../../mutations/remove-worksheet-merge.mutation'; import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation'; @@ -35,7 +36,6 @@ import { AddWorksheetMergeAllCommand, AddWorksheetMergeCommand } from '../add-wo import { ClearSelectionAllCommand } from '../clear-selection-all.command'; import { ClearSelectionContentCommand } from '../clear-selection-content.command'; import { ClearSelectionFormatCommand } from '../clear-selection-format.command'; -import type { ISetRangeValuesCommandParams } from '../set-range-values.command'; import { SetRangeValuesCommand } from '../set-range-values.command'; import { createCommandTestBed } from './create-command-test-bed'; @@ -201,7 +201,8 @@ describe('Test clear selection content commands', () => { return get(IUniverInstanceService) .getUniverSheetInstance('test') ?.getSheetBySheetId('sheet1') - ?.getConfig().mergeData; + ?.getConfig() + .mergeData; } // set formats @@ -343,7 +344,8 @@ describe('Test clear selection content commands', () => { return get(IUniverInstanceService) .getUniverSheetInstance('test') ?.getSheetBySheetId('sheet1') - ?.getConfig().mergeData; + ?.getConfig() + .mergeData; } // set formats diff --git a/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts b/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts index 56c0623024b..36ef67372f8 100644 --- a/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts +++ b/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts @@ -35,7 +35,7 @@ import { BorderStyleManagerService } from '../../../services/border-style-manage import { WorkbookPermissionService } from '../../../services/permission/workbook-permission/workbook-permission.service'; import { WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '../../../services/permission/worksheet-permission'; import { WorksheetPermissionService } from '../../../services/permission/worksheet-permission/worksheet-permission.service'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { SheetInterceptorService } from '../../../services/sheet-interceptor/sheet-interceptor.service'; const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = { diff --git a/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts index e9f60ab0ffc..221ce8ef4b8 100644 --- a/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts @@ -26,7 +26,7 @@ import { } from '@univerjs/core'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation'; import { InsertColMutation, InsertRowMutation } from '../../mutations/insert-row-col.mutation'; import { MoveRangeMutation } from '../../mutations/move-range.mutation'; diff --git a/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts index 37ad45d3fcf..4e10ab39d86 100644 --- a/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer } from '@univerjs/core'; import { ICommandService, IUniverInstanceService, @@ -25,11 +26,10 @@ import { UndoCommand, } from '@univerjs/core'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer } from '@univerjs/core'; import { MergeCellController } from '../../../controllers/merge-cell.controller'; import { RefRangeService } from '../../../services/ref-range/ref-range.service'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation'; import { InsertColMutation, InsertRowMutation } from '../../mutations/insert-row-col.mutation'; import { MoveRangeMutation } from '../../mutations/move-range.mutation'; diff --git a/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts index 91eb33a86a5..041f0adbf2c 100644 --- a/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts @@ -15,6 +15,7 @@ */ import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core'; +import type { IRemoveRowColCommandParams } from '../remove-row-col.command'; import { ICommandService, IUniverInstanceService, @@ -25,11 +26,11 @@ import { UndoCommand, UniverInstanceType, } from '@univerjs/core'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { MergeCellController } from '../../../controllers/merge-cell.controller'; import { RefRangeService } from '../../../services/ref-range/ref-range.service'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation'; import { InsertColMutation, InsertRowMutation } from '../../mutations/insert-row-col.mutation'; import { MoveRangeMutation } from '../../mutations/move-range.mutation'; @@ -45,7 +46,6 @@ import { InsertRowBeforeCommand, InsertRowCommand, } from '../insert-row-col.command'; -import type { IRemoveRowColCommandParams } from '../remove-row-col.command'; import { RemoveColCommand, RemoveRowCommand } from '../remove-row-col.command'; import { createCommandTestBed } from './create-command-test-bed'; diff --git a/packages/sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts index 20ed86b43b1..47b8d55c7d2 100644 --- a/packages/sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts @@ -15,6 +15,7 @@ */ import type { ICellData, Injector, IRange, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core'; +import type { IMoveColsCommandParams, IMoveRowsCommandParams } from '../move-rows-cols.command'; import { cellToRange, ICommandService, @@ -26,16 +27,15 @@ import { UndoCommand, UniverInstanceType, } from '@univerjs/core'; -import { beforeEach, describe, expect, it } from 'vitest'; +import { beforeEach, describe, expect, it } from 'vitest'; import { MergeCellController } from '../../../controllers/merge-cell.controller'; import { RefRangeService } from '../../../services/ref-range/ref-range.service'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation'; import { MoveColsMutation, MoveRowsMutation } from '../../mutations/move-rows-cols.mutation'; import { RemoveWorksheetMergeMutation } from '../../mutations/remove-worksheet-merge.mutation'; import { SetSelectionsOperation } from '../../operations/selection.operation'; -import type { IMoveColsCommandParams, IMoveRowsCommandParams } from '../move-rows-cols.command'; import { MoveColsCommand, MoveRowsCommand } from '../move-rows-cols.command'; import { createCommandTestBed } from './create-command-test-bed'; diff --git a/packages/sheets/src/commands/commands/__tests__/remove-rows-cols.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/remove-rows-cols.command.spec.ts index f09c1e8fd7a..40aa2a9b1bd 100644 --- a/packages/sheets/src/commands/commands/__tests__/remove-rows-cols.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/remove-rows-cols.command.spec.ts @@ -15,6 +15,7 @@ */ import type { ICellData, Injector, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core'; +import type { IRemoveRowColCommandParams } from '../remove-row-col.command'; import { ICommandService, IUniverInstanceService, @@ -25,17 +26,16 @@ import { UndoCommand, UniverInstanceType, } from '@univerjs/core'; -import { beforeEach, describe, expect, it } from 'vitest'; +import { beforeEach, describe, expect, it } from 'vitest'; import { MergeCellController } from '../../../controllers/merge-cell.controller'; import { RefRangeService } from '../../../services/ref-range/ref-range.service'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; -import { SetSelectionsOperation } from '../../operations/selection.operation'; -import type { IRemoveRowColCommandParams } from '../remove-row-col.command'; -import { RemoveColCommand, RemoveRowCommand } from '../remove-row-col.command'; -import { RemoveColMutation, RemoveRowMutation } from '../../mutations/remove-row-col.mutation'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { InsertColMutation, InsertRowMutation } from '../../mutations/insert-row-col.mutation'; +import { RemoveColMutation, RemoveRowMutation } from '../../mutations/remove-row-col.mutation'; import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation'; +import { SetSelectionsOperation } from '../../operations/selection.operation'; +import { RemoveColCommand, RemoveRowCommand } from '../remove-row-col.command'; import { createCommandTestBed } from './create-command-test-bed'; describe('Test remove rows cols', () => { diff --git a/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts index 86b91bde959..98ab9061f0e 100644 --- a/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts @@ -14,11 +14,11 @@ * limitations under the License. */ +import type { IBorderData, Injector, IRange, Univer } from '@univerjs/core'; import { BorderStyleTypes, BorderType, ICommandService, IUniverInstanceService, RANGE_TYPE } from '@univerjs/core'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import type { IBorderData, Injector, IRange, Univer } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation'; import { RemoveWorksheetMergeMutation } from '../../mutations/remove-worksheet-merge.mutation'; import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation'; diff --git a/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts index ce781e9bcb2..122f59ee935 100644 --- a/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts @@ -15,12 +15,12 @@ */ import type { Injector, Univer, Workbook } from '@univerjs/core'; +import type { IDeltaColumnWidthCommandParams, ISetColWidthCommandParams } from '../set-worksheet-col-width.command'; import { ICommandService, IUniverInstanceService, RANGE_TYPE, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { SetWorksheetColWidthMutation } from '../../mutations/set-worksheet-col-width.mutation'; -import type { IDeltaColumnWidthCommandParams, ISetColWidthCommandParams } from '../set-worksheet-col-width.command'; import { DeltaColumnWidthCommand, SetColWidthCommand } from '../set-worksheet-col-width.command'; import { createCommandTestBed } from './create-command-test-bed'; diff --git a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts index 3fc9b53e61c..56b9628c22d 100644 --- a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts @@ -30,7 +30,7 @@ import { } from '@univerjs/core'; import { DEFAULT_TEXT_FORMAT } from '@univerjs/engine-numfmt'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation'; import { SetRangeValuesCommand } from '../set-range-values.command'; import { createCommandTestBed } from './create-command-test-bed'; diff --git a/packages/sheets/src/commands/commands/__tests__/set-row-col-visible.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-row-col-visible.command.spec.ts index 849769126b9..62daaead4ea 100644 --- a/packages/sheets/src/commands/commands/__tests__/set-row-col-visible.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/set-row-col-visible.command.spec.ts @@ -18,7 +18,7 @@ import type { Injector, Univer, Workbook } from '@univerjs/core'; import { ICommandService, IUniverInstanceService, RANGE_TYPE, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { SetColHiddenMutation, SetColVisibleMutation } from '../../mutations/set-col-visible.mutation'; import { SetRowHiddenMutation, SetRowVisibleMutation } from '../../mutations/set-row-visible.mutation'; import { SetSelectionsOperation } from '../../operations/selection.operation'; diff --git a/packages/sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts index 9037efdace4..f2f18dd0f2b 100644 --- a/packages/sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts @@ -15,6 +15,7 @@ */ import type { Injector, Nullable, Univer, Workbook } from '@univerjs/core'; +import type { IDeltaRowHeightCommand, ISetRowHeightCommandParams } from '../set-worksheet-row-height.command'; import { BooleanNumber, ICommandService, @@ -24,14 +25,13 @@ import { UndoCommand, UniverInstanceType, } from '@univerjs/core'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, } from '../../mutations/set-worksheet-row-height.mutation'; -import type { IDeltaRowHeightCommand, ISetRowHeightCommandParams } from '../set-worksheet-row-height.command'; import { DeltaRowHeightCommand, SetRowHeightCommand, diff --git a/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts index c3d8a684882..52548647fff 100644 --- a/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts +++ b/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts @@ -32,7 +32,7 @@ import { } from '@univerjs/core'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { SheetsSelectionsService } from '../../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../../services/selections/selection.service'; import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation'; import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation'; import { InsertSheetCommand } from '../insert-sheet.command'; diff --git a/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts b/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts index 18a7193e514..15387ee8f20 100644 --- a/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts +++ b/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts @@ -15,6 +15,12 @@ */ import type { IAccessor, ICellData, ICommand, IMutationInfo, Injector, IRange, Nullable, Workbook, Worksheet } from '@univerjs/core'; +import type { + IAddWorksheetMergeMutationParams, + IRemoveWorksheetMergeMutationParams, +} from '../../basics/interfaces/mutation-interface'; + +import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; import { CommandType, Dimension, @@ -26,19 +32,13 @@ import { sequenceExecute, UniverInstanceType, } from '@univerjs/core'; - -import type { - IAddWorksheetMergeMutationParams, - IRemoveWorksheetMergeMutationParams, -} from '../../basics/interfaces/mutation-interface'; import { getAddMergeMutationRangeByType } from '../../controllers/merge-cell.controller'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { AddMergeUndoMutationFactory, AddWorksheetMergeMutation } from '../mutations/add-worksheet-merge.mutation'; import { RemoveMergeUndoMutationFactory, RemoveWorksheetMergeMutation, } from '../mutations/remove-worksheet-merge.mutation'; -import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; import { getSheetCommandTarget } from './utils/target-util'; diff --git a/packages/sheets/src/commands/commands/clear-selection-all.command.ts b/packages/sheets/src/commands/commands/clear-selection-all.command.ts index bd160d4a036..baafa72bf8a 100644 --- a/packages/sheets/src/commands/commands/clear-selection-all.command.ts +++ b/packages/sheets/src/commands/commands/clear-selection-all.command.ts @@ -15,6 +15,8 @@ */ import type { IAccessor, ICommand, IMutationInfo, Workbook } from '@univerjs/core'; +import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; + import { CommandType, ICommandService, @@ -23,12 +25,10 @@ import { sequenceExecute, UniverInstanceType, } from '@univerjs/core'; - -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { generateNullCell } from '../../basics/utils'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; -import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; -import { generateNullCell } from '../../basics/utils'; /** * The command to clear all in current selected ranges. @@ -100,4 +100,3 @@ export const ClearSelectionAllCommand: ICommand = { return false; }, }; - diff --git a/packages/sheets/src/commands/commands/clear-selection-content.command.ts b/packages/sheets/src/commands/commands/clear-selection-content.command.ts index 3f199a6be18..b7d7892f30a 100644 --- a/packages/sheets/src/commands/commands/clear-selection-content.command.ts +++ b/packages/sheets/src/commands/commands/clear-selection-content.command.ts @@ -15,6 +15,8 @@ */ import type { IAccessor, ICommand, Workbook } from '@univerjs/core'; +import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; + import { CommandType, ICommandService, @@ -23,12 +25,10 @@ import { sequenceExecute, UniverInstanceType, } from '@univerjs/core'; - -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { generateNullCellValue } from '../../basics/utils'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; -import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; -import { generateNullCellValue } from '../../basics/utils'; /** * The command to clear content in current selected ranges. diff --git a/packages/sheets/src/commands/commands/clear-selection-format.command.ts b/packages/sheets/src/commands/commands/clear-selection-format.command.ts index 42a33d75217..c1cc725e827 100644 --- a/packages/sheets/src/commands/commands/clear-selection-format.command.ts +++ b/packages/sheets/src/commands/commands/clear-selection-format.command.ts @@ -15,6 +15,8 @@ */ import type { IAccessor, ICommand, IMutationInfo, Workbook } from '@univerjs/core'; +import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; + import { CommandType, ICommandService, @@ -23,12 +25,10 @@ import { sequenceExecute, UniverInstanceType, } from '@univerjs/core'; - -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { generateNullCellStyle } from '../../basics/utils'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; -import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; -import { generateNullCellStyle } from '../../basics/utils'; /** * The command to clear content in current selected ranges. @@ -104,4 +104,3 @@ export const ClearSelectionFormatCommand: ICommand = { return false; }, }; - diff --git a/packages/sheets/src/commands/commands/delete-range-move-left.command.ts b/packages/sheets/src/commands/commands/delete-range-move-left.command.ts index 8dc4eb1ec52..b903528c931 100644 --- a/packages/sheets/src/commands/commands/delete-range-move-left.command.ts +++ b/packages/sheets/src/commands/commands/delete-range-move-left.command.ts @@ -15,6 +15,8 @@ */ import type { IAccessor, ICommand, IMutationInfo, IRange } from '@univerjs/core'; +import type { IDeleteRangeMutationParams } from '../../basics/interfaces/mutation-interface'; + import { CommandType, Dimension, @@ -23,9 +25,7 @@ import { IUniverInstanceService, sequenceExecute, } from '@univerjs/core'; - -import type { IDeleteRangeMutationParams } from '../../basics/interfaces/mutation-interface'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { getRemoveRangeMutations } from '../utils/handle-range-mutation'; import { followSelectionOperation } from './utils/selection-utils'; diff --git a/packages/sheets/src/commands/commands/delete-range-move-up.command.ts b/packages/sheets/src/commands/commands/delete-range-move-up.command.ts index fb5d9390947..0e1f855d321 100644 --- a/packages/sheets/src/commands/commands/delete-range-move-up.command.ts +++ b/packages/sheets/src/commands/commands/delete-range-move-up.command.ts @@ -15,6 +15,8 @@ */ import type { IAccessor, ICommand, IMutationInfo, IRange } from '@univerjs/core'; +import type { IDeleteRangeMutationParams } from '../../basics/interfaces/mutation-interface'; + import { CommandType, Dimension, @@ -23,9 +25,7 @@ import { IUniverInstanceService, sequenceExecute, } from '@univerjs/core'; - -import type { IDeleteRangeMutationParams } from '../../basics/interfaces/mutation-interface'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { getRemoveRangeMutations } from '../utils/handle-range-mutation'; import { followSelectionOperation } from './utils/selection-utils'; diff --git a/packages/sheets/src/commands/commands/insert-range-move-down.command.ts b/packages/sheets/src/commands/commands/insert-range-move-down.command.ts index 4b1afd0b5dd..104a3d55048 100644 --- a/packages/sheets/src/commands/commands/insert-range-move-down.command.ts +++ b/packages/sheets/src/commands/commands/insert-range-move-down.command.ts @@ -33,7 +33,7 @@ import { Range, sequenceExecute, } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { InsertRowMutation, InsertRowMutationUndoFactory } from '../mutations/insert-row-col.mutation'; import { RemoveRowMutation } from '../mutations/remove-row-col.mutation'; diff --git a/packages/sheets/src/commands/commands/insert-range-move-right.command.ts b/packages/sheets/src/commands/commands/insert-range-move-right.command.ts index f966dba16b9..f088f26b44b 100644 --- a/packages/sheets/src/commands/commands/insert-range-move-right.command.ts +++ b/packages/sheets/src/commands/commands/insert-range-move-right.command.ts @@ -14,6 +14,13 @@ * limitations under the License. */ +import type { IAccessor, ICellData, ICommand, IMutationInfo, IObjectMatrixPrimitiveType, IRange } from '@univerjs/core'; +import type { + IInsertColMutationParams, + IInsertRangeMutationParams, + IRemoveColMutationParams, +} from '../../basics/interfaces/mutation-interface'; + import { BooleanNumber, CommandType, @@ -26,20 +33,13 @@ import { Range, sequenceExecute, } from '@univerjs/core'; -import type { IAccessor, ICellData, ICommand, IMutationInfo, IObjectMatrixPrimitiveType, IRange } from '@univerjs/core'; - -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { InsertColMutation, InsertColMutationUndoFactory } from '../mutations/insert-row-col.mutation'; import { RemoveColMutation } from '../mutations/remove-row-col.mutation'; import { getInsertRangeMutations } from '../utils/handle-range-mutation'; import { followSelectionOperation } from './utils/selection-utils'; import { getSheetCommandTarget } from './utils/target-util'; -import type { - IInsertColMutationParams, - IInsertRangeMutationParams, - IRemoveColMutationParams, -} from '../../basics/interfaces/mutation-interface'; export interface InsertRangeMoveRightCommandParams { range: IRange; diff --git a/packages/sheets/src/commands/commands/insert-row-col.command.ts b/packages/sheets/src/commands/commands/insert-row-col.command.ts index 8e515d14c78..0ce055be969 100644 --- a/packages/sheets/src/commands/commands/insert-row-col.command.ts +++ b/packages/sheets/src/commands/commands/insert-row-col.command.ts @@ -32,7 +32,7 @@ import { RANGE_TYPE, sequenceExecute, } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { InsertColMutation, diff --git a/packages/sheets/src/commands/commands/move-rows-cols.command.ts b/packages/sheets/src/commands/commands/move-rows-cols.command.ts index 42a025dff13..3bb2ead99fb 100644 --- a/packages/sheets/src/commands/commands/move-rows-cols.command.ts +++ b/packages/sheets/src/commands/commands/move-rows-cols.command.ts @@ -30,7 +30,7 @@ import { Rectangle, sequenceExecute, } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { MoveColsMutation, diff --git a/packages/sheets/src/commands/commands/remove-row-col.command.ts b/packages/sheets/src/commands/commands/remove-row-col.command.ts index 9b767f56d23..a0c5eb0ccb8 100644 --- a/packages/sheets/src/commands/commands/remove-row-col.command.ts +++ b/packages/sheets/src/commands/commands/remove-row-col.command.ts @@ -15,6 +15,13 @@ */ import type { IAccessor, ICommand, IMutationInfo, IRange } from '@univerjs/core'; +import type { + IInsertColMutationParams, + IInsertRowMutationParams, + IRemoveColMutationParams, + IRemoveRowsMutationParams, +} from '../../basics/interfaces/mutation-interface'; + import { CommandType, ICommandService, @@ -22,14 +29,7 @@ import { IUniverInstanceService, sequenceExecute, } from '@univerjs/core'; - -import type { - IInsertColMutationParams, - IInsertRowMutationParams, - IRemoveColMutationParams, - IRemoveRowsMutationParams, -} from '../../basics/interfaces/mutation-interface'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { InsertColMutation, InsertRowMutation } from '../mutations/insert-row-col.mutation'; import { diff --git a/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts b/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts index 8f20117cbae..74b16124de7 100644 --- a/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts +++ b/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts @@ -15,20 +15,20 @@ */ import type { IAccessor, ICellData, ICommand, IMutationInfo, IRange, Nullable, Worksheet } from '@univerjs/core'; -import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, ObjectMatrix, Rectangle, sequenceExecute, Tools } from '@univerjs/core'; - import type { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams, } from '../../basics/interfaces/mutation-interface'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; + +import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; +import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, ObjectMatrix, Rectangle, sequenceExecute, Tools } from '@univerjs/core'; +import { SetSelectionsOperation } from '../../commands/operations/selection.operation'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { AddWorksheetMergeMutation } from '../mutations/add-worksheet-merge.mutation'; import { RemoveMergeUndoMutationFactory, RemoveWorksheetMergeMutation, } from '../mutations/remove-worksheet-merge.mutation'; -import { SetSelectionsOperation } from '../../commands/operations/selection.operation'; -import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation'; import { SetRangeValuesMutation } from '../mutations/set-range-values.mutation'; import { getSheetCommandTarget } from './utils/target-util'; diff --git a/packages/sheets/src/commands/commands/set-border-command.ts b/packages/sheets/src/commands/commands/set-border-command.ts index efca8bdee45..d2b90ad19db 100644 --- a/packages/sheets/src/commands/commands/set-border-command.ts +++ b/packages/sheets/src/commands/commands/set-border-command.ts @@ -37,7 +37,7 @@ import { Tools, } from '@univerjs/core'; import { BorderStyleManagerService, type IBorderInfo } from '../../services/border-style-manager.service'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; import { getSheetCommandTarget } from './utils/target-util'; diff --git a/packages/sheets/src/commands/commands/set-col-visible.command.ts b/packages/sheets/src/commands/commands/set-col-visible.command.ts index e8bbe505fb8..0218bd8fcf2 100644 --- a/packages/sheets/src/commands/commands/set-col-visible.command.ts +++ b/packages/sheets/src/commands/commands/set-col-visible.command.ts @@ -14,6 +14,10 @@ * limitations under the License. */ +import type { IAccessor, ICommand, IRange, Nullable, Worksheet } from '@univerjs/core'; +import type { ISetColHiddenMutationParams, ISetColVisibleMutationParams } from '../mutations/set-col-visible.mutation'; + +import type { ISetSelectionsOperationParams } from '../operations/selection.operation'; import { CommandType, ICommandService, @@ -22,9 +26,7 @@ import { RANGE_TYPE, sequenceExecute, } from '@univerjs/core'; -import type { IAccessor, ICommand, IRange, Nullable, Worksheet } from '@univerjs/core'; - -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { SetColHiddenMutation, @@ -35,8 +37,6 @@ import { import { SetSelectionsOperation } from '../operations/selection.operation'; import { getPrimaryForRange } from './utils/selection-utils'; import { getSheetCommandTarget } from './utils/target-util'; -import type { ISetColHiddenMutationParams, ISetColVisibleMutationParams } from '../mutations/set-col-visible.mutation'; -import type { ISetSelectionsOperationParams } from '../operations/selection.operation'; export interface ISetSpecificColsVisibleCommandParams { unitId: string; diff --git a/packages/sheets/src/commands/commands/set-range-values.command.ts b/packages/sheets/src/commands/commands/set-range-values.command.ts index 37e1457b509..7f6c6b3c2d6 100644 --- a/packages/sheets/src/commands/commands/set-range-values.command.ts +++ b/packages/sheets/src/commands/commands/set-range-values.command.ts @@ -29,7 +29,7 @@ import { Tools, } from '@univerjs/core'; import { WorksheetEditPermission } from '../../services/permission/permission-point'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; import { followSelectionOperation } from './utils/selection-utils'; diff --git a/packages/sheets/src/commands/commands/set-row-visible.command.ts b/packages/sheets/src/commands/commands/set-row-visible.command.ts index 1daccf9f43e..b7049f7ab57 100644 --- a/packages/sheets/src/commands/commands/set-row-visible.command.ts +++ b/packages/sheets/src/commands/commands/set-row-visible.command.ts @@ -14,6 +14,10 @@ * limitations under the License. */ +import type { IAccessor, ICommand, IRange, Nullable, Worksheet } from '@univerjs/core'; +import type { ISetRowHiddenMutationParams, ISetRowVisibleMutationParams } from '../mutations/set-row-visible.mutation'; + +import type { ISetSelectionsOperationParams } from '../operations/selection.operation'; import { CommandType, ICommandService, @@ -22,9 +26,7 @@ import { RANGE_TYPE, sequenceExecute, } from '@univerjs/core'; -import type { IAccessor, ICommand, IRange, Nullable, Worksheet } from '@univerjs/core'; - -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { SetRowHiddenMutation, @@ -35,8 +37,6 @@ import { import { SetSelectionsOperation } from '../operations/selection.operation'; import { getPrimaryForRange } from './utils/selection-utils'; import { getSheetCommandTarget } from './utils/target-util'; -import type { ISetRowHiddenMutationParams, ISetRowVisibleMutationParams } from '../mutations/set-row-visible.mutation'; -import type { ISetSelectionsOperationParams } from '../operations/selection.operation'; export interface ISetSpecificRowsVisibleCommandParams { unitId: string; diff --git a/packages/sheets/src/commands/commands/set-style.command.ts b/packages/sheets/src/commands/commands/set-style.command.ts index 87c07e794fd..13eaa8a2ea4 100644 --- a/packages/sheets/src/commands/commands/set-style.command.ts +++ b/packages/sheets/src/commands/commands/set-style.command.ts @@ -41,7 +41,7 @@ import { sequenceExecute, Tools, } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation'; import { createRangeIteratorWithSkipFilteredRows } from './utils/selection-utils'; diff --git a/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts b/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts index e1e21905099..e2e8ca1e6df 100644 --- a/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts +++ b/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts @@ -26,7 +26,7 @@ import { Rectangle, sequenceExecute, } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { SetWorksheetColWidthMutation, diff --git a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts index 3c2c53e10ac..38b3903e532 100644 --- a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts +++ b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts @@ -30,7 +30,7 @@ import { Rectangle, sequenceExecute, } from '@univerjs/core'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service'; import { SetWorksheetRowHeightMutation, diff --git a/packages/sheets/src/commands/commands/utils/selection-utils.ts b/packages/sheets/src/commands/commands/utils/selection-utils.ts index 3af143f252c..e0b370118c2 100644 --- a/packages/sheets/src/commands/commands/utils/selection-utils.ts +++ b/packages/sheets/src/commands/commands/utils/selection-utils.ts @@ -243,7 +243,6 @@ export function createRangeIteratorWithSkipFilteredRows(sheet: Worksheet) { * @param endColumn * @param isRow * @param styleRowOrColumn - * @returns */ export function copyRangeStyles( worksheet: Worksheet, @@ -269,3 +268,41 @@ export function copyRangeStyles( } return cellValue; } + +export function copyRangeStylesWithoutBorder( + worksheet: Worksheet, + startRow: number, + endRow: number, + startColumn: number, + endColumn: number, + isRow: boolean, + styleRowOrColumn: number +): IObjectMatrixPrimitiveType { + const cellValue: IObjectMatrixPrimitiveType = {}; + for (let row = startRow; row <= endRow; row++) { + for (let column = startColumn; column <= endColumn; column++) { + const cell = isRow ? worksheet.getCell(styleRowOrColumn, column) : worksheet.getCell(row, styleRowOrColumn); + if (!cell || !cell.s) { + continue; + } + if (!cellValue[row]) { + cellValue[row] = {}; + } + + // univer-pro/issues/3016 insert row/column should not reuse border style + if (typeof cell.s === 'string') { + const styleData = worksheet.getStyleDataByHash(cell.s); + if (styleData) { + delete styleData.bd; + cell.s = worksheet.setStyleData(styleData); + } + } else { + const styleData = { ...cell.s }; + delete styleData.bd; + cell.s = worksheet.setStyleData(styleData); + } + cellValue[row][column] = { s: cell.s }; + } + } + return cellValue; +} diff --git a/packages/sheets/src/commands/utils/handle-merge-operation.ts b/packages/sheets/src/commands/utils/handle-merge-operation.ts index 786e182d3c1..ec34b3a4d28 100644 --- a/packages/sheets/src/commands/utils/handle-merge-operation.ts +++ b/packages/sheets/src/commands/utils/handle-merge-operation.ts @@ -15,10 +15,10 @@ */ import type { IAccessor, IRange } from '@univerjs/core'; -import { Dimension } from '@univerjs/core'; import type { IAddMergeCommandParams } from '../commands/add-worksheet-merge.command'; -import { SheetsSelectionsService } from '../../services/selections/selection-manager.service'; import type { ISetSelectionsOperationParams } from '../operations/selection.operation'; +import { Dimension } from '@univerjs/core'; +import { SheetsSelectionsService } from '../../services/selections/selection.service'; import { SetSelectionsOperation } from '../operations/selection.operation'; export const AddMergeRedoSelectionsOperationFactory = (accessor: IAccessor, params: IAddMergeCommandParams, ranges: IRange[]) => { diff --git a/packages/sheets/src/commands/utils/selection-command-util.ts b/packages/sheets/src/commands/utils/selection-command-util.ts index 9dc93509c25..78cac12a211 100644 --- a/packages/sheets/src/commands/utils/selection-command-util.ts +++ b/packages/sheets/src/commands/utils/selection-command-util.ts @@ -16,8 +16,8 @@ import type { IAccessor } from '@univerjs/core'; import { IContextService } from '@univerjs/core'; -import { DISABLE_NORMAL_SELECTIONS, SheetsSelectionsService } from '../../services/selections/selection-manager.service'; import { IRefSelectionsService } from '../../services/selections/ref-selections.service'; +import { DISABLE_NORMAL_SELECTIONS, SheetsSelectionsService } from '../../services/selections/selection.service'; export function getSelectionsService( accessor: IAccessor diff --git a/packages/sheets/src/controllers/merge-cell.controller.ts b/packages/sheets/src/controllers/merge-cell.controller.ts index 5f1ea929d8a..b14ae34de9d 100644 --- a/packages/sheets/src/controllers/merge-cell.controller.ts +++ b/packages/sheets/src/controllers/merge-cell.controller.ts @@ -16,6 +16,27 @@ /* eslint-disable max-lines-per-function */ +import type { + ICommandInfo, IMutationInfo, IRange, Workbook, +} from '@univerjs/core'; +import type { + IAddWorksheetMergeMutationParams, + IInsertColMutationParams, + IRemoveColMutationParams, + IRemoveRowsMutationParams, + IRemoveWorksheetMergeMutationParams, +} from '../basics/interfaces/mutation-interface'; + +import type { IDeleteRangeMoveLeftCommandParams } from '../commands/commands/delete-range-move-left.command'; +import type { IDeleteRangeMoveUpCommandParams } from '../commands/commands/delete-range-move-up.command'; +import type { InsertRangeMoveDownCommandParams } from '../commands/commands/insert-range-move-down.command'; +import type { InsertRangeMoveRightCommandParams } from '../commands/commands/insert-range-move-right.command'; +import type { IInsertColCommandParams, IInsertRowCommandParams } from '../commands/commands/insert-row-col.command'; +import type { IMoveRangeCommandParams } from '../commands/commands/move-range.command'; +import type { IMoveColsCommandParams, IMoveRowsCommandParams } from '../commands/commands/move-rows-cols.command'; +import type { IMoveRowsMutationParams } from '../commands/mutations/move-rows-cols.mutation'; +import type { ISetWorksheetActiveOperationParams } from '../commands/operations/set-worksheet-active.operation'; +import type { EffectRefRangeParams } from '../services/ref-range/type'; import { createInterceptorKey, Dimension, @@ -31,10 +52,6 @@ import { UniverInstanceType, } from '@univerjs/core'; import { first } from 'rxjs'; - -import type { - ICommandInfo, IMutationInfo, IRange, Workbook, -} from '@univerjs/core'; import { ClearSelectionAllCommand } from '../commands/commands/clear-selection-all.command'; import { ClearSelectionFormatCommand } from '../commands/commands/clear-selection-format.command'; import { DeleteRangeMoveLeftCommand } from '../commands/commands/delete-range-move-left.command'; @@ -60,25 +77,8 @@ import { SetWorksheetActiveOperation } from '../commands/operations/set-workshee import { RefRangeService } from '../services/ref-range/ref-range.service'; import { EffectRefRangId } from '../services/ref-range/type'; import { handleMoveCols, handleMoveRows, runRefRangeMutations } from '../services/ref-range/util'; -import { SheetsSelectionsService } from '../services/selections/selection-manager.service'; +import { SheetsSelectionsService } from '../services/selections/selection.service'; import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service'; -import type { - IAddWorksheetMergeMutationParams, - IInsertColMutationParams, - IRemoveColMutationParams, - IRemoveRowsMutationParams, - IRemoveWorksheetMergeMutationParams, -} from '../basics/interfaces/mutation-interface'; -import type { IDeleteRangeMoveLeftCommandParams } from '../commands/commands/delete-range-move-left.command'; -import type { IDeleteRangeMoveUpCommandParams } from '../commands/commands/delete-range-move-up.command'; -import type { InsertRangeMoveDownCommandParams } from '../commands/commands/insert-range-move-down.command'; -import type { InsertRangeMoveRightCommandParams } from '../commands/commands/insert-range-move-right.command'; -import type { IInsertColCommandParams, IInsertRowCommandParams } from '../commands/commands/insert-row-col.command'; -import type { IMoveRangeCommandParams } from '../commands/commands/move-range.command'; -import type { IMoveColsCommandParams, IMoveRowsCommandParams } from '../commands/commands/move-rows-cols.command'; -import type { IMoveRowsMutationParams } from '../commands/mutations/move-rows-cols.mutation'; -import type { ISetWorksheetActiveOperationParams } from '../commands/operations/set-worksheet-active.operation'; -import type { EffectRefRangeParams } from '../services/ref-range/type'; const mutationIdByRowCol = [InsertColMutation.id, InsertRowMutation.id, RemoveColMutation.id, RemoveRowMutation.id]; const mutationIdArrByMove = [MoveRowsMutation.id, MoveColsMutation.id]; diff --git a/packages/sheets/src/services/__tests__/ref-range.setvice.spec.ts b/packages/sheets/src/services/__tests__/ref-range.setvice.spec.ts index 4e3c8705f69..6882f4040a9 100644 --- a/packages/sheets/src/services/__tests__/ref-range.setvice.spec.ts +++ b/packages/sheets/src/services/__tests__/ref-range.setvice.spec.ts @@ -15,15 +15,15 @@ */ import type { Injector, IRange, Univer, Workbook, Worksheet } from '@univerjs/core'; +import type { IMoveRangeCommandParams } from '../../commands/commands/move-range.command'; import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core'; -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import type { IMoveRangeCommandParams } from '../../commands/commands/move-range.command'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { MoveRangeCommand } from '../../commands/commands/move-range.command'; import { MoveRangeMutation } from '../../commands/mutations/move-range.mutation'; import { SetSelectionsOperation } from '../../commands/operations/selection.operation'; import { RefRangeService } from '../ref-range/ref-range.service'; -import { SheetsSelectionsService } from '../selections/selection-manager.service'; +import { SheetsSelectionsService } from '../selections/selection.service'; import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service'; import { createTestBase, TEST_WORKBOOK_DATA_DEMO } from './util'; diff --git a/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts b/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts index 48c66546f91..ff23f92bb82 100644 --- a/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts +++ b/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts @@ -14,15 +14,15 @@ * limitations under the License. */ -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import type { Dependency, ICommand, IRange, IWorkbookData, Nullable, Workbook } from '@univerjs/core'; +import type { IInsertColMutationParams } from '../../../basics'; import { ICommandService, ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; -import { RefRangeService } from '../ref-range.service'; -import { SheetsSelectionsService } from '../../selections/selection-manager.service'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { InsertColMutation } from '../../../commands/mutations/insert-row-col.mutation'; -import type { IInsertColMutationParams } from '../../../basics'; +import { SheetsSelectionsService } from '../../selections/selection.service'; import { SheetInterceptorService } from '../../sheet-interceptor/sheet-interceptor.service'; +import { RefRangeService } from '../ref-range.service'; const TEST_WORKBOOK_DATA: IWorkbookData = { id: 'test', diff --git a/packages/sheets/src/services/ref-range/ref-range.service.ts b/packages/sheets/src/services/ref-range/ref-range.service.ts index a9715a182ae..b03bcde9e0e 100644 --- a/packages/sheets/src/services/ref-range/ref-range.service.ts +++ b/packages/sheets/src/services/ref-range/ref-range.service.ts @@ -34,7 +34,7 @@ import { } from '@univerjs/core'; import { MoveRangeMutation } from '../../commands/mutations/move-range.mutation'; import { RemoveSheetMutation } from '../../commands/mutations/remove-sheet.mutation'; -import { SheetsSelectionsService } from '../selections/selection-manager.service'; +import { SheetsSelectionsService } from '../selections/selection.service'; import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service'; import { EffectRefRangId } from './type'; import { adjustRangeOnMutation, getEffectedRangesOnMutation } from './util'; diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.ts index 034d5807c47..6508c952889 100644 --- a/packages/sheets/src/services/ref-range/util.ts +++ b/packages/sheets/src/services/ref-range/util.ts @@ -46,7 +46,7 @@ import { type IMoveRangeMutationParams, MoveRangeMutation } from '../../commands import { type IMoveColumnsMutationParams, type IMoveRowsMutationParams, MoveColsMutation, MoveRowsMutation } from '../../commands/mutations/move-rows-cols.mutation'; import { RemoveColMutation, RemoveRowMutation } from '../../commands/mutations/remove-row-col.mutation'; import { RemoveSheetMutation } from '../../commands/mutations/remove-sheet.mutation'; -import { SheetsSelectionsService } from '../selections/selection-manager.service'; +import { SheetsSelectionsService } from '../selections/selection.service'; import { EffectRefRangId, OperatorType } from './type'; const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; diff --git a/packages/sheets/src/services/selections/index.ts b/packages/sheets/src/services/selections/index.ts index d69d3545753..711280d8afa 100644 --- a/packages/sheets/src/services/selections/index.ts +++ b/packages/sheets/src/services/selections/index.ts @@ -15,6 +15,6 @@ */ export { IRefSelectionsService, RefSelectionsService } from './ref-selections.service'; +export { DISABLE_NORMAL_SELECTIONS, SheetsSelectionsService } from './selection.service'; export { WorkbookSelectionModel } from './selection-data-model'; -export { DISABLE_NORMAL_SELECTIONS, SheetsSelectionsService } from './selection-manager.service'; export { type ISelectionManagerSearchParam, SelectionMoveType } from './type'; diff --git a/packages/sheets/src/services/selections/ref-selections.service.ts b/packages/sheets/src/services/selections/ref-selections.service.ts index ee9ca87ad74..59f830ca3a8 100644 --- a/packages/sheets/src/services/selections/ref-selections.service.ts +++ b/packages/sheets/src/services/selections/ref-selections.service.ts @@ -19,7 +19,7 @@ import type { Observable } from 'rxjs'; import type { WorkbookSelectionModel } from './selection-data-model'; import { createIdentifier, IUniverInstanceService, UniverInstanceType } from '@univerjs/core'; import { BehaviorSubject, map, merge, switchMap, takeUntil } from 'rxjs'; -import { SheetsSelectionsService } from './selection-manager.service'; +import { SheetsSelectionsService } from './selection.service'; /** * Ref selections service reuses code of `SelectionManagerService`. And it only contains ref selections diff --git a/packages/sheets/src/services/selections/selection-manager.service.ts b/packages/sheets/src/services/selections/selection.service.ts similarity index 99% rename from packages/sheets/src/services/selections/selection-manager.service.ts rename to packages/sheets/src/services/selections/selection.service.ts index 51c599e2f13..4ff65a5fdb7 100644 --- a/packages/sheets/src/services/selections/selection-manager.service.ts +++ b/packages/sheets/src/services/selections/selection.service.ts @@ -89,7 +89,6 @@ export class SheetsSelectionsService extends RxDisposable { if (!current) { throw new Error('[SheetsSelectionsService]: cannot find current selection position!'); } - const { unitId, sheetId } = current; this._ensureWorkbookSelection(unitId).addSelections(sheetId, unitIdOrSelections); } diff --git a/packages/sheets/src/sheets-plugin.ts b/packages/sheets/src/sheets-plugin.ts index 61b4d8459a0..e9be6d1d059 100644 --- a/packages/sheets/src/sheets-plugin.ts +++ b/packages/sheets/src/sheets-plugin.ts @@ -38,7 +38,7 @@ import { RangeProtectionService } from './services/permission/range-permission/r import { WorkbookPermissionService } from './services/permission/workbook-permission/workbook-permission.service'; import { WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from './services/permission/worksheet-permission'; import { RefRangeService } from './services/ref-range/ref-range.service'; -import { SheetsSelectionsService } from './services/selections/selection-manager.service'; +import { SheetsSelectionsService } from './services/selections/selection.service'; import { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service'; const PLUGIN_NAME = 'SHEET_PLUGIN'; diff --git a/packages/ui/src/components/progress-bar/ProgressBar.tsx b/packages/ui/src/components/progress-bar/ProgressBar.tsx index 59605384602..3d7db0248ce 100644 --- a/packages/ui/src/components/progress-bar/ProgressBar.tsx +++ b/packages/ui/src/components/progress-bar/ProgressBar.tsx @@ -17,7 +17,7 @@ import { ThemeService, useDependency } from '@univerjs/core'; import { Tooltip } from '@univerjs/design'; import { CloseSingle } from '@univerjs/icons'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { useEffect, useRef } from 'react'; import styles from './index.module.less'; export interface IProgressBarProps { @@ -35,30 +35,36 @@ export function ProgressBar(props: IProgressBarProps) { const color = barColor ?? themeService.getCurrentTheme().primaryColor; ; const progressBarInnerRef = useRef(null); - // Introduce a state variable for visibility - const [visible, setVisible] = useState(count > 0); + const progressBarContainerRef = useRef(null); useEffect(() => { - if (!progressBarInnerRef.current) return; - const progressBarInner = progressBarInnerRef.current; + const progressBarContainer = progressBarContainerRef.current; + + if (!progressBarInner || !progressBarContainer) return; // Hide immediately if both count and done are zero if (count === 0 && done === 0) { - setVisible(false); + progressBarContainer.style.display = 'none'; progressBarInner.style.width = '0%'; + return; } // Update the width of the progress bar else if (count > 0) { - setVisible(true); + progressBarContainer.style.display = 'flex'; + + const width = Math.floor((done / count) * 100); // Trigger the animation to prevent the progress bar from not being closed due to reaching 100% too quickly without animation if (done === count) { requestAnimationFrame(() => { - progressBarInner.style.width = `${Math.floor((done / count) * 100)}%`; + progressBarInner.style.width = `${width - 1}%`; // Set a width slightly smaller than the target + requestAnimationFrame(() => { + progressBarInner.style.width = `${width}%`; // Then set the target width + }); }); } else { - progressBarInner.style.width = `${Math.floor((done / count) * 100)}%`; + progressBarInner.style.width = `${width}%`; } } // Else, wait for the transition to end before hiding @@ -67,7 +73,8 @@ export function ProgressBar(props: IProgressBarProps) { const handleTransitionEnd = () => { if (done === count) { // Hide the progress bar after the animation finishes - setVisible(false); + progressBarContainer.style.display = 'none'; + progressBarInner.style.width = '0%'; // Notify the parent component to reset the progress after the animation ends // After the progress bar is completed 100%, the upper props data source may not be reset, resulting in count and done still being the previous values (displaying 100%) when the progress bar is triggered next time, so a message is reported here to trigger clearing. @@ -84,7 +91,7 @@ export function ProgressBar(props: IProgressBarProps) { }, [count, done]); return ( -
+
{label}