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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(sheet): group sheet get cell intercptor to performance well (#3534)
VicKunab97ea11c225
diff --git a/packages/core/src/common/interceptor.ts b/packages/core/src/common/interceptor.tsindex 1e11f22fdd..9c72672367 100644--- a/packages/core/src/common/interceptor.ts+++ b/packages/core/src/common/interceptor.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { Nullable } from '../shared/types';import { remove } from './array';+import type { Nullable } from '../shared/types';export type InterceptorHandler<M = unknown, C = unknown> = (value: Nullable<M>,@@ -23,11 +23,19 @@ export type InterceptorHandler<M = unknown, C = unknown> = (next: (value: Nullable<M>) => Nullable<M>) => Nullable<M>;+export enum InterceptorEffectEnum {+ Style = 1, // 1<< 0+ Value = 2, // 1<< 1+}export interface IInterceptor<M, C> {priority?: number;handler: InterceptorHandler<M, C>;}+export interface ICellInterceptor<M, C> extends IInterceptor<M, C> {+ effect?: InterceptorEffectEnum;+}+export function createInterceptorKey<T, C>(key: string): IInterceptor<T, C> {const symbol = `sheet_interceptor_${key}`;return symbol as unknown as IInterceptor<T, C>; // FIXME: priority and handler is completely missing?@@ -42,28 +50,35 @@ export type IComposeInterceptors<T = any, C = any> = (*/export const composeInterceptors = <T, C>(interceptors: Array<IInterceptor<T, C>>) =>- function (initialValue: T, context: C) {+ function (initialValue: Nullable<T>, context: C) {let index = -1;+ let value: Nullable<T> = initialValue;- function passThrough(- i: number,- v: Parameters<IInterceptor<T, C>['handler']>[0]- ): Parameters<IInterceptor<T, C>['handler']>[0] {+ for (let i = 0; i <= interceptors.length; i++) {if (i <= index) {throw new Error('[SheetInterceptorService]: next() called multiple times!');}index = i;+if (i === interceptors.length) {- return v;+ return value;}const interceptor = interceptors[i];+ let nextCalled = false;- return interceptor.handler!(v, context, passThrough.bind(null, i + 1));+ value = interceptor.handler!(value, context, (nextValue) => {+ nextCalled = true;+ return nextValue;+ });++ if (!nextCalled) {+ break;+ }}- return passThrough(0, initialValue);+ return value;} as ReturnType<IComposeInterceptors<T, C>>;export class InterceptorManager<P extends Record<string, IInterceptor<any, any>>> {diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 8932371933..27b468591f 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -32,8 +32,8 @@ export * from './common/di';export { shallowEqual } from './common/equal';export { CustomCommandExecutionError } from './common/error';export { throttle } from './common/function';-export type { IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';-export { composeInterceptors, createInterceptorKey, InterceptorManager } from './common/interceptor';+export type { ICellInterceptor, IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';+export { composeInterceptors, createInterceptorKey, InterceptorEffectEnum, InterceptorManager } from './common/interceptor';export type { Serializable } from './common/json';export { MemoryCursor } from './common/memory-cursor';export { mixinClass } from './common/mixin';diff --git a/packages/core/src/sheets/view-model.ts b/packages/core/src/sheets/view-model.tsindex f7596d8b8a..f4e8ab60e6 100644--- a/packages/core/src/sheets/view-model.ts+++ b/packages/core/src/sheets/view-model.ts@@ -14,8 +14,9 @@* limitations under the License.*/-import { Disposable, toDisposable } from '../shared/lifecycle';+import { InterceptorEffectEnum } from '../common/interceptor';+import { Disposable, toDisposable } from '../shared/lifecycle';import type { IDisposable } from '../common/di';import type { Nullable } from '../shared/types';import type { ICellData, ICellDataForSheetInterceptor } from './typedef';@@ -24,7 +25,7 @@ import type { ICellData, ICellDataForSheetInterceptor } from './typedef';* @internal*/export interface ICellContentInterceptor {- getCell: (row: number, col: number) => Nullable<ICellDataForSheetInterceptor>;+ getCell: (row: number, col: number, effect: InterceptorEffectEnum) => Nullable<ICellDataForSheetInterceptor>;}export interface IRowFilteredInterceptor {}@@ -71,7 +72,23 @@ export class SheetViewModel extends Disposable {getCell(row: number, col: number): Nullable<ICellDataForSheetInterceptor> {if (this._cellContentInterceptor) {- return this._cellContentInterceptor.getCell(row, col);+ return this._cellContentInterceptor.getCell(row, col, InterceptorEffectEnum.Value | InterceptorEffectEnum.Style);+ }++ return this.getRawCell(row, col);+ }++ getCellValueOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor> {+ if (this._cellContentInterceptor) {+ return this._cellContentInterceptor.getCell(row, col, InterceptorEffectEnum.Value);+ }++ return this.getRawCell(row, col);+ }++ getCellStyleOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor> {+ if (this._cellContentInterceptor) {+ return this._cellContentInterceptor.getCell(row, col, InterceptorEffectEnum.Style);}return this.getRawCell(row, col);diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.tsindex 958398e2b2..a9428b2d6c 100644--- a/packages/core/src/sheets/worksheet.ts+++ b/packages/core/src/sheets/worksheet.ts@@ -355,6 +355,34 @@ export class Worksheet {return this._viewModel.getCell(row, col);}+ /**+ * Get cellData only use effect on value interceptor+ * @param {number} number row The row index of the cell.+ * @param {number} number col The column index of the cell.+ * @returns {Nullable<ICellDataForSheetInterceptor>} The cell data only use effect on value interceptor+ */+ getCellValueOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor> {+ if (row < 0 || col < 0) {+ return null;+ }++ return this._viewModel.getCellValueOnly(row, col);+ }++ /**+ * Get cellData only use effect on style interceptor+ * @param {number} row The row index of the cell.+ * @param {number} col The column index of the cell.+ * @returns {Nullable<ICellDataForSheetInterceptor>} The cell data only use effect on style interceptor+ */+ getCellStyleOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor> {+ if (row < 0 || col < 0) {+ return null;+ }++ return this._viewModel.getCellStyleOnly(row, col);+ }+getCellRaw(row: number, col: number): Nullable<ICellData> {return this.getCellMatrix().getValue(row, col);}diff --git a/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.ts b/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.tsindex ce22f4b5f3..bac47256f7 100644--- a/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.ts+++ b/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.ts@@ -14,13 +14,13 @@* limitations under the License.*/-import type { ICellDataForSheetInterceptor, Workbook } from '@univerjs/core';-import { Disposable, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, Range, UniverInstanceType } from '@univerjs/core';+import { Disposable, Inject, InterceptorEffectEnum, IUniverInstanceService, LifecycleStages, OnLifecycle, Range, UniverInstanceType } from '@univerjs/core';+import { IRenderManagerService } from '@univerjs/engine-render';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';+import { ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingViewModel, DEFAULT_PADDING, DEFAULT_WIDTH } from '@univerjs/sheets-conditional-formatting';import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { bufferTime, filter } from 'rxjs/operators';-import { IRenderManagerService } from '@univerjs/engine-render';-import { ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingViewModel, DEFAULT_PADDING, DEFAULT_WIDTH } from '@univerjs/sheets-conditional-formatting';+import type { ICellDataForSheetInterceptor, Workbook } from '@univerjs/core';import type { IConditionalFormattingCellData, IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';@OnLifecycle(LifecycleStages.Starting, SheetsCfRenderController)@@ -228,6 +228,7 @@ export class SheetsCfRenderController extends Disposable {private _initViewModelInterceptor() {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ effect: InterceptorEffectEnum.Style,handler: (cell, context, next) => {const result = this._conditionalFormattingService.composeStyle(context.unitId, context.subUnitId, context.row, context.col);if (!result) {diff --git a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts b/packages/sheets-data-validation/src/controllers/dv-render.controller.tsindex cdfe472cae..ef7a3c6592 100644--- a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts+++ b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { DataValidationRenderMode, DataValidationStatus, DataValidationType, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, Optional, RxDisposable, sequenceExecute, UniverInstanceType, WrapStrategy } from '@univerjs/core';+import { DataValidationRenderMode, DataValidationStatus, DataValidationType, ICommandService, Inject, InterceptorEffectEnum, IUniverInstanceService, LifecycleStages, OnLifecycle, Optional, RxDisposable, sequenceExecute, UniverInstanceType, WrapStrategy } from '@univerjs/core';import { DataValidatorRegistryService } from '@univerjs/data-validation';import { IRenderManagerService } from '@univerjs/engine-render';import { InterceptCellContentPriority, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';@@ -162,6 +162,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT,{+ effect: InterceptorEffectEnum.Style,// must be after numfmtpriority: InterceptCellContentPriority.DATA_VALIDATION,// eslint-disable-next-line complexity@@ -322,6 +323,7 @@ export class SheetsDataValidationMobileRenderController extends RxDisposable {this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT,{+ effect: InterceptorEffectEnum.Style,priority: InterceptCellContentPriority.DATA_VALIDATION,// eslint-disable-next-line max-lines-per-function, complexityhandler: (cell, pos, next) => {diff --git a/packages/sheets-filter-ui/src/views/render-modules/sheets-filter.render-controller.ts b/packages/sheets-filter-ui/src/views/render-modules/sheets-filter.render-controller.tsindex d5b7f68448..cdab50f6b8 100644--- a/packages/sheets-filter-ui/src/views/render-modules/sheets-filter.render-controller.ts+++ b/packages/sheets-filter-ui/src/views/render-modules/sheets-filter.render-controller.ts@@ -14,18 +14,18 @@* limitations under the License.*/-import type { IDisposable, IRange, Workbook } from '@univerjs/core';-import { CommandType, fromCallback, ICommandService, Inject, Injector, RxDisposable, ThemeService } from '@univerjs/core';-import type { IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';-import type { ISelectionStyle, ISheetCommandSharedParams } from '@univerjs/sheets';+import { CommandType, fromCallback, ICommandService, Inject, Injector, InterceptorEffectEnum, RxDisposable, ThemeService } from '@univerjs/core';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';-import type { FilterModel } from '@univerjs/sheets-filter';import { FILTER_MUTATIONS, SheetsFilterService } from '@univerjs/sheets-filter';import { getCoordByCell, ISheetSelectionRenderService, SelectionShape, SheetSkeletonManagerService } from '@univerjs/sheets-ui';-import { filter, map, of, startWith, switchMap, takeUntil, throttleTime } from 'rxjs';-import type { ISheetsFilterButtonShapeProps } from '../widgets/filter-button.shape';+import type { IDisposable, IRange, Workbook } from '@univerjs/core';+import type { IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';+import type { ISelectionStyle, ISheetCommandSharedParams } from '@univerjs/sheets';++import type { FilterModel } from '@univerjs/sheets-filter';import { FILTER_ICON_PADDING, FILTER_ICON_SIZE, SheetsFilterButtonShape } from '../widgets/filter-button.shape';+import type { ISheetsFilterButtonShapeProps } from '../widgets/filter-button.shape';const DEFAULT_Z_INDEX = 1000;@@ -171,6 +171,7 @@ export class SheetsFilterRenderController extends RxDisposable implements IRendeprivate _interceptCellContent(workbookId: string, worksheetId: string, range: IRange): void {const { startRow, startColumn, endColumn } = range;this._buttonRenderDisposable = this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ effect: InterceptorEffectEnum.Style,handler: (cell, pos, next) => {const { row, col, unitId, subUnitId } = pos;if (diff --git a/packages/sheets-formula/src/controllers/array-formula-display.controller.ts b/packages/sheets-formula/src/controllers/array-formula-display.controller.tsindex 7df606cc36..61d49f3809 100644--- a/packages/sheets-formula/src/controllers/array-formula-display.controller.ts+++ b/packages/sheets-formula/src/controllers/array-formula-display.controller.ts@@ -14,11 +14,11 @@* limitations under the License.*/-import type { ICommandInfo } from '@univerjs/core';-import { CellValueType, Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, ThemeService } from '@univerjs/core';-import type { ISetArrayFormulaDataMutationParams } from '@univerjs/engine-formula';+import { CellValueType, Disposable, ICommandService, Inject, InterceptorEffectEnum, LifecycleStages, OnLifecycle, ThemeService } from '@univerjs/core';import { FormulaDataModel, SetArrayFormulaDataMutation, stripErrorMargin } from '@univerjs/engine-formula';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';+import type { ICommandInfo } from '@univerjs/core';+import type { ISetArrayFormulaDataMutationParams } from '@univerjs/engine-formula';@OnLifecycle(LifecycleStages.Ready, ArrayFormulaDisplayController)export class ArrayFormulaDisplayController extends Disposable {@@ -64,6 +64,7 @@ export class ArrayFormulaDisplayController extends Disposable {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {priority: 100,+ effect: InterceptorEffectEnum.Value,handler: (cell, location, next) => {const { unitId, subUnitId, row, col } = location;const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();diff --git a/packages/sheets-formula/src/controllers/formula-render.controller.ts b/packages/sheets-formula/src/controllers/formula-render.controller.tsindex 3b86041690..472e31344b 100644--- a/packages/sheets-formula/src/controllers/formula-render.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-render.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { Inject, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';+import { Inject, InterceptorEffectEnum, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';import { extractFormulaError } from './utils/utils';@@ -39,6 +39,7 @@ export class FormulaRenderManagerController extends RxDisposable {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT,{+ effect: InterceptorEffectEnum.Style,handler: (cell, pos, next) => {const errorType = extractFormulaError(cell);if (!errorType) {diff --git a/packages/sheets-hyper-link-ui/src/controllers/render-controllers/render.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/render-controllers/render.controller.tsindex 320d003bde..8b640dacc3 100644--- a/packages/sheets-hyper-link-ui/src/controllers/render-controllers/render.controller.ts+++ b/packages/sheets-hyper-link-ui/src/controllers/render-controllers/render.controller.ts@@ -14,14 +14,14 @@* limitations under the License.*/-import type { Workbook } from '@univerjs/core';-import { Disposable, Inject, LifecycleStages, OnLifecycle, ThemeService } from '@univerjs/core';-import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';-import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';-import type { IRenderContext, IRenderModule, Spreadsheet } from '@univerjs/engine-render';+import { Disposable, Inject, InterceptorEffectEnum, LifecycleStages, OnLifecycle, ThemeService } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';+import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';import { HyperLinkModel } from '@univerjs/sheets-hyper-link';+import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { debounceTime } from 'rxjs';+import type { Workbook } from '@univerjs/core';+import type { IRenderContext, IRenderModule, Spreadsheet } from '@univerjs/engine-render';export class SheetsHyperLinkRenderController extends Disposable implements IRenderModule {constructor(@@ -78,6 +78,8 @@ export class SheetsHyperLinkRenderManagerController extends Disposable {this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT,{+ effect: InterceptorEffectEnum.Value,+ priority: 100,handler: (cell, pos, next) => {const { row, col, unitId, subUnitId } = pos;const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);@@ -92,7 +94,6 @@ export class SheetsHyperLinkRenderManagerController extends Disposable {return next(cell);},- priority: 100,}));diff --git a/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.tsindex 6a46c92bd2..418bdedb3d 100644--- a/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.ts@@ -19,6 +19,7 @@ import {Disposable,ICommandService,Inject,+ InterceptorEffectEnum,IUniverInstanceService,LifecycleStages,LocaleService,@@ -37,7 +38,7 @@ import type {} from '@univerjs/core';import type { ISetNumfmtMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';-import { getPatternPreview } from '../utils/pattern';+import { getPatternPreviewIgnoreGeneral } from '../utils/pattern';@OnLifecycle(LifecycleStages.Rendered, SheetsNumfmtCellContentController)export class SheetsNumfmtCellContentController extends Disposable {@@ -57,10 +58,20 @@ export class SheetsNumfmtCellContentController extends Disposable {private _initInterceptorCellContent() {const renderCache = new ObjectMatrix<{ result: ICellData; parameters: string | number }>();this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,handler: (cell, location, next) => {const unitId = location.unitId;const sheetId = location.subUnitId;let numfmtValue;+ const originCellValue = cell;+ if (!originCellValue) {+ return next(cell);+ }++ // just handle number+ if (originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v)) {+ return next(cell);+ }if (cell?.s) {const style = location.workbook.getStyles().get(cell.s);@@ -75,15 +86,6 @@ export class SheetsNumfmtCellContentController extends Disposable {if (!numfmtValue) {return next(cell);}- const originCellValue = cell;- if (!originCellValue) {- return next(cell);- }-- // just handle number- if (originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v)) {- return next(cell);- }let numfmtRes: string = '';const cache = renderCache.getValue(location.row, location.col);@@ -91,7 +93,7 @@ export class SheetsNumfmtCellContentController extends Disposable {return next({ ...cell, ...cache.result });}- const info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());+ const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());numfmtRes = info.result;if (!numfmtRes) {return next(cell);diff --git a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.controller.tsindex 769f87d4f5..4da6949d25 100644--- a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts@@ -14,13 +14,13 @@* limitations under the License.*/-import type { IDisposable, IRange, Workbook } from '@univerjs/core';import {CellValueType,Disposable,DisposableCollection,ICommandService,Inject,+ InterceptorEffectEnum,IUniverInstanceService,LifecycleStages,LocaleService,@@ -31,7 +31,6 @@ import {UniverInstanceType,} from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';-import type { ISetNumfmtMutationParams } from '@univerjs/sheets';import {INTERCEPTOR_POINT,INumfmtService,@@ -40,23 +39,25 @@ import {SheetInterceptorService,SheetsSelectionsService,} from '@univerjs/sheets';+import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { ComponentManager, ISidebarService } from '@univerjs/ui';import { combineLatest, Observable } from 'rxjs';import { debounceTime, map, switchMap, tap } from 'rxjs/operators';+import type { IDisposable, IRange, Workbook } from '@univerjs/core';-import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';+import type { ISetNumfmtMutationParams } from '@univerjs/sheets';import { SHEET_NUMFMT_PLUGIN } from '../base/const/PLUGIN_NAME';import { AddDecimalCommand } from '../commands/commands/add-decimal.command';import { SetCurrencyCommand } from '../commands/commands/set-currency.command';-import type { ISetNumfmtCommandParams } from '../commands/commands/set-numfmt.command';import { SetNumfmtCommand } from '../commands/commands/set-numfmt.command';+import { SetPercentCommand } from '../commands/commands/set-percent.command';import { SubtractDecimalCommand } from '../commands/commands/subtract-decimal.command';import { CloseNumfmtPanelOperator } from '../commands/operations/close.numfmt.panel.operation';import { OpenNumfmtPanelOperator } from '../commands/operations/open.numfmt.panel.operation';-import type { ISheetNumfmtPanelProps } from '../components/index';import { SheetNumfmtPanel } from '../components/index';-import { getPatternPreview, getPatternType } from '../utils/pattern';-import { SetPercentCommand } from '../commands/commands/set-percent.command';+import { getPatternPreviewIgnoreGeneral, getPatternType } from '../utils/pattern';+import type { ISetNumfmtCommandParams } from '../commands/commands/set-numfmt.command';+import type { ISheetNumfmtPanelProps } from '../components/index';import type { INumfmtController } from './type';@OnLifecycle(LifecycleStages.Rendered, NumfmtController)@@ -245,6 +246,7 @@ export class NumfmtController extends Disposable implements INumfmtController {disposableCollection.add(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {priority: 99,+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,handler: (cell, location, next) => {const { row, col } = location;const defaultValue = next(cell) || {};@@ -268,7 +270,7 @@ export class NumfmtController extends Disposable implements INumfmtController {) {return defaultValue;}- const info = getPatternPreview(this._previewPattern, value as number, this._localeService.getCurrentLocale());+ const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value as number, this._localeService.getCurrentLocale());if (info.color) {const colorMap = this._themeService.getCurrentTheme();const color = colorMap[`${info.color}500`];diff --git a/packages/sheets-numfmt/src/utils/pattern.ts b/packages/sheets-numfmt/src/utils/pattern.tsindex 33642a0554..3ae4102197 100644--- a/packages/sheets-numfmt/src/utils/pattern.ts+++ b/packages/sheets-numfmt/src/utils/pattern.ts@@ -18,7 +18,12 @@ import { LocaleType, numfmt } from '@univerjs/core';import type { FormatType } from '@univerjs/sheets';export const getPatternType = (pattern: string): FormatType => numfmt.getInfo(pattern).type || 'unknown';-export const getPatternPreview = (pattern: string, value: number, _locale?: LocaleType) => {+interface IPatternPreview {+ result: string;+ color?: string;+}++export const getPatternPreview = (pattern: string, value: number, _locale?: LocaleType): IPatternPreview => {const info = numfmt.getInfo(pattern);const locale = _locale === LocaleType.ZH_CN ? 'zh-CN' : 'en';const negInfo = info._partitions[1];@@ -33,3 +38,12 @@ export const getPatternPreview = (pattern: string, value: number, _locale?: Locaresult,};};++export const getPatternPreviewIgnoreGeneral = (pattern: string, value: number, _locale?: LocaleType): IPatternPreview => {+ if (pattern === 'General') {+ return {+ result: String(value),+ };+ }+ return getPatternPreview(pattern, value, _locale);+};diff --git a/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts b/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.tsindex 026bda87bb..d0d3e55d3c 100644--- a/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts+++ b/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts@@ -14,14 +14,14 @@* limitations under the License.*/-import type { Workbook } from '@univerjs/core';-import { Disposable, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';-import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';-import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';-import type { Spreadsheet } from '@univerjs/engine-render';+import { Disposable, Inject, InterceptorEffectEnum, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';+import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';+import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { debounceTime } from 'rxjs';+import type { Workbook } from '@univerjs/core';+import type { Spreadsheet } from '@univerjs/engine-render';@OnLifecycle(LifecycleStages.Ready, SheetsThreadCommentRenderController)export class SheetsThreadCommentRenderController extends Disposable {@@ -41,6 +41,7 @@ export class SheetsThreadCommentRenderController extends Disposable {this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT,{+ effect: InterceptorEffectEnum.Style,handler: (cell, pos, next) => {const { row, col, unitId, subUnitId } = pos;if (this._sheetsThreadCommentModel.showCommentMarker(unitId, subUnitId, row, col)) {diff --git a/packages/sheets-ui/src/controllers/force-string-render.controller.ts b/packages/sheets-ui/src/controllers/force-string-render.controller.tsindex 4df2242670..2e67c15d66 100644--- a/packages/sheets-ui/src/controllers/force-string-render.controller.ts+++ b/packages/sheets-ui/src/controllers/force-string-render.controller.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import { CellValueType, Inject, isRealNum, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';-import type { Workbook } from '@univerjs/core';+import { CellValueType, Inject, InterceptorEffectEnum, isRealNum, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';+import type { Workbook } from '@univerjs/core';import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';@@ -47,6 +47,7 @@ export class ForceStringRenderController extends RxDisposable implements IRenderINTERCEPTOR_POINT.CELL_CONTENT,{priority: 10,+ effect: InterceptorEffectEnum.Style,handler: (cell, pos, next) => {const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton;if (!skeleton) {diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.tsindex 8e459c2cc8..ae626ba011 100644--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts@@ -14,14 +14,14 @@* limitations under the License.*/-import type { Workbook } from '@univerjs/core';-import { Disposable, IAuthzIoService, ICommandService, Inject, IPermissionService, IUndoRedoService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, UserManagerService } from '@univerjs/core';+import { Disposable, IAuthzIoService, ICommandService, Inject, InterceptorEffectEnum, IPermissionService, IUndoRedoService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, UserManagerService } from '@univerjs/core';+import { UnitAction, UnitObject } from '@univerjs/protocol';-import type { IAddRangeProtectionMutationParams, IAddWorksheetProtectionParams, IRangeProtectionRule, ISetWorksheetPermissionPointsMutationParams, IWorksheetProtectionRenderCellData } from '@univerjs/sheets';import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, defaultWorkbookPermissionPoints, defaultWorksheetPermissionPoint, getAllRangePermissionPoint, getAllWorkbookPermissionPoint, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel, INTERCEPTOR_POINT, RangeProtectionRenderModel, RangeProtectionRuleModel, SetWorksheetPermissionPointsMutation, SheetInterceptorService, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';import { IDialogService } from '@univerjs/ui';+import type { Workbook } from '@univerjs/core';-import { UnitAction, UnitObject } from '@univerjs/protocol';+import type { IAddRangeProtectionMutationParams, IAddWorksheetProtectionParams, IRangeProtectionRule, ISetWorksheetPermissionPointsMutationParams, IWorksheetProtectionRenderCellData } from '@univerjs/sheets';import type { IRangeProtectionRenderCellData } from '../../views/permission/extensions/range-protection.render';@@ -344,9 +344,14 @@ export class SheetPermissionInitController extends Disposable {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {// permissions are placed at a high level to prioritize whether to filter subsequent renderings.priority: 999,+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,handler: (cell = {}, context, next) => {const { unitId, subUnitId, row, col } = context;+ const length = this._rangeProtectionRuleModel.getSubunitRuleListLength(unitId, subUnitId);+ if (length === 0) {+ return next(cell);+ }const permissionList = this._selectionProtectionRenderModel.getCellInfo(unitId, subUnitId, row, col).filter((p) => !!p.ruleId).map((p) => {@@ -378,6 +383,7 @@ export class SheetPermissionInitController extends Disposable {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {// permissions are placed at a high level to prioritize whether to filter subsequent renderings.priority: 999,+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,handler: (cell = {}, context, next) => {const { unitId, subUnitId } = context;const worksheetRule = this._worksheetProtectionRuleModel.getRule(unitId, subUnitId);diff --git a/packages/sheets/src/controllers/number-cell.controller.ts b/packages/sheets/src/controllers/number-cell.controller.tsindex f93f9f30db..4a07ef8b90 100644--- a/packages/sheets/src/controllers/number-cell.controller.ts+++ b/packages/sheets/src/controllers/number-cell.controller.ts@@ -14,10 +14,10 @@* limitations under the License.*/-import { CellValueType, Disposable, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';+import { CellValueType, Disposable, Inject, InterceptorEffectEnum, LifecycleStages, OnLifecycle } from '@univerjs/core';import { stripErrorMargin } from '@univerjs/engine-formula';-import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service';import { INTERCEPTOR_POINT } from '../services/sheet-interceptor/interceptor-const';+import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service';@OnLifecycle(LifecycleStages.Ready, NumberCellDisplayController)export class NumberCellDisplayController extends Disposable {@@ -36,6 +36,7 @@ export class NumberCellDisplayController extends Disposable {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {priority: 11,+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,handler: (cell, location, next) => {// Skip if the cell contains a numfmt patternconst style = location.workbook.getStyles().getStyleByCell(cell);diff --git a/packages/sheets/src/model/range-protection-rule.model.ts b/packages/sheets/src/model/range-protection-rule.model.tsindex 5b2722348c..f6cd3db567 100644--- a/packages/sheets/src/model/range-protection-rule.model.ts+++ b/packages/sheets/src/model/range-protection-rule.model.ts@@ -14,9 +14,9 @@* limitations under the License.*/+import { LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';import { BehaviorSubject, Subject } from 'rxjs';import type { IRange } from '@univerjs/core';-import { LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';import type { UnitObject } from '@univerjs/protocol';@@ -103,6 +103,11 @@ export class RangeProtectionRuleModel {return [...map.values()] as IRangeProtectionRule[];}+ getSubunitRuleListLength(unitId: string, subUnitId: string) {+ const map = this._model.get(unitId)?.get(subUnitId);+ return map ? map.size : 0;+ }+private _ensureRuleMap(unitId: string, subUnitId: string) {let subUnitMap = this._model.get(unitId);if (!subUnitMap) {diff --git a/packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts b/packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.tsindex 6db7423bc3..0586954550 100644--- a/packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts+++ b/packages/sheets/src/services/sheet-interceptor/__tests__/sheet-interceptor.service.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { createInterceptorKey, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';+import { createInterceptorKey, InterceptorEffectEnum, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';@@ -58,6 +58,7 @@ describe('Test SheetInterceptorService', () => {describe('Test intercepting getting cell content', () => {it('should intercept cells and merge result if next is called', () => {get(SheetInterceptorService).intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,priority: 100,handler(_cell, location: ISheetLocation, next: (v: Nullable<ICellData>) => Nullable<ICellData>) {if (location.row === 0 && location.col === 0) {@@ -75,6 +76,7 @@ describe('Test SheetInterceptorService', () => {it('interceptors should directly return result if next is not called', () => {get(SheetInterceptorService).intercept(INTERCEPTOR_POINT.CELL_CONTENT, {priority: 100,+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,handler(_cell, location: ISheetLocation, next: (v: Nullable<ICellData>) => Nullable<ICellData>) {if (location.row === 0 && location.col === 0) {return { v: 'intercepted' };diff --git a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts b/packages/sheets/src/services/sheet-interceptor/interceptor-const.tsindex 0cb2ff09d1..b7972aaa6b 100644--- a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts+++ b/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import type { ICellDataForSheetInterceptor } from '@univerjs/core';import { createInterceptorKey } from '@univerjs/core';+import type { ICellDataForSheetInterceptor, ICellInterceptor } from '@univerjs/core';import type { ISheetLocation, ISheetRowLocation } from './utils/interceptor';-const CELL_CONTENT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('CELL_CONTENT');+const CELL_CONTENT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('CELL_CONTENT') as ICellInterceptor<ICellDataForSheetInterceptor, ISheetLocation>;const ROW_FILTERED = createInterceptorKey<boolean, ISheetRowLocation>('ROW_FILTERED');export const INTERCEPTOR_POINT = {diff --git a/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.tsindex 379a384ff2..a211e1dec0 100644--- a/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts+++ b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts@@ -14,8 +14,19 @@* limitations under the License.*/+import {+ composeInterceptors,+ Disposable,+ DisposableCollection,+ InterceptorEffectEnum,+ IUniverInstanceService,+ remove,+ toDisposable,+ UniverInstanceType,+} from '@univerjs/core';import type {ICellData,+ ICellInterceptor,ICommandInfo,IDisposable,IInterceptor,@@ -25,15 +36,6 @@ import type {Workbook,Worksheet,} from '@univerjs/core';-import {- composeInterceptors,- Disposable,- DisposableCollection,- IUniverInstanceService,- remove,- toDisposable,- UniverInstanceType,-} from '@univerjs/core';import { INTERCEPTOR_POINT } from './interceptor-const';@@ -88,6 +90,7 @@ export class SheetInterceptorService extends Disposable {// register default viewModel interceptorthis.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {priority: -1,+ effect: InterceptorEffectEnum.Style | InterceptorEffectEnum.Value,handler(value, context): Nullable<ICellData> {const rawData = context.worksheet.getCellRaw(context.row, context.col);if (value) {@@ -191,17 +194,34 @@ export class SheetInterceptorService extends Disposable {}const interceptors = this._interceptorsByName.get(key)!;interceptors.push(interceptor);-- this._interceptorsByName.set(- key,- interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))- );+ const sortedInterceptors = interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));++ if (key === INTERCEPTOR_POINT.CELL_CONTENT as unknown as string) {+ this._interceptorsByName.set(+ `${key}-${(InterceptorEffectEnum.Style | InterceptorEffectEnum.Value)}`,+ sortedInterceptors+ );+ // 3 means both style and value+ this._interceptorsByName.set(+ `${key}-${(InterceptorEffectEnum.Style)}`,+ (sortedInterceptors as ICellInterceptor<unknown, unknown>[]).filter((i) => ((i.effect || 3) & InterceptorEffectEnum.Style) > 0)+ );+ this._interceptorsByName.set(+ `${key}-${(InterceptorEffectEnum.Value)}`,+ (sortedInterceptors as ICellInterceptor<unknown, unknown>[]).filter((i) => ((i.effect || 3) & InterceptorEffectEnum.Value) > 0)+ );+ } else {+ this._interceptorsByName.set(+ key,+ sortedInterceptors+ );+ }return this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key)!, interceptor)));}- fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>) {- const key = name as unknown as string;+ fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>, effect?: InterceptorEffectEnum) {+ const key = effect === undefined ? name as unknown as string : `${name as unknown as string}-${effect}`;const interceptors = this._interceptorsByName.get(key) as unknown as Array<typeof name>;return composeInterceptors<T, C>(interceptors || []);}@@ -219,8 +239,8 @@ export class SheetInterceptorService extends Disposable {sheetInterceptorService._worksheetDisposables.set(getWorksheetDisposableID(unitId, worksheet), sheetDisposables);sheetDisposables.add(viewModel.registerCellContentInterceptor({- getCell(row: number, col: number): Nullable<ICellData> {- return sheetInterceptorService.fetchThroughInterceptors(INTERCEPTOR_POINT.CELL_CONTENT)(+ getCell(row: number, col: number, effect: InterceptorEffectEnum): Nullable<ICellData> {+ return sheetInterceptorService.fetchThroughInterceptors(INTERCEPTOR_POINT.CELL_CONTENT, effect)(worksheet.getCellRaw(row, col),{unitId,