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.

chore: mv editor interceptor from sheet interceptor to editor (#624)

Gpound.liue051f73a5ede
diff --git a/packages/core/src/basics/univer-sheet.ts b/packages/core/src/basics/univer-sheet.ts
index 7d85aa2d04..70b924016e 100644
--- a/packages/core/src/basics/univer-sheet.ts
+++ b/packages/core/src/basics/univer-sheet.ts
@@ -6,7 +6,6 @@ import type { Plugin, PluginCtor } from '../plugin/plugin';
import { PluginStore } from '../plugin/plugin';
import { LifecycleStages } from '../services/lifecycle/lifecycle';
import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
-import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service';
import { Disposable, toDisposable } from '../shared/lifecycle';
import { Workbook } from '../sheets/workbook';
import type { IWorkbookData } from '../types/interfaces/i-workbook-data';
@@ -84,8 +83,7 @@ export class UniverSheet extends Disposable implements IDisposable {
}
private _initDependencies(injector: Injector): void {
- const dependencies: Dependency[] = [[SheetInterceptorService]];
-
+ const dependencies: Dependency[] = [];
dependencies.forEach((d) => injector.add(d));
}
}
diff --git a/packages/core/src/common/interceptor.ts b/packages/core/src/common/interceptor.ts
new file mode 100644
index 0000000000..6280b07840
--- /dev/null
+++ b/packages/core/src/common/interceptor.ts
@@ -0,0 +1,85 @@
+import { remove } from './array';
+import type { Nullable } from './type-utils';
+
+export type InterceptorHandler<M = unknown, C = unknown> = (
+ value: Nullable<M>,
+ context: C,
+ next: (value: Nullable<M>) => Nullable<M>
+) => Nullable<M>;
+
+export interface IInterceptor<M, C> {
+ priority?: number;
+ handler: InterceptorHandler<M, C>;
+}
+
+export const createInterceptorKey = <T = any, C = any>(key: string) => {
+ const symbol = `sheet_interceptor_${key}`;
+ return symbol as unknown as IInterceptor<T, C>;
+};
+
+export type IComposeInterceptors<T = any, C = any> = (
+ interceptors: Array<IInterceptor<T, C>>
+) => (initValue: Nullable<T>, initContext: C) => Nullable<T>;
+
+/**
+ * A helper to compose a certain type of interceptors.
+ */
+export const composeInterceptors = <T, C>(interceptors: Array<IInterceptor<T, C>>) =>
+ // eslint-disable-next-line func-names
+ function (initialValue: T, context: C) {
+ let index = -1;
+
+ function passThrough(
+ i: number,
+ v: Parameters<IInterceptor<T, C>['handler']>[0]
+ ): Parameters<IInterceptor<T, C>['handler']>[0] {
+ if (i <= index) {
+ throw new Error('[SheetInterceptorService]: next() called multiple times!');
+ }
+
+ index = i;
+ if (i === interceptors.length) {
+ return v;
+ }
+
+ const interceptor = interceptors[i];
+
+ return interceptor.handler!(v, context, passThrough.bind(null, i + 1));
+ }
+
+ return passThrough(0, initialValue);
+ } as ReturnType<IComposeInterceptors<T, C>>;
+
+export class InterceptorManager<P extends Record<string, IInterceptor<any, any>>> {
+ private _interceptorsByName: Map<string, Array<IInterceptor<unknown, unknown>>> = new Map();
+ private _interceptorPoints: P;
+
+ constructor(interceptorPoints: P) {
+ this._interceptorPoints = interceptorPoints;
+ }
+
+ fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>) {
+ const key = name as unknown as string;
+ const interceptors = this._interceptorsByName.get(key) as unknown as Array<typeof name>;
+ return composeInterceptors(interceptors || []);
+ }
+
+ intercept<T extends IInterceptor<any, any>>(name: T, interceptor: T) {
+ const key = name as unknown as string;
+ if (!this._interceptorsByName.has(key)) {
+ this._interceptorsByName.set(key, []);
+ }
+ const interceptors = this._interceptorsByName.get(key)!;
+ interceptors.push(interceptor);
+
+ this._interceptorsByName.set(
+ key,
+ interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
+ );
+ return () => remove(this._interceptorsByName.get(key)!, interceptor);
+ }
+
+ getInterceptPoints() {
+ return this._interceptorPoints;
+ }
+}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 97c822c467..50c9787ab1 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -61,9 +61,6 @@ export {
export { ResourceManagerService } from './services/resource-manager/resource-manager.service';
export type { IResourceHook } from './services/resource-manager/type';
export { IResourceManagerService } from './services/resource-manager/type';
-export { INTERCEPTOR_POINT } from './services/sheet-interceptor/interceptor-const';
-export { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
-export type { IInterceptor, ISheetLocation } from './services/sheet-interceptor/utils/interceptor';
export { type IStyleSheet, ThemeService } from './services/theme/theme.service';
export {
type IUndoRedoCommandInfos,
@@ -77,8 +74,8 @@ export {
export * from './shared';
// #region sheet
-
-export { composeInterceptors, createInterceptorKey } from './services/sheet-interceptor/utils/interceptor';
+export type { IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';
+export { composeInterceptors, createInterceptorKey, InterceptorManager } from './common/interceptor';
export { Range } from './sheets/range';
export {
deserializeRangeWithSheet,
diff --git a/packages/core/src/services/sheet-interceptor/interceptor-const.ts b/packages/core/src/services/sheet-interceptor/interceptor-const.ts
deleted file mode 100644
index 696f856825..0000000000
--- a/packages/core/src/services/sheet-interceptor/interceptor-const.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import type { ICellData } from '../../types/interfaces/i-cell-data';
-import type { ICommandInfo } from '../command/command.service';
-import type { ISheetLocation } from './utils/interceptor';
-import { createInterceptorKey } from './utils/interceptor';
-
-const CELL_CONTENT = createInterceptorKey<ICellData, ISheetLocation>('CELL_CONTENT');
-const BEFORE_CELL_EDIT = createInterceptorKey<ICellData, ISheetLocation>('BEFORE_CELL_EDIT');
-const AFTER_CELL_EDIT = createInterceptorKey<ICellData, ISheetLocation>('AFTER_CELL_EDIT');
-const PERMISSION = createInterceptorKey<boolean, ICommandInfo>('PERMISSION');
-
-export const INTERCEPTOR_POINT = {
- CELL_CONTENT,
- BEFORE_CELL_EDIT,
- AFTER_CELL_EDIT,
- PERMISSION,
-};
diff --git a/packages/core/src/services/sheet-interceptor/utils/interceptor.ts b/packages/core/src/services/sheet-interceptor/utils/interceptor.ts
deleted file mode 100644
index a05b0f3ad5..0000000000
--- a/packages/core/src/services/sheet-interceptor/utils/interceptor.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-import type { Nullable } from '../../../common/type-utils';
-import type { Workbook } from '../../../sheets/workbook';
-import type { Worksheet } from '../../../sheets/worksheet';
-
-export type InterceptorHandler<M = unknown, C = ISheetLocation> = (
- value: Nullable<M>,
- context: C,
- next: (value: Nullable<M>) => Nullable<M>
-) => Nullable<M>;
-
-export interface IInterceptor<M, C> {
- priority?: number;
- handler: InterceptorHandler<M, C>;
-}
-export interface ISheetLocation {
- workbook: Workbook;
- worksheet: Worksheet;
- workbookId: string;
- worksheetId: string;
- row: number;
- col: number;
-}
-
-export const createInterceptorKey = <T = any, C = any>(key: string) => {
- const symbol = `sheet_interceptor_${key}`;
- return symbol as unknown as IInterceptor<T, C>;
-};
-
-/**
- * A helper to compose a certain type of interceptors.
- */
-export function composeInterceptors<T = any, C = any>(interceptors: Array<IInterceptor<T, C>>) {
- // eslint-disable-next-line func-names
- return function (
- initialValue: Parameters<IInterceptor<T, C>['handler']>[0],
- context: Parameters<IInterceptor<T, C>['handler']>[1]
- ) {
- let index = -1;
-
- function passThrough(
- i: number,
- v: Parameters<IInterceptor<T, C>['handler']>[0]
- ): Parameters<IInterceptor<T, C>['handler']>[0] {
- if (i <= index) {
- throw new Error('[SheetInterceptorService]: next() called multiple times!');
- }
-
- index = i;
- if (i === interceptors.length) {
- return v;
- }
-
- const interceptor = interceptors[i];
-
- return interceptor.handler!(v, context, passThrough.bind(null, i + 1));
- }
-
- return passThrough(0, initialValue);
- };
-}
diff --git a/packages/core/src/sheets/__tests__/worksheet.spec.ts b/packages/core/src/sheets/__tests__/worksheet.spec.ts
deleted file mode 100644
index 6983330747..0000000000
--- a/packages/core/src/sheets/__tests__/worksheet.spec.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import type { Injector } from '@wendellhu/redi';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-
-import type { Univer } from '../../basics/univer';
-import { IUniverInstanceService } from '../../services/instance/instance.service';
-import { LocaleType } from '../../types/enum/locale-type';
-import type { IWorkbookData } from '../../types/interfaces/i-workbook-data';
-import { createCoreTestBed } from './create-core-test-bed';
-
-const WORKBOOK_DATA: IWorkbookData = {
- id: 'test',
- appVersion: '3.0.0-alpha',
- sheets: {
- sheet1: {
- id: 'sheet1',
- cellData: {
- '2': {
- '2': {
- v: 'C3',
- },
- '3': {
- v: 'D3',
- },
- },
- '3': {
- '2': {
- v: 'C4',
- },
- '3': {
- v: 'D4',
- },
- },
- },
- },
- },
- locale: LocaleType.EN_US,
- name: '',
- sheetOrder: [],
- styles: {},
-};
-
-describe('Test SheetInterceptorService', () => {
- let univer: Univer;
- let get: Injector['get'];
-
- beforeEach(() => {
- const testBed = createCoreTestBed(WORKBOOK_DATA);
- univer = testBed.univer;
- get = testBed.get;
- });
-
- afterEach(() => univer.dispose());
-
- describe('Test worksheet', () => {
- it('getLastRowWithContent', () => {
- const univerInstanceService = get(IUniverInstanceService);
- const sheet = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet()!;
- expect(sheet.getLastRowWithContent()).toBe(3);
- });
- it('getLastColumnWithContent', () => {
- const univerInstanceService = get(IUniverInstanceService);
- const sheet = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet()!;
- expect(sheet.getLastColumnWithContent()).toBe(3);
- });
- });
-});
diff --git a/packages/formula/src/controllers/array-formula-display.controller.ts b/packages/formula/src/controllers/array-formula-display.controller.ts
index 784a39adb6..7e28d3aed3 100644
--- a/packages/formula/src/controllers/array-formula-display.controller.ts
+++ b/packages/formula/src/controllers/array-formula-display.controller.ts
@@ -1,13 +1,6 @@
import type { ICommandInfo } from '@univerjs/core';
-import {
- Disposable,
- ICommandService,
- INTERCEPTOR_POINT,
- IUniverInstanceService,
- LifecycleStages,
- OnLifecycle,
- SheetInterceptorService,
-} from '@univerjs/core';
+import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
@@ -19,8 +12,7 @@ export class ArrayFormulaDisplayController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
- @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,
- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService
+ @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel
) {
super();
diff --git a/packages/formula/src/controllers/update-formula.controller.ts b/packages/formula/src/controllers/update-formula.controller.ts
index 92ccf6ff6a..0f58954315 100644
--- a/packages/formula/src/controllers/update-formula.controller.ts
+++ b/packages/formula/src/controllers/update-formula.controller.ts
@@ -12,7 +12,6 @@ import {
RANGE_TYPE,
Rectangle,
serializeRangeToRefString,
- SheetInterceptorService,
Tools,
} from '@univerjs/core';
import type { IFormulaData, IFormulaDataItem, ISequenceNode, IUnitSheetNameMap } from '@univerjs/engine-formula';
@@ -56,6 +55,7 @@ import {
SelectionManagerService,
SetRangeValuesMutation,
SetRangeValuesUndoMutationFactory,
+ SheetInterceptorService,
} from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
index 9f70daadf0..391c7edcc6 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
@@ -4,7 +4,6 @@ import {
Disposable,
DisposableCollection,
ICommandService,
- INTERCEPTOR_POINT,
IUniverInstanceService,
LifecycleStages,
LocaleService,
@@ -13,7 +12,6 @@ import {
OnLifecycle,
Range,
Rectangle,
- SheetInterceptorService,
ThemeService,
toDisposable,
} from '@univerjs/core';
@@ -23,9 +21,11 @@ import {
ClearSelectionAllCommand,
ClearSelectionFormatCommand,
factorySetNumfmtUndoMutation,
+ INTERCEPTOR_POINT,
INumfmtService,
SelectionManagerService,
SetNumfmtMutation,
+ SheetInterceptorService,
} from '@univerjs/sheets';
import type { IAutoFillHook } from '@univerjs/sheets-ui';
import { APPLY_TYPE, getRepeatRange, IAutoFillService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts
index e942dd2634..0074d57d59 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts
@@ -2,11 +2,10 @@ import type { Nullable } from '@univerjs/core';
import {
CellValueType,
Disposable,
- INTERCEPTOR_POINT,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
- SheetInterceptorService,
+ toDisposable,
} from '@univerjs/core';
import numfmt from '@univerjs/engine-numfmt';
import type { INumfmtItemWithCache, ISetNumfmtMutationParams } from '@univerjs/sheets';
@@ -15,7 +14,9 @@ import {
INumfmtService,
SetNumfmtMutation,
SetRangeValuesCommand,
+ SheetInterceptorService,
} from '@univerjs/sheets';
+import { IEditorBridgeService } from '@univerjs/sheets-ui';
import { Inject, Injector } from '@wendellhu/redi';
import { getPatternType } from '../utils/pattern';
@@ -55,7 +56,8 @@ export class NumfmtEditorController extends Disposable {
@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
@Inject(INumfmtService) private _numfmtService: INumfmtService,
@Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
- @Inject(Injector) private _injector: Injector
+ @Inject(Injector) private _injector: Injector,
+ @Inject(IEditorBridgeService) private _editorBridgeService: IEditorBridgeService
) {
super();
this._initInterceptorEditorStart();
@@ -65,34 +67,44 @@ export class NumfmtEditorController extends Disposable {
private _initInterceptorEditorStart() {
this.disposeWithMe(
- this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.BEFORE_CELL_EDIT, {
- handler: (value, context, next) => {
- const row = context.row;
- const col = context.col;
- const numfmtCell = this._numfmtService.getValue(context.workbookId, context.worksheetId, row, col);
- if (numfmtCell) {
- const type = getPatternType(numfmtCell.pattern);
- switch (type) {
- case 'scientific':
- case 'percent':
- case 'currency':
- case 'grouped':
- case 'number': {
- // remove the style atr
- const cell = context.worksheet.getCellRaw(row, col);
- return cell ? filterAtr(cell, ['s']) : cell;
- }
- case 'date':
- case 'time':
- case 'datetime':
- default: {
- return next && next(value);
+ toDisposable(
+ this._editorBridgeService.interceptor.intercept(
+ this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,
+ {
+ handler: (value, context, next) => {
+ const row = context.row;
+ const col = context.col;
+ const numfmtCell = this._numfmtService.getValue(
+ context.workbookId,
+ context.worksheetId,
+ row,
+ col
+ );
+ if (numfmtCell) {
+ const type = getPatternType(numfmtCell.pattern);
+ switch (type) {
+ case 'scientific':
+ case 'percent':
+ case 'currency':
+ case 'grouped':
+ case 'number': {
+ // remove the style atr
+ const cell = context.worksheet.getCellRaw(row, col);
+ return cell ? filterAtr(cell, ['s']) : cell;
+ }
+ case 'date':
+ case 'time':
+ case 'datetime':
+ default: {
+ return next && next(value);
+ }
+ }
}
- }
+ return next(value);
+ },
}
- return next(value);
- },
- })
+ )
+ )
);
}
@@ -103,59 +115,64 @@ export class NumfmtEditorController extends Disposable {
*/
private _initInterceptorEditorEnd() {
this.disposeWithMe(
- this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.AFTER_CELL_EDIT, {
- handler: (value, context, next) => {
- // clear the effect
- this._collectEffectMutation.clean();
- const currentNumfmtValue = this._numfmtService.getValue(
- context.workbookId,
- context.worksheetId,
- context.row,
- context.col
- );
- const clean = () => {
- currentNumfmtValue &&
- this._collectEffectMutation.add(
+ toDisposable(
+ this._editorBridgeService.interceptor.intercept(
+ this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,
+ {
+ handler: (value, context, next) => {
+ // clear the effect
+ this._collectEffectMutation.clean();
+ const currentNumfmtValue = this._numfmtService.getValue(
context.workbookId,
context.worksheetId,
context.row,
- context.col,
- null
+ context.col
);
- };
- if (!value?.v) {
- clean();
- return next(value);
- }
+ const clean = () => {
+ currentNumfmtValue &&
+ this._collectEffectMutation.add(
+ context.workbookId,
+ context.worksheetId,
+ context.row,
+ context.col,
+ null
+ );
+ };
+ if (!value?.v) {
+ clean();
+ return next(value);
+ }
- const content = String(value.v);
+ const content = String(value.v);
- const dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content);
- const isTranslateDate = !!dateInfo;
- if (isTranslateDate) {
- if (dateInfo && dateInfo.z) {
- const v = Number(dateInfo.v);
- this._collectEffectMutation.add(
- context.workbookId,
- context.worksheetId,
- context.row,
- context.col,
- {
- type: 'date',
- pattern: dateInfo.z,
+ const dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content);
+ const isTranslateDate = !!dateInfo;
+ if (isTranslateDate) {
+ if (dateInfo && dateInfo.z) {
+ const v = Number(dateInfo.v);
+ this._collectEffectMutation.add(
+ context.workbookId,
+ context.worksheetId,
+ context.row,
+ context.col,
+ {
+ type: 'date',
+ pattern: dateInfo.z,
+ }
+ );
+ return { ...value, v, t: CellValueType.NUMBER };
}
- );
- return { ...value, v, t: CellValueType.NUMBER };
- }
- } else if (
- ['date', 'time', 'datetime'].includes(currentNumfmtValue?.type || '') ||
- !isNumeric(content)
- ) {
- clean();
+ } else if (
+ ['date', 'time', 'datetime'].includes(currentNumfmtValue?.type || '') ||
+ !isNumeric(content)
+ ) {
+ clean();
+ }
+ return next(value);
+ },
}
- return next(value);
- },
- })
+ )
+ )
);
}
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.ts
index 76b359b569..70c21679e9 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.ts
@@ -1,12 +1,12 @@
+import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import type { IRemoveSheetCommandParams, ISetNumfmtMutationParams } from '@univerjs/sheets';
import {
- Disposable,
- IUniverInstanceService,
- LifecycleStages,
- OnLifecycle,
+ factorySetNumfmtUndoMutation,
+ INumfmtService,
+ RemoveSheetCommand,
+ SetNumfmtMutation,
SheetInterceptorService,
-} from '@univerjs/core';
-import type { IRemoveSheetCommandParams, ISetNumfmtMutationParams } from '@univerjs/sheets';
-import { factorySetNumfmtUndoMutation, INumfmtService, RemoveSheetCommand, SetNumfmtMutation } from '@univerjs/sheets';
+} from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';
@OnLifecycle(LifecycleStages.Rendered, NumfmtSheetController)
diff --git a/packages/sheets-ui/src/controllers/auto-height.controller.ts b/packages/sheets-ui/src/controllers/auto-height.controller.ts
index e16e5fef77..a900d99568 100644
--- a/packages/sheets-ui/src/controllers/auto-height.controller.ts
+++ b/packages/sheets-ui/src/controllers/auto-height.controller.ts
@@ -1,5 +1,5 @@
import type { IRange } from '@univerjs/core';
-import { IUniverInstanceService, LifecycleStages, OnLifecycle, SheetInterceptorService } from '@univerjs/core';
+import { IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type {
ISetRangeValuesRangeMutationParams,
ISetStyleCommandParams,
@@ -16,6 +16,7 @@ import {
SetWorksheetRowAutoHeightMutation,
SetWorksheetRowAutoHeightMutationFactory,
SetWorksheetRowIsAutoHeightCommand,
+ SheetInterceptorService,
} from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index 47217e7511..775447fba3 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -1,5 +1,5 @@
import type { ICellData, IMutationInfo, IRange } from '@univerjs/core';
-import { IUniverInstanceService, ObjectMatrix, Rectangle, SheetInterceptorService } from '@univerjs/core';
+import { IUniverInstanceService, ObjectMatrix, Rectangle } from '@univerjs/core';
import type {
IAddWorksheetMergeMutationParams,
IMoveRangeMutationParams,
@@ -17,6 +17,7 @@ import {
SetRangeValuesMutation,
SetRangeValuesUndoMutationFactory,
SetSelectionsOperation,
+ SheetInterceptorService,
} from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
diff --git a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts b/packages/sheets-ui/src/controllers/editor-bridge.controller.ts
index b0f092602c..a585ff35ee 100644
--- a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor-bridge.controller.ts
@@ -3,12 +3,10 @@ import {
Disposable,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
ICommandService,
- INTERCEPTOR_POINT,
IUniverInstanceService,
LifecycleStages,
makeCellToSelection,
OnLifecycle,
- SheetInterceptorService,
} from '@univerjs/core';
import { DeviceInputEventType, getCanvasOffsetByEngine, IRenderManagerService } from '@univerjs/engine-render';
import {
@@ -35,8 +33,7 @@ export class EditorBridgeController extends Disposable {
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,
@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
- @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,
- @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService
+ @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService
) {
super();
@@ -128,11 +125,9 @@ export class EditorBridgeController extends Disposable {
row: startRow,
col: startColumn,
};
-
- const cell = this._sheetInterceptorService.fetchThroughInterceptors(INTERCEPTOR_POINT.BEFORE_CELL_EDIT)(
- worksheet.getCell(startRow, startColumn),
- location
- );
+ const cell = this._editorBridgeService.interceptor.fetchThroughInterceptors(
+ this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT
+ )(worksheet.getCell(startRow, startColumn), location);
let documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell);
diff --git a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts
index 6727a69090..c2714a1227 100644
--- a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts
@@ -10,20 +10,23 @@ import {
FOCUSING_FORMULA_EDITOR,
ICommandService,
IContextService,
- INTERCEPTOR_POINT,
isFormulaString,
IUndoRedoService,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
- SheetInterceptorService,
Tools,
} from '@univerjs/core';
import { MoveCursorOperation, MoveSelectionOperation } from '@univerjs/docs';
import { FormulaEngineService, matchToken } from '@univerjs/engine-formula';
import type { IMouseEvent, IPointerEvent } from '@univerjs/engine-render';
import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
-import { SelectionManagerService, SetRangeValuesCommand, SetSelectionsOperation } from '@univerjs/sheets';
+import {
+ SelectionManagerService,
+ SetRangeValuesCommand,
+ SetSelectionsOperation,
+ SheetInterceptorService,
+} from '@univerjs/sheets';
import { KeyCode } from '@univerjs/ui';
import { Inject } from '@wendellhu/redi';
import type { Subscription } from 'rxjs';
@@ -209,10 +212,9 @@ export class EndEditController extends Disposable {
row,
col: column,
};
- const cell = this._sheetInterceptorService.fetchThroughInterceptors(INTERCEPTOR_POINT.AFTER_CELL_EDIT)(
- cellData,
- context
- );
+ const cell = this._editorBridgeService.interceptor.fetchThroughInterceptors(
+ this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT
+ )(cellData, context);
this._commandService.executeCommand(SetRangeValuesCommand.id, {
worksheetId: sheetId,
workbookId: unitId,
diff --git a/packages/sheets-ui/src/controllers/menu/__tests__/create-menu-test-bed.ts b/packages/sheets-ui/src/controllers/menu/__tests__/create-menu-test-bed.ts
index 4d8fdd918d..77c0555f0c 100644
--- a/packages/sheets-ui/src/controllers/menu/__tests__/create-menu-test-bed.ts
+++ b/packages/sheets-ui/src/controllers/menu/__tests__/create-menu-test-bed.ts
@@ -1,6 +1,6 @@
import type { IWorkbookData } from '@univerjs/core';
import { LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
-import { SelectionManagerService, SheetPermissionService } from '@univerjs/sheets';
+import { SelectionManagerService, SheetInterceptorService, SheetPermissionService } from '@univerjs/sheets';
import { DesktopMenuService, DesktopShortcutService, IMenuService, IShortcutService } from '@univerjs/ui';
import { Inject, Injector } from '@wendellhu/redi';
@@ -50,6 +50,7 @@ export function createMenuTestBed() {
injector.add([IShortcutService, { useClass: DesktopShortcutService }]);
injector.add([IMenuService, { useClass: DesktopMenuService }]);
injector.add([SheetPermissionService]);
+ injector.add([SheetInterceptorService]);
}
override onDestroy(): void {
diff --git a/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts b/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts
index 7591bed8a4..ecc8c1bc23 100644
--- a/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts
+++ b/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts
@@ -1,13 +1,6 @@
import type { IRange } from '@univerjs/core';
-import {
- Disposable,
- IUniverInstanceService,
- LifecycleStages,
- OnLifecycle,
- SheetInterceptorService,
- toDisposable,
-} from '@univerjs/core';
-import { SelectionManagerService } from '@univerjs/sheets';
+import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
+import { SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';
import type { IDisposable } from '@wendellhu/redi';
import { createIdentifier, Inject } from '@wendellhu/redi';
import type { Observable } from 'rxjs';
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index 0aa1faaa7f..f57430d947 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -1,6 +1,8 @@
-import type { IPosition, Nullable } from '@univerjs/core';
+import type { ICellData, IPosition, Nullable } from '@univerjs/core';
+import { createInterceptorKey, Disposable, InterceptorManager, toDisposable } from '@univerjs/core';
import type { IDocumentLayoutObject } from '@univerjs/engine-render';
import { DeviceInputEventType } from '@univerjs/engine-render';
+import type { ISheetLocation } from '@univerjs/sheets';
import type { KeyCode } from '@univerjs/ui';
import type { IDisposable } from '@wendellhu/redi';
import { createIdentifier } from '@wendellhu/redi';
@@ -25,10 +27,15 @@ export interface IEditorBridgeServiceParam {
scaleY: number;
editorUnitId: string;
}
-
+const BEFORE_CELL_EDIT = createInterceptorKey<ICellData, ISheetLocation>('BEFORE_CELL_EDIT');
+const AFTER_CELL_EDIT = createInterceptorKey<ICellData, ISheetLocation>('AFTER_CELL_EDIT');
export interface IEditorBridgeService {
state$: Observable<Nullable<IEditorBridgeServiceParam>>;
visible$: Observable<IEditorBridgeServiceVisibleParam>;
+ interceptor: InterceptorManager<{
+ BEFORE_CELL_EDIT: typeof BEFORE_CELL_EDIT;
+ AFTER_CELL_EDIT: typeof AFTER_CELL_EDIT;
+ }>;
dispose(): void;
setState(param: IEditorBridgeServiceParam): void;
getState(): Readonly<Nullable<IEditorBridgeServiceParam>>;
@@ -40,7 +47,7 @@ export interface IEditorBridgeService {
getCurrentEditorId(): Nullable<string>;
}
-export class EditorBridgeService implements IEditorBridgeService, IDisposable {
+export class EditorBridgeService extends Disposable implements IEditorBridgeService, IDisposable {
private _state: Nullable<IEditorBridgeServiceParam> = null;
private _isForceKeepVisible: boolean = false;
@@ -59,9 +66,36 @@ export class EditorBridgeService implements IEditorBridgeService, IDisposable {
private readonly _afterVisible$ = new BehaviorSubject<IEditorBridgeServiceVisibleParam>(this._visible);
readonly afterVisible$ = this._afterVisible$.asObservable();
- dispose(): void {
- this._state$.complete();
- this._state = null;
+ interceptor = new InterceptorManager({
+ BEFORE_CELL_EDIT,
+ AFTER_CELL_EDIT,
+ });
+
+ constructor() {
+ super();
+ this.disposeWithMe(
+ toDisposable(() => {
+ this._state$.complete();
+ this._state = null;
+ })
+ );
+ this.disposeWithMe(
+ toDisposable(
+ this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT, {
+ priority: -1,
+ handler: (_value) => _value,
+ })
+ )
+ );
+
+ this.disposeWithMe(
+ toDisposable(
+ this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT, {
+ priority: -1,
+ handler: (_value) => _value,
+ })
+ )
+ );
}
setState(param: IEditorBridgeServiceParam) {
diff --git a/packages/sheets/src/base-sheets-plugin.ts b/packages/sheets/src/base-sheets-plugin.ts
index 036c14b379..c34b0c3d76 100644
--- a/packages/sheets/src/base-sheets-plugin.ts
+++ b/packages/sheets/src/base-sheets-plugin.ts
@@ -11,6 +11,7 @@ import { INumfmtService } from './services/numfmt/type';
import { SheetPermissionService } from './services/permission';
import { RefRangeService } from './services/ref-range/ref-range.service';
import { SelectionManagerService } from './services/selection-manager.service';
+import { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
/**
* The main sheet base, construct the sheet container and layout, mount the rendering engine
@@ -43,6 +44,7 @@ export class SheetPlugin extends Plugin {
[RefRangeService],
[SheetPermissionService],
[INumfmtService, { useClass: NumfmtService }],
+ [SheetInterceptorService],
// controllers
[BasicWorksheetController],
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 9fd2723cf5..569cec0ed1 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
@@ -5,6 +5,7 @@ import { Inject, Injector } from '@wendellhu/redi';
import { BorderStyleManagerService } from '../../../services/border-style-manager.service';
import { SelectionManagerService } from '../../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../../services/sheet-interceptor/sheet-interceptor.service';
const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
id: 'test',
@@ -55,6 +56,7 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
override onStarting(injector: Injector): void {
injector.add([SelectionManagerService]);
injector.add([BorderStyleManagerService]);
+ injector.add([SheetInterceptorService]);
dependencies?.forEach((d) => injector.add(d));
}
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 d54a43e784..2a46e85fe5 100644
--- a/packages/sheets/src/commands/commands/clear-selection-all.command.ts
+++ b/packages/sheets/src/commands/commands/clear-selection-all.command.ts
@@ -6,11 +6,11 @@ import {
IUniverInstanceService,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.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';
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 e56dc643ec..5e2e075df7 100644
--- a/packages/sheets/src/commands/commands/clear-selection-content.command.ts
+++ b/packages/sheets/src/commands/commands/clear-selection-content.command.ts
@@ -6,11 +6,11 @@ import {
IUniverInstanceService,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.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';
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 8985fc9433..132996846f 100644
--- a/packages/sheets/src/commands/commands/clear-selection-format.command.ts
+++ b/packages/sheets/src/commands/commands/clear-selection-format.command.ts
@@ -6,11 +6,11 @@ import {
IUniverInstanceService,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.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';
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 08826e47a3..5c9a07f8d0 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
@@ -6,7 +6,6 @@ import {
IUndoRedoService,
IUniverInstanceService,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -15,6 +14,7 @@ import type {
IInsertRangeMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../mutations/delete-range.mutation';
import { InsertRangeMutation } from '../mutations/insert-range.mutation';
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 7cef762e5f..e488c02f86 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
@@ -6,7 +6,6 @@ import {
IUndoRedoService,
IUniverInstanceService,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -15,6 +14,7 @@ import type {
IInsertRangeMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../mutations/delete-range.mutation';
import { InsertRangeMutation } from '../mutations/insert-range.mutation';
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 da9f375ccd..1fc9e0839b 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
@@ -10,7 +10,6 @@ import {
ObjectArray,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -21,6 +20,7 @@ import type {
IRemoveRowsMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { DeleteRangeMutation } from '../mutations/delete-range.mutation';
import { InsertRangeMutation, InsertRangeUndoMutationFactory } from '../mutations/insert-range.mutation';
import { InsertRowMutation, InsertRowMutationUndoFactory } from '../mutations/insert-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 5c8d8843c4..6370eb5bf8 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
@@ -10,7 +10,6 @@ import {
ObjectArray,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -21,6 +20,7 @@ import type {
IRemoveColMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { DeleteRangeMutation } from '../mutations/delete-range.mutation';
import { InsertRangeMutation, InsertRangeUndoMutationFactory } from '../mutations/insert-range.mutation';
import { InsertColMutation, InsertColMutationUndoFactory } from '../mutations/insert-row-col.mutation';
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 640f39bd15..d322e307d1 100644
--- a/packages/sheets/src/commands/commands/insert-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/insert-row-col.command.ts
@@ -10,7 +10,6 @@ import {
ObjectArray,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -23,6 +22,7 @@ import type {
IRemoveRowsMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { DeleteRangeMutation } from '../mutations/delete-range.mutation';
import { InsertRangeMutation, InsertRangeUndoMutationFactory } from '../mutations/insert-range.mutation';
import {
diff --git a/packages/sheets/src/commands/commands/move-range.command.ts b/packages/sheets/src/commands/commands/move-range.command.ts
index daa60e848c..784e1b10f0 100644
--- a/packages/sheets/src/commands/commands/move-range.command.ts
+++ b/packages/sheets/src/commands/commands/move-range.command.ts
@@ -6,11 +6,11 @@ import {
IUniverInstanceService,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { NORMAL_SELECTION_PLUGIN_NAME } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import type { IMoveRangeMutationParams } from '../mutations/move-range.mutation';
import { MoveRangeMutation } from '../mutations/move-range.mutation';
import { SetSelectionsOperation } from '../operations/selection.operation';
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 98279ac9f8..b517547bf6 100644
--- a/packages/sheets/src/commands/commands/move-rows-cols.command.ts
+++ b/packages/sheets/src/commands/commands/move-rows-cols.command.ts
@@ -8,7 +8,6 @@ import {
RANGE_TYPE,
Rectangle,
sequenceExecute,
- SheetInterceptorService,
Tools,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -18,6 +17,7 @@ import type {
IRemoveWorksheetMergeMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { AddMergeUndoMutationFactory, AddWorksheetMergeMutation } from '../mutations/add-worksheet-merge.mutation';
import type { IMoveColumnsMutationParams, IMoveRowsMutationParams } from '../mutations/move-rows-cols.mutation';
import {
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 7e91ddc5a5..bf0e717bd8 100644
--- a/packages/sheets/src/commands/commands/remove-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/remove-row-col.command.ts
@@ -7,7 +7,6 @@ import {
IUniverInstanceService,
Rectangle,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -20,6 +19,7 @@ import type {
IRemoveRowsMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../mutations/delete-range.mutation';
import { InsertRangeMutation } from '../mutations/insert-range.mutation';
import { InsertColMutation, InsertRowMutation } from '../mutations/insert-row-col.mutation';
diff --git a/packages/sheets/src/commands/commands/remove-sheet.command.ts b/packages/sheets/src/commands/commands/remove-sheet.command.ts
index 22d42e6889..6b6169994f 100644
--- a/packages/sheets/src/commands/commands/remove-sheet.command.ts
+++ b/packages/sheets/src/commands/commands/remove-sheet.command.ts
@@ -5,7 +5,6 @@ import {
IUndoRedoService,
IUniverInstanceService,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -13,6 +12,7 @@ import type {
IInsertSheetMutationParams,
IRemoveSheetMutationParams,
} from '../../basics/interfaces/mutation-interface';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { InsertSheetMutation } from '../mutations/insert-sheet.mutation';
import { RemoveSheetMutation, RemoveSheetUndoMutationFactory } from '../mutations/remove-sheet.mutation';
import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';
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 0ebd0b2fe9..9fb573ec71 100644
--- a/packages/sheets/src/commands/commands/set-range-values.command.ts
+++ b/packages/sheets/src/commands/commands/set-range-values.command.ts
@@ -2,18 +2,18 @@ import type { ICellData, ICommand, IRange, ObjectMatrixPrimitiveType } from '@un
import {
CommandType,
ICommandService,
- INTERCEPTOR_POINT,
isICellData,
IUndoRedoService,
IUniverInstanceService,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
Tools,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { INTERCEPTOR_POINT } from '../../services/sheet-interceptor/interceptor-const';
+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';
diff --git a/packages/sheets/src/commands/commands/set-style.command.ts b/packages/sheets/src/commands/commands/set-style.command.ts
index 059797db2e..f373a6c4e6 100644
--- a/packages/sheets/src/commands/commands/set-style.command.ts
+++ b/packages/sheets/src/commands/commands/set-style.command.ts
@@ -19,12 +19,12 @@ import {
IUniverInstanceService,
ObjectMatrix,
sequenceExecute,
- SheetInterceptorService,
Tools,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.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';
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 bfa635ab6f..5844fb7e03 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
@@ -7,11 +7,11 @@ import {
RANGE_TYPE,
Rectangle,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import type { ISetWorksheetColWidthMutationParams } from '../mutations/set-worksheet-col-width.mutation';
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 b1fe352628..279a69c152 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
@@ -7,11 +7,11 @@ import {
RANGE_TYPE,
Rectangle,
sequenceExecute,
- SheetInterceptorService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import type {
ISetWorksheetRowHeightMutationParams,
ISetWorksheetRowIsAutoHeightMutationParams,
diff --git a/packages/sheets/src/controllers/merge-cell.controller.ts b/packages/sheets/src/controllers/merge-cell.controller.ts
index 9e426d1920..1c6e3b27ad 100644
--- a/packages/sheets/src/controllers/merge-cell.controller.ts
+++ b/packages/sheets/src/controllers/merge-cell.controller.ts
@@ -7,7 +7,6 @@ import {
LifecycleStages,
OnLifecycle,
Rectangle,
- SheetInterceptorService,
Tools,
} from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
@@ -47,6 +46,7 @@ import {
import { RefRangeService } from '../services/ref-range/ref-range.service';
import type { EffectRefRangeParams } from '../services/ref-range/type';
import { SelectionManagerService } from '../services/selection-manager.service';
+import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service';
@OnLifecycle(LifecycleStages.Steady, MergeCellController)
export class MergeCellController extends Disposable {
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index 5ece6992d7..a5e3c92c61 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -238,3 +238,6 @@ export {
handleMoveRange,
runRefRangeMutations,
} from './services/ref-range/util';
+export { INTERCEPTOR_POINT } from './services/sheet-interceptor/interceptor-const';
+export { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
+export type { ISheetLocation } from './services/sheet-interceptor/utils/interceptor';
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 3240a5ada2..0ce99d1306 100644
--- a/packages/sheets/src/services/__tests__/ref-range.setvice.spec.ts
+++ b/packages/sheets/src/services/__tests__/ref-range.setvice.spec.ts
@@ -1,5 +1,5 @@
import type { IRange, Univer, Workbook, Worksheet } from '@univerjs/core';
-import { ICommandService, IUniverInstanceService, SheetInterceptorService } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService } from '@univerjs/core';
import type { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -8,6 +8,7 @@ import { MoveRangeCommand } from '../../commands/commands/move-range.command';
import { MoveRangeMutation } from '../../commands/mutations/move-range.mutation';
import { RefRangeService } from '../ref-range/ref-range.service';
import { SelectionManagerService } from '../selection-manager.service';
+import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service';
import { createTestBase, TEST_WORKBOOK_DATA_DEMO } from './util';
const originRange: IRange = {
@@ -32,7 +33,11 @@ describe('Test ref-range.service', () => {
let worksheet: Worksheet;
beforeEach(() => {
- const testBed = createTestBase(TEST_WORKBOOK_DATA_DEMO, [[SelectionManagerService], [RefRangeService]]);
+ const testBed = createTestBase(TEST_WORKBOOK_DATA_DEMO, [
+ [SelectionManagerService],
+ [RefRangeService],
+ [SheetInterceptorService],
+ ]);
get = testBed.get;
univer = testBed.univer;
sheetInterceptorService = get(SheetInterceptorService);
diff --git a/packages/sheets/src/services/__tests__/sheet-permission.spec.ts b/packages/sheets/src/services/__tests__/sheet-permission.spec.ts
index 78c68cc216..699a94487b 100644
--- a/packages/sheets/src/services/__tests__/sheet-permission.spec.ts
+++ b/packages/sheets/src/services/__tests__/sheet-permission.spec.ts
@@ -8,6 +8,7 @@ import { SetRangeValuesCommand } from '../../commands/commands/set-range-values.
import { SetRangeValuesMutation } from '../../commands/mutations/set-range-values.mutation';
import { SheetEditablePermission, SheetPermissionService } from '../permission';
import { SelectionManagerService } from '../selection-manager.service';
+import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service';
import { createTestBase, TEST_WORKBOOK_DATA_DEMO } from './util';
describe('test sheet permission service', () => {
@@ -15,7 +16,11 @@ describe('test sheet permission service', () => {
let commandService: ICommandService;
let get: Injector['get'];
beforeEach(() => {
- const testBed = createTestBase(TEST_WORKBOOK_DATA_DEMO, [[SheetPermissionService], [SelectionManagerService]]);
+ const testBed = createTestBase(TEST_WORKBOOK_DATA_DEMO, [
+ [SheetPermissionService],
+ [SelectionManagerService],
+ [SheetInterceptorService],
+ ]);
get = testBed.get;
univer = testBed.univer;
commandService = testBed.get(ICommandService);
diff --git a/packages/sheets/src/services/permission/sheet-permission.service.ts b/packages/sheets/src/services/permission/sheet-permission.service.ts
index 698f0c76ee..e785ecfd26 100644
--- a/packages/sheets/src/services/permission/sheet-permission.service.ts
+++ b/packages/sheets/src/services/permission/sheet-permission.service.ts
@@ -2,12 +2,10 @@ import type { PermissionService } from '@univerjs/core';
import {
Disposable,
getTypeFromPermissionItemList,
- INTERCEPTOR_POINT,
IPermissionService,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
- SheetInterceptorService,
toDisposable,
UniverEditablePermissionPoint,
} from '@univerjs/core';
@@ -15,6 +13,8 @@ import { Inject } from '@wendellhu/redi';
import { map } from 'rxjs/operators';
import { SetRangeValuesCommand } from '../../commands/commands/set-range-values.command';
+import { INTERCEPTOR_POINT } from '../sheet-interceptor/interceptor-const';
+import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service';
import { SheetEditablePermission } from './permission-point';
@OnLifecycle(LifecycleStages.Ready, SheetPermissionService)
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 6ad41dd8fb..92ada0ab54 100644
--- a/packages/sheets/src/services/ref-range/ref-range.service.ts
+++ b/packages/sheets/src/services/ref-range/ref-range.service.ts
@@ -8,13 +8,13 @@ import {
OnLifecycle,
Rectangle,
remove,
- SheetInterceptorService,
toDisposable,
} from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';
import { Inject } from '@wendellhu/redi';
import { SelectionManagerService } from '../selection-manager.service';
+import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service';
import type { EffectRefRangeParams } from './type';
import { EffectRefRangId } from './type';
diff --git a/packages/core/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts b/packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts
similarity index 81%
rename from packages/core/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts
rename to packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts
index 5c8ec5f32d..62d985be17 100644
--- a/packages/core/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts
+++ b/packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts
@@ -1,13 +1,8 @@
+import type { IWorkbookData } from '@univerjs/core';
+import { ILogService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
-import { Univer } from '../../../basics/univer';
-import { Plugin, PluginType } from '../../../plugin/plugin';
-import { LocaleType } from '../../../types/enum/locale-type';
-import type { IWorkbookData } from '../../../types/interfaces/i-workbook-data';
-import { IUniverInstanceService } from '../../instance/instance.service';
-import { ILogService } from '../../log/log.service';
-
const TEST_WORKBOOK_DATA: IWorkbookData = {
id: 'test',
appVersion: '3.0.0-alpha',
@@ -50,6 +45,10 @@ export function createCoreTestBed(workbookConfig?: IWorkbookData, dependencies?:
get = this._injector.get.bind(_injector);
}
+ override onStarting(injector: Injector): void {
+ dependencies?.forEach((d) => injector.add(d));
+ }
+
override onDestroy(): void {
get = undefined;
}
diff --git a/packages/core/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts b/packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts
similarity index 85%
rename from packages/core/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts
rename to packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts
index 91c8d6ed54..39e6daeb95 100644
--- a/packages/core/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts
+++ b/packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts
@@ -1,15 +1,12 @@
/* eslint-disable no-magic-numbers */
+import type { ICellData, Nullable, Univer } from '@univerjs/core';
+import { createInterceptorKey, IUniverInstanceService } from '@univerjs/core';
import type { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import type { Univer } from '../../../basics/univer';
-import type { Nullable } from '../../../common/type-utils';
-import type { ICellData } from '../../../types/interfaces/i-cell-data';
-import { IUniverInstanceService } from '../../instance/instance.service';
import { INTERCEPTOR_POINT } from '../interceptor-const';
import { SheetInterceptorService } from '../sheet-interceptor.service';
import type { ISheetLocation } from '../utils/interceptor';
-import { createInterceptorKey } from '../utils/interceptor';
import { createCoreTestBed } from './create-core-test-bed';
describe('Test SheetInterceptorService', () => {
@@ -19,7 +16,7 @@ describe('Test SheetInterceptorService', () => {
const numberIntercept = createInterceptorKey<number, { step: number }>('numberIntercept');
beforeEach(() => {
- const testBed = createCoreTestBed();
+ const testBed = createCoreTestBed(undefined, [[SheetInterceptorService]]);
univer = testBed.univer;
get = testBed.get;
});
@@ -142,4 +139,17 @@ describe('Test SheetInterceptorService', () => {
expect(result).toBe('zero');
});
});
+
+ // it('Test SheetInterceptorService', () => {
+ // it('getLastRowWithContent', () => {
+ // const univerInstanceService = get(IUniverInstanceService);
+ // const sheet = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet()!;
+ // expect(sheet.getLastRowWithContent()).toBe(3);
+ // });
+ // it('getLastColumnWithContent', () => {
+ // const univerInstanceService = get(IUniverInstanceService);
+ // const sheet = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet()!;
+ // expect(sheet.getLastColumnWithContent()).toBe(3);
+ // });
+ // });
});
diff --git a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts b/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts
new file mode 100644
index 0000000000..989aa94a79
--- /dev/null
+++ b/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts
@@ -0,0 +1,12 @@
+import type { ICellData, ICommandInfo } from '@univerjs/core';
+import { createInterceptorKey } from '@univerjs/core';
+
+import type { ISheetLocation } from './utils/interceptor';
+
+const CELL_CONTENT = createInterceptorKey<ICellData, ISheetLocation>('CELL_CONTENT');
+const PERMISSION = createInterceptorKey<boolean, ICommandInfo>('PERMISSION');
+
+export const INTERCEPTOR_POINT = {
+ CELL_CONTENT,
+ PERMISSION,
+};
diff --git a/packages/core/src/services/sheet-interceptor/sheet-interceptor.service.ts b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts
similarity index 87%
rename from packages/core/src/services/sheet-interceptor/sheet-interceptor.service.ts
rename to packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts
index 69011f3226..5ece693f5b 100644
--- a/packages/core/src/services/sheet-interceptor/sheet-interceptor.service.ts
+++ b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts
@@ -1,18 +1,25 @@
+import type {
+ ICellData,
+ ICommandInfo,
+ IInterceptor,
+ IUndoRedoCommandInfos,
+ Nullable,
+ Workbook,
+ Worksheet,
+} from '@univerjs/core';
+import {
+ composeInterceptors,
+ Disposable,
+ DisposableCollection,
+ IUniverInstanceService,
+ LifecycleStages,
+ OnLifecycle,
+ remove,
+ toDisposable,
+} from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';
-import { remove } from '../../common/array';
-import type { Nullable } from '../../common/type-utils';
-import { Disposable, DisposableCollection, toDisposable } from '../../shared/lifecycle';
-import type { Workbook } from '../../sheets/workbook';
-import type { Worksheet } from '../../sheets/worksheet';
-import type { ICellData } from '../../types/interfaces/i-cell-data';
-import type { ICommandInfo } from '../command/command.service';
-import { IUniverInstanceService } from '../instance/instance.service';
-import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle';
-import type { IUndoRedoCommandInfos } from '../undoredo/undoredo.service';
import { INTERCEPTOR_POINT } from './interceptor-const';
-import type { IInterceptor } from './utils/interceptor';
-import { composeInterceptors } from './utils/interceptor';
export interface ICommandInterceptor {
priority?: number;
@@ -69,16 +76,6 @@ export class SheetInterceptorService extends Disposable {
priority: -1,
handler: () => true,
});
-
- this.intercept(INTERCEPTOR_POINT.BEFORE_CELL_EDIT, {
- priority: -1,
- handler: (_value) => _value,
- });
-
- this.intercept(INTERCEPTOR_POINT.AFTER_CELL_EDIT, {
- priority: -1,
- handler: (_value) => _value,
- });
}
override dispose(): void {
diff --git a/packages/sheets/src/services/sheet-interceptor/utils/interceptor.ts b/packages/sheets/src/services/sheet-interceptor/utils/interceptor.ts
new file mode 100644
index 0000000000..31245d2e52
--- /dev/null
+++ b/packages/sheets/src/services/sheet-interceptor/utils/interceptor.ts
@@ -0,0 +1,10 @@
+import type { Workbook, Worksheet } from '@univerjs/core';
+
+export interface ISheetLocation {
+ workbook: Workbook;
+ worksheet: Worksheet;
+ workbookId: string;
+ worksheetId: string;
+ row: number;
+ col: number;
+}