Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor: rename isAutoHeight to ia and change it TS type to BooleanNumber (#1210)

Ran Luo3c6725284f79
diff --git a/packages/core/src/sheets/row-manager.ts b/packages/core/src/sheets/row-manager.ts
index 5b8d46f2c6..e58ffce885 100644
--- a/packages/core/src/sheets/row-manager.ts
+++ b/packages/core/src/sheets/row-manager.ts
@@ -66,9 +66,9 @@ export class RowManager {
hd: BooleanNumber.FALSE,
h: config.defaultRowHeight,
};
- const { isAutoHeight, ah, h = config.defaultRowHeight } = row;
+ const { ia, ah, h = config.defaultRowHeight } = row;
- height += (isAutoHeight == null || !!isAutoHeight) && typeof ah === 'number' ? ah : h;
+ height += (ia == null || ia === BooleanNumber.TRUE) && typeof ah === 'number' ? ah : h;
}
return height;
diff --git a/packages/core/src/types/interfaces/i-row-data.ts b/packages/core/src/types/interfaces/i-row-data.ts
index 2ec331096f..18a229c6af 100644
--- a/packages/core/src/types/interfaces/i-row-data.ts
+++ b/packages/core/src/types/interfaces/i-row-data.ts
@@ -27,7 +27,7 @@ export interface IRowData {
/**
* is current row self-adaptive to its content, use `ah` to set row height when true, else use `h`.
*/
- isAutoHeight?: boolean;
+ ia?: BooleanNumber; // pre name `isAutoHeight`
/**
* auto height
*/
diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
index 57b614a9e4..a63c2ab0c4 100644
--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts
+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
@@ -413,8 +413,8 @@ export class SpreadsheetSkeleton extends Skeleton {
continue;
}
- // The row sets isAutoHeight to false, and there is no need to calculate the automatic row height for the row.
- if (rowObjectArray[rowIndex]?.isAutoHeight === false) {
+ // The row sets ia to false, and there is no need to calculate the automatic row height for the row.
+ if (rowObjectArray[rowIndex]?.ia === BooleanNumber.FALSE) {
continue;
}
@@ -1330,8 +1330,8 @@ export class SpreadsheetSkeleton extends Skeleton {
if (!rowDataItem) {
continue;
}
- const { h = defaultRowHeight, ah, isAutoHeight } = rowDataItem;
- if ((isAutoHeight == null || !!isAutoHeight) && typeof ah === 'number') {
+ const { h = defaultRowHeight, ah, ia } = rowDataItem;
+ if ((ia == null || ia === BooleanNumber.TRUE) && typeof ah === 'number') {
rowHeight = ah;
} else {
rowHeight = h;
diff --git a/packages/sheets-ui/src/services/selection/__test__/create-service-test-bed.ts b/packages/sheets-ui/src/services/selection/__test__/create-service-test-bed.ts
index 945f4337fb..efc0adc2b4 100644
--- a/packages/sheets-ui/src/services/selection/__test__/create-service-test-bed.ts
+++ b/packages/sheets-ui/src/services/selection/__test__/create-service-test-bed.ts
@@ -15,7 +15,15 @@
*/
import type { IWorkbookData, Workbook } from '@univerjs/core';
-import { ILogService, IUniverInstanceService, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
+import {
+ BooleanNumber,
+ ILogService,
+ IUniverInstanceService,
+ LogLevel,
+ Plugin,
+ PluginType,
+ Univer,
+} from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
@@ -54,7 +62,7 @@ const TEST_WORKBOOK_DATA_DEMO: () => IWorkbookData = () => ({
'3': {
hd: 0,
h: 96.328125,
- isAutoHeight: false,
+ ia: BooleanNumber.FALSE,
},
},
columnData: {
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 33801a59b8..4677856cb5 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,7 +15,14 @@
*/
import type { Nullable, Univer } from '@univerjs/core';
-import { ICommandService, IUniverInstanceService, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core';
+import {
+ BooleanNumber,
+ ICommandService,
+ IUniverInstanceService,
+ RANGE_TYPE,
+ RedoCommand,
+ UndoCommand,
+} from '@univerjs/core';
import type { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
@@ -44,12 +51,12 @@ describe('Test set row height commands', () => {
return worksheet.getRowHeight(row);
}
- function getRowIsAutoHeight(row: number): Nullable<boolean> {
+ function getRowIsAutoHeight(row: number): Nullable<BooleanNumber> {
const worksheet = get(IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet();
const rowManager = worksheet.getRowManager();
const rowInfo = rowManager.getRow(row);
- return rowInfo?.isAutoHeight;
+ return rowInfo?.ia;
}
beforeEach(() => {
@@ -111,11 +118,11 @@ describe('Test set row height commands', () => {
anchorRow: 5,
});
expect(getRowHeight(1)).toBe(14);
- expect(getRowIsAutoHeight(1)).toBe(false);
+ expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(2)).toBe(14);
- expect(getRowIsAutoHeight(2)).toBe(false);
+ expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(5)).toBe(14);
- expect(getRowIsAutoHeight(5)).toBe(false);
+ expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.FALSE);
await commandService.executeCommand(UndoCommand.id);
expect(getRowHeight(1)).toBe(19);
@@ -150,11 +157,11 @@ describe('Test set row height commands', () => {
value: 77,
});
expect(getRowHeight(1)).toBe(77);
- expect(getRowIsAutoHeight(1)).toBe(false);
+ expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(2)).toBe(77);
- expect(getRowIsAutoHeight(2)).toBe(false);
+ expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(5)).toBe(77);
- expect(getRowIsAutoHeight(5)).toBe(false);
+ expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.FALSE);
await commandService.executeCommand(UndoCommand.id);
expect(getRowHeight(1)).toBe(14);
@@ -168,21 +175,21 @@ describe('Test set row height commands', () => {
});
describe('Set fit content in ranges', () => {
- it('Should change all rows isAutoHeight to true in selections', async () => {
+ it('Should change all rows ia to true in selections', async () => {
await commandService.executeCommand(SetWorksheetRowIsAutoHeightCommand.id);
- expect(getRowIsAutoHeight(1)).toBe(true);
- expect(getRowIsAutoHeight(2)).toBe(true);
- expect(getRowIsAutoHeight(5)).toBe(true);
+ expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.TRUE);
+ expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.TRUE);
+ expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.TRUE);
await commandService.executeCommand(UndoCommand.id);
expect(getRowIsAutoHeight(1)).toBe(undefined);
- expect(getRowIsAutoHeight(2)).toBe(false);
+ expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.FALSE);
expect(getRowIsAutoHeight(5)).toBe(undefined);
await commandService.executeCommand(RedoCommand.id);
- expect(getRowIsAutoHeight(1)).toBe(true);
- expect(getRowIsAutoHeight(2)).toBe(true);
- expect(getRowIsAutoHeight(5)).toBe(true);
+ expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.TRUE);
+ expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.TRUE);
+ expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.TRUE);
});
});
});
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 7813106844..4102771ca9 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
@@ -16,6 +16,7 @@
import type { ICommand, IRange } from '@univerjs/core';
import {
+ BooleanNumber,
CommandType,
ICommandService,
IUndoRedoService,
@@ -123,7 +124,7 @@ export const DeltaRowHeightCommand: ICommand = {
unitId,
subUnitId,
ranges: redoMutationParams.ranges,
- autoHeightInfo: false,
+ autoHeightInfo: BooleanNumber.FALSE,
};
const undoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams =
@@ -132,7 +133,7 @@ export const DeltaRowHeightCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
- const result = await sequenceExecute(
+ const result = sequenceExecute(
[
{
id: SetWorksheetRowHeightMutation.id,
@@ -214,7 +215,7 @@ export const SetRowHeightCommand: ICommand = {
unitId,
subUnitId,
ranges: redoMutationParams.ranges,
- autoHeightInfo: false,
+ autoHeightInfo: BooleanNumber.FALSE,
};
const undoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams =
@@ -303,7 +304,7 @@ export const SetWorksheetRowIsAutoHeightCommand: ICommand = {
unitId,
subUnitId,
ranges,
- autoHeightInfo: true, // Hard code first, maybe it will change by the menu item in the future.
+ autoHeightInfo: BooleanNumber.TRUE, // Hard code first, maybe it will change by the menu item in the future.
};
const undoMutationParams: ISetWorksheetRowIsAutoHeightMutationParams =
diff --git a/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts b/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts
index 606e3e8179..8c2ac349e2 100644
--- a/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts
+++ b/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts
@@ -15,7 +15,15 @@
*/
import type { IWorkbookData, Workbook } from '@univerjs/core';
-import { ILogService, IUniverInstanceService, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
+import {
+ BooleanNumber,
+ ILogService,
+ IUniverInstanceService,
+ LogLevel,
+ Plugin,
+ PluginType,
+ Univer,
+} from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
@@ -54,7 +62,7 @@ const TEST_WORKBOOK_DATA_DEMO: () => IWorkbookData = () => ({
'3': {
hd: 0,
h: 96.328125,
- isAutoHeight: false,
+ ia: BooleanNumber.FALSE,
},
},
columnData: {
diff --git a/packages/sheets/src/commands/mutations/__tests__/remove-row-col.mutation.spec.ts b/packages/sheets/src/commands/mutations/__tests__/remove-row-col.mutation.spec.ts
index 2206aed243..5150e682c2 100644
--- a/packages/sheets/src/commands/mutations/__tests__/remove-row-col.mutation.spec.ts
+++ b/packages/sheets/src/commands/mutations/__tests__/remove-row-col.mutation.spec.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { ICommandService, IUniverInstanceService } from '@univerjs/core';
+import { BooleanNumber, ICommandService, IUniverInstanceService } from '@univerjs/core';
import type { Injector } from '@wendellhu/redi';
import { beforeEach, describe, expect, it } from 'vitest';
@@ -72,7 +72,7 @@ describe('Test moving rows & cols', () => {
expect(undoDeleteParams).toEqual({
...getId(),
range: { endColumn: 19, endRow: 3, rangeType: 1, startColumn: 0, startRow: 3 },
- rowInfo: { 0: { h: 96.328125, hd: 0, isAutoHeight: false } },
+ rowInfo: { 0: { h: 96.328125, hd: 0, ia: BooleanNumber.FALSE } },
});
});
});
diff --git a/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
index e6fee52610..8705e81d02 100644
--- a/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { IMutation, IObjectArrayPrimitiveType, IRange, Nullable } from '@univerjs/core';
+import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, Nullable } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
import type { IRowAutoHeightInfo } from '@univerjs/engine-render';
import type { IAccessor } from '@wendellhu/redi';
@@ -32,7 +32,7 @@ export interface ISetWorksheetRowIsAutoHeightMutationParams {
unitId: string;
subUnitId: string;
ranges: IRange[];
- autoHeightInfo: boolean | IObjectArrayPrimitiveType<Nullable<boolean>>;
+ autoHeightInfo: BooleanNumber | IObjectArrayPrimitiveType<Nullable<BooleanNumber>>;
}
export interface ISetWorksheetRowAutoHeightMutationParams {
@@ -82,14 +82,14 @@ export const SetWorksheetRowIsAutoHeightMutationFactory = (
const workbook = univerInstanceService.getUniverSheetInstance(unitId)!;
const worksheet = workbook.getSheetBySheetId(subUnitId)!;
- const autoHeightHash: IObjectArrayPrimitiveType<Nullable<boolean>> = {};
+ const autoHeightHash: IObjectArrayPrimitiveType<Nullable<BooleanNumber>> = {};
const manager = worksheet.getRowManager();
for (const { startRow, endRow } of ranges) {
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
const row = manager.getRowOrCreate(rowIndex);
- autoHeightHash[rowIndex] = row.isAutoHeight;
+ autoHeightHash[rowIndex] = row.ia;
}
}
@@ -184,10 +184,10 @@ export const SetWorksheetRowIsAutoHeightMutation: IMutation<ISetWorksheetRowIsAu
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
const row = manager.getRowOrCreate(rowIndex);
- if (typeof autoHeightInfo === 'boolean') {
- row.isAutoHeight = autoHeightInfo;
+ if (typeof autoHeightInfo === 'number') {
+ row.ia = autoHeightInfo;
} else {
- row.isAutoHeight = autoHeightInfo[rowIndex - startRow] ?? defaultRowIsAutoHeight;
+ row.ia = autoHeightInfo[rowIndex - startRow] ?? defaultRowIsAutoHeight;
}
}
}