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
fix: fix multi memory leak problems (#4591)
Wenzhao Hu3dc94a97697a
diff --git a/packages/drawing-ui/src/controllers/image-cropper.controller.ts b/packages/drawing-ui/src/controllers/image-cropper.controller.tsindex 6a5a586f63..b78b2b70ec 100644--- a/packages/drawing-ui/src/controllers/image-cropper.controller.ts+++ b/packages/drawing-ui/src/controllers/image-cropper.controller.ts@@ -23,7 +23,7 @@ import { MessageType } from '@univerjs/design';import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, SetDrawingSelectedOperation } from '@univerjs/drawing';import { CURSOR_TYPE, degToRad, Image, IRenderManagerService, precisionTo, Vector2 } from '@univerjs/engine-render';import { IMessageService } from '@univerjs/ui';-import { filter, switchMap } from 'rxjs';+import { of, switchMap } from 'rxjs';import { AutoImageCropOperation, CloseImageCropOperation, CropType, OpenImageCropOperation } from '../commands/operations/image-crop.operation';import { ImageCropperObject } from '../views/crop/image-cropper-object';@@ -334,14 +334,14 @@ export class ImageCropperController extends Disposable {imageCropperObject?.dispose();}));- const sheetUnit = this._univerInstanceService++ const sheetUnit$ = this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(- filter((workbook) => Boolean(workbook)),- switchMap((workbook) => workbook!.activeSheet$)+ switchMap((workbook) => workbook ? workbook.activeSheet$ : of(null)));- this.disposeWithMe(sheetUnit.subscribe(() => {+ this.disposeWithMe(sheetUnit$.subscribe(() => {this._commandService.syncExecuteCommand(CloseImageCropOperation.id);}));}diff --git a/packages/engine-render/src/render-manager/render-unit.ts b/packages/engine-render/src/render-manager/render-unit.tsindex 31d9c6e1b2..8a037145b3 100644--- a/packages/engine-render/src/render-manager/render-unit.ts+++ b/packages/engine-render/src/render-manager/render-unit.ts@@ -128,15 +128,6 @@ export class RenderUnit extends Disposable implements IRender {this._activated$.next(false);this._activated$.complete();-- // Avoid memory leak. Basically it is because RenderUnit itself is leaking.- // We use this as a temporary solution to make CI pass.- // @ts-ignore- this._renderContext.activated$ = null;- // @ts-ignore- this._renderContext.activate = null;- // @ts-ignore- this._renderContext.deactivate = null;}/**diff --git a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.tsindex c22c36ad18..a9af3ef6b9 100644--- a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts+++ b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts@@ -28,7 +28,7 @@ import { COMMAND_LISTENER_SKELETON_CHANGE, getSheetCommandTarget, SetFrozenMutatimport { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';import { ISheetSelectionRenderService, SetScrollOperation, SetZoomRatioOperation, SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { CanvasFloatDomService } from '@univerjs/ui';-import { BehaviorSubject, filter, map, Subject, switchMap, take } from 'rxjs';+import { BehaviorSubject, filter, map, of, Subject, switchMap, take } from 'rxjs';import { InsertSheetDrawingCommand } from '../commands/commands/insert-sheet-drawing.command';export interface ICanvasFloatDom {@@ -556,22 +556,27 @@ export class SheetCanvasFloatDomManagerService extends Disposable {// #region scrollthis.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(- filter((workbook) => !!workbook),- switchMap((workbook) => workbook.activeSheet$),- filter((sheet) => !!sheet),- map((sheet) => {- const render = this._renderManagerService.getRenderById(sheet.getUnitId());- return render ? { render, unitId: sheet.getUnitId(), subUnitId: sheet.getSheetId() } : null;+ switchMap((workbook) => workbook ? workbook.activeSheet$ : of(null)),+ map((worksheet) => {+ if (!worksheet) return null;+ const unitId = worksheet.getUnitId();+ const render = this._renderManagerService.getRenderById(unitId);+ return render ? { render, unitId, subUnitId: worksheet.getSheetId() } : null;}),- filter((render) => !!render),switchMap((render) =>- fromEventSubject(render.render.scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN)!.onScrollAfter$)- .pipe(map(() => ({ unitId: render.unitId, subUnitId: render.subUnitId })))+ render+ ? fromEventSubject(render.render.scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN)!.onScrollAfter$)+ .pipe(map(() => ({ unitId: render.unitId, subUnitId: render.subUnitId })))+ : of(null))- ).subscribe(({ unitId, subUnitId }) => {+ ).subscribe((value) => {+ if (!value) return; // TODO@weird94: maybe we should throw an error here and do some cleaning work?++ const { unitId, subUnitId } = value;updateSheet(unitId, subUnitId);}));+//#endregion// #region zoomdiff --git a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts b/packages/sheets-filter/src/controllers/sheets-filter.controller.tsindex 9157af4068..eecb6e5b74 100644--- a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts+++ b/packages/sheets-filter/src/controllers/sheets-filter.controller.ts@@ -199,7 +199,7 @@ export class SheetsFilterController extends Disposable {const filterColumn = filterModel.getAllFilterColumns();const effected = filterColumn.filter((column) => column[0] >= anchor);if (effected.length !== 0) {- const { newRange, oldRange } = this.moveCriteria(unitId, subUnitId, effected, count);+ const { newRange, oldRange } = this._moveCriteria(unitId, subUnitId, effected, count);redos.push(...newRange.redos, ...oldRange.redos);undos.push(...newRange.undos, ...oldRange.undos);}@@ -281,7 +281,7 @@ export class SheetsFilterController extends Disposable {let newRangeCriteria: { undos: IMutationInfo[]; redos: IMutationInfo[] } = { undos: [], redos: [] };if (shifted.length > 0) {- const { oldRange, newRange } = this.moveCriteria(unitId, subUnitId, shifted, -removeCount);+ const { oldRange, newRange } = this._moveCriteria(unitId, subUnitId, shifted, -removeCount);newRangeCriteria = newRange;redos.push(...oldRange.redos);undos.unshift(...oldRange.undos);@@ -693,7 +693,7 @@ export class SheetsFilterController extends Disposable {}));}- private moveCriteria(unitId: string, subUnitId: string, target: [number, FilterColumn][], step: number) {+ private _moveCriteria(unitId: string, subUnitId: string, target: [number, FilterColumn][], step: number) {const defaultSetCriteriaMutationParams: ISetSheetsFilterCriteriaMutationParams = {unitId,subUnitId,diff --git a/packages/sheets-filter/src/models/filter-model.ts b/packages/sheets-filter/src/models/filter-model.tsindex bf8c940647..3de2a8471c 100644--- a/packages/sheets-filter/src/models/filter-model.ts+++ b/packages/sheets-filter/src/models/filter-model.ts@@ -16,10 +16,11 @@import type { CellValue, ICellData, IRange, Nullable, Worksheet } from '@univerjs/core';import type { Observable } from 'rxjs';+import type { IAutoFilter, ICustomFilter, ICustomFilters, IFilterColumn, IFilters } from './types';import { CellValueType, Disposable, extractPureTextFromCell, mergeSets, Rectangle, Tools } from '@univerjs/core';import { BehaviorSubject } from 'rxjs';import { ensureNumeric, getCustomFilterFn, isNumericFilterFn, notEquals } from './custom-filters';-import { CustomFilterOperator, type IAutoFilter, type ICustomFilter, type ICustomFilters, type IFilterColumn, type IFilters } from './types';+import { CustomFilterOperator } from './types';const EMPTY = () => new Set<number>();diff --git a/packages/sheets-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-ui/src/controllers/auto-fill.controller.tsindex c91600a23d..90474d3749 100644--- a/packages/sheets-ui/src/controllers/auto-fill.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-fill.controller.ts@@ -40,7 +40,6 @@ import {IUniverInstanceService,ObjectMatrix,Rectangle,- toDisposable,Tools,UniverInstanceType,} from '@univerjs/core';@@ -113,7 +112,7 @@ export class AutoFillController extends Disposable {private _init() {this._initDefaultHook();- this._onSelectionControlFillChanged();+ this._initSelectionControlFillChanged();this._initQuitListener();this._initSkeletonChange();}@@ -179,11 +178,10 @@ export class AutoFillController extends Disposable {this._autoFillService.setShowMenu(false);}- // eslint-disable-next-line max-lines-per-function- private _onSelectionControlFillChanged() {+ private _initSelectionControlFillChanged() {const disposableCollection = new DisposableCollection();- const addListener = (disposableCollection: DisposableCollection) => {- // Each range change requires re-listening+ const updateListener = () => {+ // Each range change requires re-listening.disposableCollection.dispose();const currentRenderer = this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET);@@ -192,78 +190,69 @@ export class AutoFillController extends Disposable {const selectionRenderService = currentRenderer.with(ISheetSelectionRenderService);const selectionControls = selectionRenderService.getSelectionControls();selectionControls.forEach((controlSelection) => {- disposableCollection.add(- toDisposable(- controlSelection.selectionFilled$.subscribe((filled) => {- if (- filled == null ||+ disposableCollection.add(controlSelection.selectionFilled$.subscribe((filled) => {+ if (+ filled == null ||filled.startColumn === -1 ||filled.startRow === -1 ||filled.endColumn === -1 ||filled.endRow === -1- ) {- return;- }- const source: IRange = {- startColumn: controlSelection.model.startColumn,- endColumn: controlSelection.model.endColumn,- startRow: controlSelection.model.startRow,- endRow: controlSelection.model.endRow,- };- const selection: IRange = {- startColumn: filled.startColumn,- endColumn: filled.endColumn,- startRow: filled.startRow,- endRow: filled.endRow,- };-- this._commandService.executeCommand(AutoFillCommand.id, { sourceRange: source, targetRange: selection });- })- )- );+ ) {+ return;+ }+ const source: IRange = {+ startColumn: controlSelection.model.startColumn,+ endColumn: controlSelection.model.endColumn,+ startRow: controlSelection.model.startRow,+ endRow: controlSelection.model.endRow,+ };+ const selection: IRange = {+ startColumn: filled.startColumn,+ endColumn: filled.endColumn,+ startRow: filled.startRow,+ endRow: filled.endRow,+ };++ this._commandService.executeCommand(AutoFillCommand.id, { sourceRange: source, targetRange: selection });+ }));// double click to fill range, range length will align to left or right column.// fill results will be as same as drag operation- disposableCollection.add(- toDisposable(- controlSelection.fillControl.onDblclick$.subscribeEvent(() => {- const source = {- startColumn: controlSelection.model.startColumn,- endColumn: controlSelection.model.endColumn,- startRow: controlSelection.model.startRow,- endRow: controlSelection.model.endRow,- };- this._handleDbClickFill(source);- })- )- );-- disposableCollection.add(- toDisposable(- controlSelection.fillControl.onPointerDown$.subscribeEvent(() => {- const visibleState = this._editorBridgeService.isVisible();- if (visibleState.visible) {- this._editorBridgeService.changeVisible({- visible: false,- eventType: DeviceInputEventType.PointerDown,- unitId: currentRenderer.unitId,- });- }- })- )- );+ disposableCollection.add(controlSelection.fillControl.onDblclick$.subscribeEvent(() => {+ const source = {+ startColumn: controlSelection.model.startColumn,+ endColumn: controlSelection.model.endColumn,+ startRow: controlSelection.model.startRow,+ endRow: controlSelection.model.endRow,+ };+ this._handleDbClickFill(source);+ }));++ disposableCollection.add(controlSelection.fillControl.onPointerDown$.subscribeEvent(() => {+ const visibleState = this._editorBridgeService.isVisible();+ if (visibleState.visible) {+ this._editorBridgeService.changeVisible({+ visible: false,+ eventType: DeviceInputEventType.PointerDown,+ unitId: currentRenderer.unitId,+ });+ }+ }));});};- addListener(disposableCollection);+ updateListener();- this.disposeWithMe(- this._commandService.onCommandExecuted((command: ICommandInfo) => {- if (command.id === SetSelectionsOperation.id) {- addListener(disposableCollection);- }- })- );+ // Should subscribe current current renderer change as well.+ // TODO@yuhongz: this seems not ideal. This should be an `IRenderModule` for running with multiple renderers?+ this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => {+ if (command.id === SetSelectionsOperation.id) {+ updateListener();+ }+ }));++ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET)+ .subscribe(() => updateListener()));}private _handleDbClickFill(source: IRange) {diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.tsindex 59e9ec029b..94a24e5ac7 100644--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts@@ -913,6 +913,7 @@ export class SheetClipboardController extends RxDisposable {if (sheetsUIConfig?.clipboardConfig?.hidePasteOptions) {return;}+this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(ClipboardPopupMenu, this._injector)));diff --git a/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.ts b/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.tsindex a8ce5da6c8..334a201629 100644--- a/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.ts+++ b/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.ts@@ -30,13 +30,9 @@ import {} from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';import { AddMergeUndoMutationFactory, AddWorksheetMergeMutation, getAddMergeMutationRangeByType, RemoveMergeUndoMutationFactory, RemoveWorksheetMergeMutation, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';-import {- ApplyFormatPainterCommand,- SetOnceFormatPainterCommand,-} from '../../commands/commands/set-format-painter.command';+import { checkCellContentInRanges, getClearContentMutationParamsForRanges } from '../../common/utils';import { FormatPainterStatus, IFormatPainterService } from '../../services/format-painter/format-painter.service';-import { ISheetSelectionRenderService } from '../../services/selection/base-selection-render.service';export class FormatPainterController extends Disposable {constructor(@@ -54,40 +50,9 @@ export class FormatPainterController extends Disposable {}private _initialize() {- this._commandExecutedListener();this._addDefaultHook();}- private _commandExecutedListener() {- const unitId = this._univerInstanceService.getFocusedUnit()?.getUnitId() || '';- const renderUnit = this._renderManagerService.getRenderById(unitId);- if (!renderUnit) return;- const selectionRenderService = renderUnit.with(ISheetSelectionRenderService);-- this.disposeWithMe(- selectionRenderService.selectionMoveEnd$.subscribe((selections) => {- if (this._formatPainterService.getStatus() !== FormatPainterStatus.OFF) {- const { rangeWithCoord } = selections[selections.length - 1];- this._commandService.executeCommand(ApplyFormatPainterCommand.id, {- unitId: this._univerInstanceService.getFocusedUnit()?.getUnitId() || '',- subUnitId: (this._univerInstanceService.getFocusedUnit() as Workbook).getActiveSheet()?.getSheetId() || '',- range: {- startRow: rangeWithCoord.startRow,- startColumn: rangeWithCoord.startColumn,- endRow: rangeWithCoord.endRow,- endColumn: rangeWithCoord.endColumn,- },- });-- // if once, turn off the format painter- if (this._formatPainterService.getStatus() === FormatPainterStatus.ONCE) {- this._commandService.executeCommand(SetOnceFormatPainterCommand.id);- }- }- })- );- }-private _addDefaultHook() {const defaultHook: IFormatPainterHook = {id: 'default-format-painter',diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.tsindex 5271e9fa81..3817cb0755 100644--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts@@ -16,6 +16,7 @@import type { IRenderContext, IRenderModule, Spreadsheet } from '@univerjs/engine-render';import type { MenuConfig } from '@univerjs/ui';+import type { IUniverSheetsUIConfig } from '../config.schema';import { connectInjector, Disposable, IConfigService, Inject, Injector, IPermissionService, IUniverInstanceService } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';import { CheckMarkSingle, DeleteSingle, LockSingle, ProtectSingle, WriteSingle } from '@univerjs/icons';@@ -30,7 +31,7 @@ import { UNIVER_SHEET_PERMISSION_ALERT_DIALOG } from '../../views/permission/errimport { RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY, RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY, RangeProtectionCanNotViewRenderExtension, RangeProtectionCanViewRenderExtension } from '../../views/permission/extensions/range-protection.render';import { worksheetProtectionKey, WorksheetProtectionRenderExtension } from '../../views/permission/extensions/worksheet-permission.render';import { PermissionDetailUserPart } from '../../views/permission/panel-detail/PermissionDetailUserPart';-import { type IUniverSheetsUIConfig, SHEETS_UI_PLUGIN_CONFIG_KEY } from '../config.schema';+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../config.schema';export interface IUniverSheetsPermissionMenuConfig {menu: MenuConfig;@@ -99,14 +100,14 @@ export class SheetPermissionRenderController extends Disposable implements IRendthis._initRender();this._initSkeleton();- this._rangeProtectionRuleModel.ruleChange$.subscribe((info) => {+ this.disposeWithMe(this._rangeProtectionRuleModel.ruleChange$.subscribe((info) => {if ((info.oldRule?.id && this._rangeProtectionCanViewRenderExtension.renderCache.has(info.oldRule.id)) || this._rangeProtectionCanViewRenderExtension.renderCache.has(info.rule.id)) {this._rangeProtectionCanViewRenderExtension.clearCache();}if ((info.oldRule?.id && this._rangeProtectionCanNotViewRenderExtension.renderCache.has(info.oldRule.id)) || this._rangeProtectionCanNotViewRenderExtension.renderCache.has(info.rule.id)) {this._rangeProtectionCanNotViewRenderExtension.clearCache();}- });+ }));}private _initRender(): void {diff --git a/packages/sheets-ui/src/controllers/render-controllers/format-painter.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/format-painter.render-controller.tsindex b57327d01d..4cd04755cd 100644--- a/packages/sheets-ui/src/controllers/render-controllers/format-painter.render-controller.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/format-painter.render-controller.ts@@ -15,19 +15,24 @@*/import type { Workbook } from '@univerjs/core';+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';import {Disposable,+ ICommandService,toDisposable,} from '@univerjs/core';-import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';import { CURSOR_TYPE } from '@univerjs/engine-render';+import { ApplyFormatPainterCommand, SetOnceFormatPainterCommand } from '../../commands/commands/set-format-painter.command';import { FormatPainterStatus, IFormatPainterService } from '../../services/format-painter/format-painter.service';+import { ISheetSelectionRenderService } from '../../services/selection/base-selection-render.service';export class FormatPainterRenderController extends Disposable implements IRenderModule {constructor(private readonly _context: IRenderContext<Workbook>,- @IFormatPainterService private readonly _formatPainterService: IFormatPainterService+ @IFormatPainterService private readonly _formatPainterService: IFormatPainterService,+ @ISheetSelectionRenderService private readonly _selectionRenderService: ISheetSelectionRenderService,+ @ICommandService private readonly _commandService: ICommandService) {super();this._initialize();@@ -35,6 +40,32 @@ export class FormatPainterRenderController extends Disposable implements IRenderprivate _initialize() {this._bindFormatPainterStatus();+ this._commandExecutedListener();+ }++ private _commandExecutedListener() {+ this.disposeWithMe(this._selectionRenderService.selectionMoveEnd$.subscribe((selections) => {+ if (this._formatPainterService.getStatus() !== FormatPainterStatus.OFF) {+ const { rangeWithCoord } = selections[selections.length - 1];+ this._commandService.executeCommand(ApplyFormatPainterCommand.id, {+ unitId: this._context.unitId,+ subUnitId: this._context.unit.getActiveSheet()?.getSheetId() || '',+ range: {+ startRow: rangeWithCoord.startRow,+ startColumn: rangeWithCoord.startColumn,+ endRow: rangeWithCoord.endRow,+ endColumn: rangeWithCoord.endColumn,+ },+ });++ // if once, turn off the format painter+ if (this._formatPainterService.getStatus() === FormatPainterStatus.ONCE) {+ this._commandService.executeCommand(SetOnceFormatPainterCommand.id);+ }+ }+ })++ );}private _bindFormatPainterStatus() {diff --git a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.tsindex 28ba3b57c0..da0d74f5f1 100644--- a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts+++ b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts@@ -67,8 +67,9 @@ export class SheetSkeletonManagerService extends Disposable implements IRenderMothis.disposeWithMe(() => {this._currentSkeletonBefore$.complete();this._currentSkeleton$.complete();- this._sheetSkeletonParamStore = new Map();- this._sheetSkService.deleteSkeleton(this._context.unitId, this._sheetId);++ this._sheetSkeletonParamStore.forEach((sk) => this.disposeSkeleton(sk.sheetId));+ this._sheetSkeletonParamStore.clear();});this._initRemoveSheet();diff --git a/packages/sheets-ui/src/views/clipboard/ClipboardPopupMenu.tsx b/packages/sheets-ui/src/views/clipboard/ClipboardPopupMenu.tsxindex c706ba7c4b..654a73a75f 100644--- a/packages/sheets-ui/src/views/clipboard/ClipboardPopupMenu.tsx+++ b/packages/sheets-ui/src/views/clipboard/ClipboardPopupMenu.tsx@@ -22,7 +22,7 @@ import { DropdownOverlay, DropdownProvider, DropdownTrigger } from '@univerjs/deimport { convertTransformToOffsetX, convertTransformToOffsetY, IRenderManagerService } from '@univerjs/engine-render';import { CheckMarkSingle, MoreDownSingle, PasteSpecial } from '@univerjs/icons';import clsx from 'clsx';-import React, { useCallback, useEffect, useState } from 'react';+import { useCallback, useEffect, useState } from 'react';import { SheetOptionalPasteCommand } from '../../commands/commands/clipboard.command';import { SetScrollOperation } from '../../commands/operations/scroll.operation';import { useActiveWorkbook, useSheetSkeleton } from '../../components/hook';@@ -113,7 +113,6 @@ export const ClipboardPopupMenu = () => {const clipboardService = useDependency(ISheetClipboardService);const showMenu = useObservable(clipboardService.showMenu$, true);const pasteOptionsCache = useObservable(clipboardService.pasteOptionsCache$, null);- const renderManagerService = useDependency(IRenderManagerService);const localeService = useDependency(LocaleService);const commandService = useDependency(ICommandService);diff --git a/packages/sheets/src/model/range-protection-rule.model.ts b/packages/sheets/src/model/range-protection-rule.model.tsindex eaab96f7d7..b6de2b38af 100644--- a/packages/sheets/src/model/range-protection-rule.model.ts+++ b/packages/sheets/src/model/range-protection-rule.model.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IRange } from '@univerjs/core';+import type { IDisposable, IRange } from '@univerjs/core';import type { UnitObject } from '@univerjs/protocol';import { Tools } from '@univerjs/core';@@ -55,22 +55,25 @@ export interface IRuleChange {type IRuleChangeType = 'add' | 'set' | 'delete';-export class RangeProtectionRuleModel {+export class RangeProtectionRuleModel implements IDisposable {/**- ** Map<unitId, Map<subUnitId, Map<ruleId, IRangeProtectionRule>>>*/private _model: IModel = new Map();- private _ruleChange = new Subject<IRuleChange>();+ private readonly _ruleChange$ = new Subject<IRuleChange>();+ readonly ruleChange$ = this._ruleChange$.asObservable();- ruleChange$ = this._ruleChange.asObservable();+ private _ruleRefresh$ = new Subject<string>();+ ruleRefresh$ = this._ruleRefresh$.asObservable();- private _ruleRefresh = new Subject<string>();- ruleRefresh$ = this._ruleRefresh.asObservable();+ dispose(): void {+ this._ruleChange$.complete();+ this._ruleRefresh$.complete();+ }ruleRefresh(id: string) {- this._ruleRefresh.next(id);+ this._ruleRefresh$.next(id);}private _rangeRuleInitStateChange = new BehaviorSubject<boolean>(false);@@ -87,14 +90,14 @@ export class RangeProtectionRuleModel {addRule(unitId: string, subUnitId: string, rule: IRangeProtectionRule) {const ruleMap = this._ensureRuleMap(unitId, subUnitId);ruleMap.set(rule.id, rule);- this._ruleChange.next({ unitId, subUnitId, rule, type: 'add' });+ this._ruleChange$.next({ unitId, subUnitId, rule, type: 'add' });}deleteRule(unitId: string, subUnitId: string, id: string) {const rule = this._model.get(unitId)?.get(subUnitId)?.get(id);if (rule) {this._model.get(unitId)?.get(subUnitId)?.delete(id);- this._ruleChange.next({ unitId, subUnitId, rule, type: 'delete' });+ this._ruleChange$.next({ unitId, subUnitId, rule, type: 'delete' });}}@@ -102,7 +105,7 @@ export class RangeProtectionRuleModel {const oldRule = this.getRule(unitId, subUnitId, id);if (oldRule) {this._model.get(unitId)?.get(subUnitId)?.set(id, rule);- this._ruleChange.next({ unitId, subUnitId, oldRule, rule, type: 'set' });+ this._ruleChange$.next({ unitId, subUnitId, oldRule, rule, type: 'set' });}}diff --git a/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.tsindex 0bd4a5ce41..bc3a746ab0 100644--- a/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts+++ b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts@@ -305,11 +305,11 @@ export class SheetInterceptorService extends Disposable {interceptors.push(interceptor);const sortedInterceptors = interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));+ this._interceptorsDirty = true;+if (key === INTERCEPTOR_POINT.CELL_CONTENT as unknown as string) {- this._interceptorsByName.set(- `${key}-${(InterceptorEffectEnum.Style | InterceptorEffectEnum.Value)}`,- sortedInterceptors- );+ const JOINED_EFFECT = InterceptorEffectEnum.Style | InterceptorEffectEnum.Value;+ this._interceptorsByName.set(`${key}-${JOINED_EFFECT}`, sortedInterceptors);const BOTH_EFFECT = InterceptorEffectEnum.Style | InterceptorEffectEnum.Value;this._interceptorsByName.set(@@ -320,15 +320,17 @@ export class SheetInterceptorService extends Disposable {`${key}-${(InterceptorEffectEnum.Value)}`,(sortedInterceptors as ICellInterceptor<unknown, unknown>[]).filter((i) => ((i.effect || BOTH_EFFECT) & InterceptorEffectEnum.Value) > 0));++ return this.disposeWithMe(toDisposable(() => {+ remove(this._interceptorsByName.get(key)!, interceptor);+ remove(this._interceptorsByName.get(`${key}-${JOINED_EFFECT}`)!, interceptor);+ remove(this._interceptorsByName.get(`${key}-${(InterceptorEffectEnum.Style)}`)!, interceptor);+ remove(this._interceptorsByName.get(`${key}-${(InterceptorEffectEnum.Value)}`)!, interceptor);+ }));} else {- this._interceptorsByName.set(- key,- sortedInterceptors- );+ this._interceptorsByName.set(key, sortedInterceptors);+ return this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key)!, interceptor)));}-- this._interceptorsDirty = true;- return this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key)!, interceptor)));}fetchThroughInterceptors<T, C>(