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(disposeUnit): fix some issues with disposeUnit (#6460)
wpxp123456427aeed80a3c
diff --git a/common/debugger/src/views/Fab.tsx b/common/debugger/src/views/Fab.tsxindex 43898fdcfc..1544da734c 100644--- a/common/debugger/src/views/Fab.tsx+++ b/common/debugger/src/views/Fab.tsx@@ -37,35 +37,50 @@ import { useUser } from './use-user';import { useWatermark } from './use-watermark';export function Fab() {+ const locale = useLocale();+ const darkMode = useDarkMode();+ const theme = useTheme();+ const watermark = useWatermark();+ const notification = useNotification();+ const message = useMessage();+ const dialog = useDialog();+ const sidebar = useSidebar();+ const floatingDom = useFloatingDom();+ const cellContent = useCellContent();+ const units = useUnits();+ const snapshot = useSnapshot();+ const editable = useEditable();+ const user = useUser();+ const dispose = useDispose();+const configService = useDependency(IConfigService);+ const configs = configService.getConfig<IUniverDebuggerConfig>(DEBUGGER_PLUGIN_CONFIG_KEY);+ const performanceMonitor = configs?.performanceMonitor;+const univerInstanceService = useDependency(IUniverInstanceService);const unitType = univerInstanceService.getFocusedUnit()?.type;-if (!unitType) return null;const items: IDropdownMenuProps['items'] = [- useLocale(),- useDarkMode(),- useTheme(),- useWatermark(),+ locale,+ darkMode,+ theme,+ watermark,{ type: 'separator' },- useNotification(),- useMessage(),- useDialog(),- useSidebar(),+ notification,+ message,+ dialog,+ sidebar,{ type: 'separator' },- unitType === UniverInstanceType.UNIVER_SHEET && useFloatingDom(),- unitType === UniverInstanceType.UNIVER_SHEET && useCellContent(),- unitType === UniverInstanceType.UNIVER_SHEET && useUnits(),- useSnapshot(),- useEditable(),- unitType === UniverInstanceType.UNIVER_SHEET && useUser(),- useDispose(),+ unitType === UniverInstanceType.UNIVER_SHEET && floatingDom,+ unitType === UniverInstanceType.UNIVER_SHEET && cellContent,+ unitType === UniverInstanceType.UNIVER_SHEET && units,+ snapshot,+ editable,+ unitType === UniverInstanceType.UNIVER_SHEET && user,+ dispose,].filter((item) => item !== null) as IDropdownMenuProps['items'];- const configs = configService.getConfig<IUniverDebuggerConfig>(DEBUGGER_PLUGIN_CONFIG_KEY);- const performanceMonitor = configs?.performanceMonitor;-return (<divdata-u-comp="debugger-fab"diff --git a/examples/src/sheets-webcomponent/main.tsx b/examples/src/sheets-webcomponent/main.tsxindex 9a217da679..154e5752db 100644--- a/examples/src/sheets-webcomponent/main.tsx+++ b/examples/src/sheets-webcomponent/main.tsx@@ -16,6 +16,7 @@import { createComponent } from '@lit/react';import { LocaleType, LogLevel, Univer, UniverInstanceType } from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';import { render } from '@univerjs/design';import { UniverDocsPlugin } from '@univerjs/docs';import { UniverDocsUIPlugin } from '@univerjs/docs-ui';@@ -23,17 +24,44 @@ import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';import { UniverRenderEnginePlugin } from '@univerjs/engine-render';import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';import zhCN from '@univerjs/mockdata/locales/zh-CN';+import { UniverNetworkPlugin } from '@univerjs/network';import { UniverSheetsPlugin } from '@univerjs/sheets';+import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';+import { UniverSheetsConditionalFormattingUIPlugin } from '@univerjs/sheets-conditional-formatting-ui';+import { UniverSheetsCrosshairHighlightPlugin } from '@univerjs/sheets-crosshair-highlight';+import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';+import { UniverSheetsDataValidationUIPlugin } from '@univerjs/sheets-data-validation-ui';+import { UniverSheetsDrawingPlugin } from '@univerjs/sheets-drawing';+import { UniverSheetsDrawingUIPlugin } from '@univerjs/sheets-drawing-ui';+import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';+import { UniverSheetsFilterUIPlugin } from '@univerjs/sheets-filter-ui';+import { UniverSheetsFindReplacePlugin } from '@univerjs/sheets-find-replace';import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula';import { UniverSheetsFormulaUIPlugin } from '@univerjs/sheets-formula-ui';+import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';+import { UniverSheetsHyperLinkUIPlugin } from '@univerjs/sheets-hyper-link-ui';+import { UniverSheetsNotePlugin } from '@univerjs/sheets-note';+import { UniverSheetsNoteUIPlugin } from '@univerjs/sheets-note-ui';import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';import { UniverSheetsNumfmtUIPlugin } from '@univerjs/sheets-numfmt-ui';+import { UniverSheetsSortPlugin } from '@univerjs/sheets-sort';+import { UniverSheetsSortUIPlugin } from '@univerjs/sheets-sort-ui';+import { UniverSheetsTablePlugin } from '@univerjs/sheets-table';+import { UniverSheetsTableUIPlugin } from '@univerjs/sheets-table-ui';+import { UniverSheetsThreadCommentPlugin } from '@univerjs/sheets-thread-comment';+import { UniverSheetsThreadCommentUIPlugin, UniverThreadCommentUIPlugin } from '@univerjs/sheets-thread-comment-ui';import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';+import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';+import { UniverThreadCommentPlugin } from '@univerjs/thread-comment';import { UniverUIPlugin } from '@univerjs/ui';+import { UniverVue3AdapterPlugin } from '@univerjs/ui-adapter-vue3';+import { UniverWebComponentAdapterPlugin } from '@univerjs/ui-adapter-web-component';+import { UniverWatermarkPlugin } from '@univerjs/watermark';import { html, LitElement } from 'lit';import { customElement } from 'lit/decorators.js';import React from 'react';import '../global.css';+import '@univerjs/sheets/facade';@customElement('my-univer')class MyWebComponent extends LitElement {@@ -47,26 +75,69 @@ class MyWebComponent extends LitElement {},logLevel: LogLevel.VERBOSE,});-+ // basic plugins+ univer.registerPlugin(UniverNetworkPlugin);univer.registerPlugin(UniverFormulaEnginePlugin);univer.registerPlugin(UniverRenderEnginePlugin);univer.registerPlugin(UniverUIPlugin, {container,ribbonType: 'classic',});+ // docs pluginuniver.registerPlugin(UniverDocsPlugin);univer.registerPlugin(UniverDocsUIPlugin);-// sheets pluginuniver.registerPlugin(UniverSheetsPlugin);univer.registerPlugin(UniverSheetsUIPlugin);- univer.registerPlugin(UniverSheetsFormulaUIPlugin);// sheet feature pluginsuniver.registerPlugin(UniverSheetsNumfmtPlugin);univer.registerPlugin(UniverSheetsNumfmtUIPlugin);univer.registerPlugin(UniverSheetsFormulaPlugin);+ univer.registerPlugin(UniverSheetsFormulaUIPlugin);+ // sheet drawing plugins+ univer.registerPlugin(UniverSheetsDrawingPlugin);+ univer.registerPlugin(UniverSheetsDrawingUIPlugin);+ // sheet conditional formatting plugins+ univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);+ univer.registerPlugin(UniverSheetsConditionalFormattingUIPlugin);+ // sheet data validation plugins+ univer.registerPlugin(UniverSheetsDataValidationPlugin);+ univer.registerPlugin(UniverSheetsDataValidationUIPlugin);+ // sheet filter plugins+ univer.registerPlugin(UniverSheetsFilterPlugin);+ univer.registerPlugin(UniverSheetsFilterUIPlugin);+ // sheet sort plugins+ univer.registerPlugin(UniverSheetsSortPlugin);+ univer.registerPlugin(UniverSheetsSortUIPlugin);+ // sheet hyperlink plugins+ univer.registerPlugin(UniverSheetsHyperLinkPlugin);+ univer.registerPlugin(UniverSheetsHyperLinkUIPlugin);+ // sheet table plugins+ univer.registerPlugin(UniverSheetsTablePlugin);+ univer.registerPlugin(UniverSheetsTableUIPlugin);+ // sheet note plugins+ univer.registerPlugin(UniverSheetsNotePlugin);+ univer.registerPlugin(UniverSheetsNoteUIPlugin);+ // sheet thread comment plugins+ univer.registerPlugin(UniverThreadCommentPlugin);+ univer.registerPlugin(UniverThreadCommentUIPlugin);+ univer.registerPlugin(UniverSheetsThreadCommentPlugin);+ univer.registerPlugin(UniverSheetsThreadCommentUIPlugin);+ // sheet find and replace plugins+ univer.registerPlugin(UniverSheetsFindReplacePlugin);+ // zen editor plugin+ univer.registerPlugin(UniverSheetsZenEditorPlugin);+ // crosshair highlight plugin+ univer.registerPlugin(UniverSheetsCrosshairHighlightPlugin);+ // watermark plugin+ univer.registerPlugin(UniverWatermarkPlugin);+ // adapter plugins+ univer.registerPlugin(UniverWebComponentAdapterPlugin);+ univer.registerPlugin(UniverVue3AdapterPlugin);univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);++ window.univerAPI = FUniver.newAPI(univer);}override render() {diff --git a/packages/engine-formula/src/engine/dependency/formula-dependency.ts b/packages/engine-formula/src/engine/dependency/formula-dependency.tsindex 73efe23b80..1183ea3b6e 100644--- a/packages/engine-formula/src/engine/dependency/formula-dependency.ts+++ b/packages/engine-formula/src/engine/dependency/formula-dependency.ts@@ -14,10 +14,9 @@* limitations under the License.*/-import type { IRange, IUnitRange, Nullable } from '@univerjs/core';+import type { IRange, IUnitRange, Nullable, Workbook } from '@univerjs/core';import type { IFeatureDirtyRangeType, IFormulaData, IFormulaDataItem, IOtherFormulaData, IUnitData } from '../../basics/common';import type { IFormulaDirtyData } from '../../services/current-data.service';-import type { IFeatureCalculationManagerParam } from '../../services/feature-calculation-manager.service';import type { IAllRuntimeData } from '../../services/runtime.service';import type { FunctionNode, PrefixNode, SuffixNode } from '../ast-node';@@ -26,9 +25,8 @@ import type { BaseReferenceObject, FunctionVariantType } from '../reference-objeimport type { IExecuteAstNodeData } from '../utils/ast-node-tool';import type { PreCalculateNodeType } from '../utils/node-type';import type { IFormulaDependencyTree, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults } from './dependency-tree';-import { createIdentifier, Disposable, Inject, ObjectMatrix, RTree } from '@univerjs/core';+import { createIdentifier, Disposable, Inject, IUniverInstanceService, ObjectMatrix, RTree, UniverInstanceType } from '@univerjs/core';import { prefixToken, suffixToken } from '../../basics/token';-import { IFormulaCurrentConfigService } from '../../services/current-data.service';import { IDependencyManagerService } from '../../services/dependency-manager.service';import { IFeatureCalculationManagerService } from '../../services/feature-calculation-manager.service';@@ -42,8 +40,6 @@ import { Interpreter } from '../interpreter/interpreter';import { FORMULA_AST_CACHE, generateAstNode, includeDefinedName } from '../utils/generate-ast-node';import { FormulaDependencyTree, FormulaDependencyTreeModel, FormulaDependencyTreeType, FormulaDependencyTreeVirtual } from './dependency-tree';-const FORMULA_CACHE_LRU_COUNT = 5000;-interface IFeatureFormulaParam {unitId: string;subUnitId: string;@@ -66,7 +62,7 @@ export interface IFormulaDependencyGenerator {export const IFormulaDependencyGenerator = createIdentifier<IFormulaDependencyGenerator>('engine-formula.dependency-generator');-export class FormulaDependencyGenerator extends Disposable {+export class FormulaDependencyGenerator extends Disposable implements IFormulaDependencyGenerator {private _updateRangeFlattenCache = new Map<string, Map<string, IRange[]>>();protected _dependencyRTreeCacheForAddressFunction: RTree = new RTree();@@ -77,6 +73,7 @@ export class FormulaDependencyGenerator extends Disposable {@IOtherFormulaManagerService protected readonly _otherFormulaManagerService: IOtherFormulaManagerService,@IFeatureCalculationManagerServiceprivate readonly _featureCalculationManagerService: IFeatureCalculationManagerService,+ @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService,@Inject(Interpreter) private readonly _interpreter: Interpreter,@Inject(AstTreeBuilder) protected readonly _astTreeBuilder: AstTreeBuilder,@Inject(Lexer) protected readonly _lexer: Lexer,@@ -84,14 +81,33 @@ export class FormulaDependencyGenerator extends Disposable {@Inject(LexerTreeBuilder) protected readonly _lexerTreeBuilder: LexerTreeBuilder) {super();++ this._initUnitDispose();}override dispose(): void {+ super.dispose();this._updateRangeFlattenCache.clear();this._dependencyRTreeCacheForAddressFunction.clear();FORMULA_AST_CACHE.clear();}+ private _initUnitDispose() {+ this.disposeWithMe(+ this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {+ this._disposeByUnitId(workbook.getUnitId());+ })+ );+ }++ private _disposeByUnitId(unitId: string) {+ FORMULA_AST_CACHE.forEach((_, key) => {+ if (key.startsWith(unitId)) {+ FORMULA_AST_CACHE.delete(key);+ }+ });+ }+async generate(isCalculateTreeModel = false) {this._updateRangeFlatten();// const formulaInterpreter = Interpreter.create(interpreterDatasetConfig);diff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.tsindex 7c816bfb84..f4b8c1b392 100644--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts@@ -443,17 +443,18 @@ export class SheetCanvasPopManagerService extends Disposable {* @returns*/attachPopupToCell(row: number, col: number, popup: ICanvasPopup, _unitId?: string, _subUnitId?: string, viewport?: Viewport): Nullable<INeedCheckDisposable> {- let workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;- let worksheet = workbook.getActiveSheet();- if (!worksheet) {- return null;- }+ let workbook = _unitId+ ? this._univerInstanceService.getUnit<Workbook>(_unitId)+ : this._univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);+ if (!workbook) return null;++ let worksheet = _subUnitId+ ? workbook.getSheetBySheetId(_subUnitId)+ : workbook.getActiveSheet();+ if (!worksheet) return null;const unitId = workbook.getUnitId();const subUnitId = worksheet.getSheetId();- if ((_unitId && unitId !== _unitId) || (_subUnitId && subUnitId !== _subUnitId)) {- return null;- }const currentRender = this._renderManagerService.getRenderById(unitId);const skeleton = currentRender?.with(SheetSkeletonManagerService).ensureSkeleton(subUnitId);const sheetSelectionRenderService = currentRender?.with(ISheetSelectionRenderService);