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.

fix: fix minor problems (#604)

Wenzhao Hu2272789111be
diff --git a/packages/base-sheets/src/controllers/basic-worksheet.controller.ts b/packages/base-sheets/src/controllers/basic-worksheet.controller.ts
index d0d2de85ed..aaba19e085 100644
--- a/packages/base-sheets/src/controllers/basic-worksheet.controller.ts
+++ b/packages/base-sheets/src/controllers/basic-worksheet.controller.ts
@@ -1,5 +1,6 @@
-import { Disposable, ICommandService, IConfigService, IStyleData, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { IDisposable } from '@wendellhu/redi';
+import type { IStyleData } from '@univerjs/core';
+import { Disposable, ICommandService, IConfigService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import type { IDisposable } from '@wendellhu/redi';
import {
AddWorksheetMergeAllCommand,
@@ -86,6 +87,7 @@ import { RemoveSheetMutation } from '../commands/mutations/remove-sheet.mutation
import { RemoveWorksheetMergeMutation } from '../commands/mutations/remove-worksheet-merge.mutation';
import { SetColHiddenMutation, SetColVisibleMutation } from '../commands/mutations/set-col-visible.mutation';
import { SetFrozenMutation } from '../commands/mutations/set-frozen.mutation';
+import { SetNumfmtMutation } from '../commands/mutations/set-numfmt-mutation';
import { SetRangeFormattedValueMutation } from '../commands/mutations/set-range-formatted-value.mutation';
import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';
import { SetRowHiddenMutation, SetRowVisibleMutation } from '../commands/mutations/set-row-visible.mutation';
@@ -210,6 +212,7 @@ export class BasicWorksheetController extends Disposable implements IDisposable
SetWorksheetRowIsAutoHeightMutation,
SetWorksheetShowCommand,
TrimWhitespaceCommand,
+ SetNumfmtMutation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
this._configService.setConfig(MAX_CELL_PER_SHEET_KEY, MAX_CELL_PER_SHEET_DEFAULT);
diff --git a/packages/base-sheets/src/services/__tests__/numfmt.service.test.ts b/packages/base-sheets/src/services/__tests__/numfmt.service.test.ts
index cd16c01b99..5a2ab0697f 100644
--- a/packages/base-sheets/src/services/__tests__/numfmt.service.test.ts
+++ b/packages/base-sheets/src/services/__tests__/numfmt.service.test.ts
@@ -19,7 +19,9 @@ describe('test numfmt service', () => {
univer = testBed.univer;
get = testBed.get;
commandService = get(ICommandService);
+ commandService.registerCommand(SetNumfmtMutation);
});
+
afterEach(() => {
univer.dispose();
});
diff --git a/packages/base-sheets/src/services/numfmt/numfmt.service.ts b/packages/base-sheets/src/services/numfmt/numfmt.service.ts
index f4a9264ee7..d1a7c796da 100644
--- a/packages/base-sheets/src/services/numfmt/numfmt.service.ts
+++ b/packages/base-sheets/src/services/numfmt/numfmt.service.ts
@@ -13,7 +13,6 @@ import {
} from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
-import { SetNumfmtMutation } from '../../commands/mutations/set-numfmt-mutation';
import type { FormatType, INumfmtItem, INumfmtService, IRefItem, ISnapshot } from './type';
const SHEET_NUMFMT_PLUGIN = 'SHEET_NUMFMT_PLUGIN';
@@ -35,8 +34,8 @@ export class NumfmtService extends Disposable implements INumfmtService {
@Inject(ILogService) private _logService: ILogService
) {
super();
+
this._initModel();
- this._initCommands();
this.disposeWithMe(
toDisposable(() => {
this._numfmtModel.clear();
@@ -121,10 +120,6 @@ export class NumfmtService extends Disposable implements INumfmtService {
}
}
- private _initCommands() {
- [SetNumfmtMutation].forEach((config) => this.disposeWithMe(this._commandService.registerCommand(config)));
- }
-
private _setValue(workbookId: string, worksheetId: string, row: number, col: number, value: Nullable<INumfmtItem>) {
let model = this.getModel(workbookId, worksheetId);
if (!model) {
diff --git a/packages/core/src/shared/lru/lru-map.ts b/packages/core/src/shared/lru/lru-map.ts
index ce91204d9b..34df585971 100644
--- a/packages/core/src/shared/lru/lru-map.ts
+++ b/packages/core/src/shared/lru/lru-map.ts
@@ -1,3 +1,7 @@
+import type { IDisposable } from '@wendellhu/redi';
+
+import { remove } from '../../common/array';
+import { toDisposable } from '../lifecycle';
import { LRUHelper } from './lru-helper';
const NEWER = Symbol('newer');
@@ -92,7 +96,7 @@ export class Entry<K, V> {
}
export class LRUMap<K, V> {
- _keymap!: Map<K, Entry<K, V>>;
+ private _keymap!: Map<K, Entry<K, V>>;
size: number = 0;
@@ -102,6 +106,18 @@ export class LRUMap<K, V> {
newest: Entry<K, V> | undefined;
+ private readonly _onShiftListeners: Array<(entry: Entry<K, V>) => void> = [];
+
+ onShift(callback: (entry: Entry<K, V>) => void): IDisposable {
+ if (this._onShiftListeners.indexOf(callback) === -1) {
+ this._onShiftListeners.push(callback);
+
+ return toDisposable(() => remove(this._onShiftListeners, callback));
+ }
+
+ throw new Error('[LRUMap]: the listener has been registered!');
+ }
+
constructor(entries: Iterable<[K, V]>);
constructor(limit: number);
constructor(limit: number, entries: Iterable<[K, V]>);
@@ -241,6 +257,7 @@ export class LRUMap<K, V> {
entry[NEWER] = entry[OLDER] = undefined;
this._keymap.delete(entry.key);
--this.size;
+ this._onShiftListeners.forEach((callback) => callback(entry));
return [entry.key, entry.value];
}
}
@@ -264,6 +281,7 @@ export class LRUMap<K, V> {
}
delete(key: K): V | undefined {
+ console.log('delete');
const entry = this._keymap.get(key);
if (!entry) return;
this._keymap.delete(entry.key);
diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.ts
index f523467d85..35d8c75d38 100644
--- a/packages/core/src/sheets/workbook.ts
+++ b/packages/core/src/sheets/workbook.ts
@@ -1,11 +1,12 @@
import { forwardRef, Inject, Injector } from '@wendellhu/redi';
import { Subject } from 'rxjs';
-import { GenName, Nullable, Tools } from '../shared';
+import type { Nullable } from '../shared';
+import { GenName, Tools } from '../shared';
import { Disposable } from '../shared/lifecycle';
import { DEFAULT_RANGE_ARRAY, DEFAULT_WORKBOOK, DEFAULT_WORKSHEET } from '../types/const';
import { BooleanNumber } from '../types/enum';
-import {
+import type {
IColumnStartEndData,
IGridRange,
IRangeArrayData,
@@ -82,6 +83,10 @@ export class Workbook extends Disposable {
this._sheetDisposed$.complete();
}
+ save(): IWorkbookData {
+ return this._snapshot;
+ }
+
static isIRangeType(range: IRangeType | IRangeType[]): Boolean {
return typeof range === 'string' || 'startRow' in range || 'row' in range;
}