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(core): fix plugin holder of univer type not set (#3702)
Wenzhao Hu851b1ce5f4cd
diff --git a/.github/actions/update-snapshots/action.yml b/.github/actions/update-snapshots/action.ymlindex 6acd797ea8..db6bf8d85d 100644--- a/.github/actions/update-snapshots/action.yml+++ b/.github/actions/update-snapshots/action.yml@@ -15,14 +15,3 @@ runs:- name: Update Snapshotsshell: bashrun: pnpm exec playwright test e2e/visual-comparison --update-snapshots-- - name: Commit Updated Snapshots- shell: bash- run: |- git config --global user.email "[email protected]"- git config --global user.name "GitHub Actions"-- git status- git add -A- git commit -m "chore(snapshots): update snapshots" || exit 0- git pushdiff --git a/.github/workflows/update-snapshots-manually.yml b/.github/workflows/update-snapshots-manually.ymlindex ecd8c2b152..d970880f38 100644--- a/.github/workflows/update-snapshots-manually.yml+++ b/.github/workflows/update-snapshots-manually.yml@@ -19,3 +19,14 @@ jobs:- name: Update Snapshotsuses: ./.github/actions/update-snapshots++ - name: Commit Updated Snapshots+ shell: bash+ run: |+ git config --global user.email "[email protected]"+ git config --global user.name "GitHub Actions"++ git status+ git add -A+ git commit -m "chore(snapshots): update snapshots" || exit 0+ git pushdiff --git a/.github/workflows/update-snapshots-on-comment.yml b/.github/workflows/update-snapshots-on-comment.ymlindex b6677d5823..ff828d7d6a 100644--- a/.github/workflows/update-snapshots-on-comment.yml+++ b/.github/workflows/update-snapshots-on-comment.yml@@ -18,8 +18,23 @@ jobs:ref: ${{ github.event.issue.pull_request.head.ref }}fetch-depth: 0+ - name: Get Branch Name+ id: get_branch+ run: echo "##[set-output name=branch;]${{ github.event.issue.pull_request.head.ref }}"+- name: Setup Node.jsuses: ./.github/actions/setup-node- name: Update Snapshotsuses: ./.github/actions/update-snapshots++ - name: Commit Updated Snapshots+ shell: bash+ run: |+ git config --global user.email "[email protected]"+ git config --global user.name "GitHub Actions"++ git checkout ${{ steps.get_branch.outputs.branch }}+ git add -A+ git commit -m "chore(snapshots): update snapshots" || exit 0+ git pushdiff --git a/.vscode/launch.json b/.vscode/launch.jsonindex 25669c57c3..c7bc145784 100644--- a/.vscode/launch.json+++ b/.vscode/launch.json@@ -5,47 +5,47 @@"version": "0.2.0","configurations": [{- "name": "Launch Doc (Chrome)",+ "name": "Launch Sheet (Chrome)","request": "launch","type": "chrome",- "url": "http://localhost:3003",- "webRoot": "${workspaceFolder}/examples/docs/local/",+ "url": "http://localhost:3002/sheets/",+ "webRoot": "${workspaceFolder}/examples/local/sheets","presentation": {"group": "0_example",- "order": 1+ "order": 2}},{- "name": "Launch Doc (Edge)",+ "name": "Launch Sheet (Edge)","request": "launch","type": "msedge",- "url": "http://localhost:3003",- "webRoot": "${workspaceFolder}/examples/docs/local/",+ "url": "http://localhost:3002/sheets",+ "webRoot": "${workspaceFolder}/examples/sheets/local/","presentation": {"group": "0_example",- "order": 2+ "order": 1}},{- "name": "Launch Sheet (Chrome)",+ "name": "Launch Doc (Chrome)","request": "launch","type": "chrome","url": "http://localhost:3002",- "webRoot": "${workspaceFolder}/examples/sheets/local/",+ "webRoot": "${workspaceFolder}/examples/local/docs","presentation": {"group": "0_example",- "order": 3+ "order": 4}},{- "name": "Launch Sheet (Edge)",+ "name": "Launch Doc (Edge)","request": "launch","type": "msedge","url": "http://localhost:3002",- "webRoot": "${workspaceFolder}/examples/sheets/local/",+ "webRoot": "${workspaceFolder}/examples/local/docs","presentation": {"group": "0_example",- "order": 4+ "order": 3}},{@@ -56,7 +56,7 @@"webRoot": "${workspaceFolder}/examples/slides/local/","presentation": {"group": "0_example",- "order": 5+ "order": 6}},{@@ -67,7 +67,7 @@"webRoot": "${workspaceFolder}/examples/slides/local/","presentation": {"group": "0_example",- "order": 6+ "order": 5}},{diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.pngindex 97828dd477..4fcf720091 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.pngindex ba7ccfd100..745920daf0 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png differdiff --git a/packages/core/src/common/di.ts b/packages/core/src/common/di.tsindex e4731f015c..80558a2e6c 100644--- a/packages/core/src/common/di.ts+++ b/packages/core/src/common/di.ts@@ -14,5 +14,25 @@* limitations under the License.*/+import type { Dependency, Injector } from '@wendellhu/redi';+export * from '@wendellhu/redi';export * from '@wendellhu/redi/react-bindings';++/**+ * Register the dependencies to the injector.+ * @param injector The injector to register the dependencies.+ * @param dependencies The dependencies to register.+ */+export function registerDependencies(injector: Injector, dependencies: Dependency[]): void {+ dependencies.forEach((d) => injector.add(d));+}++/**+ * Touch a group of dependencies to ensure they are instantiated.+ * @param injector The injector to touch the dependencies.+ * @param dependencies The dependencies to touch.+ */+export function touchDependencies(injector: Injector, dependencies: Dependency[]): void {+ dependencies.forEach((d) => injector.get(d[0]));+}diff --git a/packages/core/src/services/plugin/plugin.service.ts b/packages/core/src/services/plugin/plugin.service.tsindex e5a22eafb8..6003967fca 100644--- a/packages/core/src/services/plugin/plugin.service.ts+++ b/packages/core/src/services/plugin/plugin.service.ts@@ -60,6 +60,8 @@ export class PluginService implements IDisposable {this._immediateInitPlugin.bind(this));+ this._pluginHoldersForTypes.set(UniverInstanceType.UNIVER_UNKNOWN, this._pluginHolderForUniver);+this._pluginHolderForUniver.start();}@@ -180,20 +182,23 @@ export class PluginHolder extends Disposable {protected readonly _pluginRegistry = new PluginRegistry();/** Stores initialized plugin instances. */protected readonly _pluginStore = new PluginStore();-- private readonly _awaitingPlugins: Plugin[][] = [];+ /** Plugins instances as they are registered in batches. */+ private readonly _pluginsInBatches: Plugin[][] = [];constructor(private _checkPluginRegistered: (pluginCtor: PluginCtor) => boolean,private _registerPlugin: <T extends PluginCtor>(plugin: T, config?: ConstructorParameters<T>[0]) => void,@ILogService protected readonly _logService: ILogService,@Inject(Injector) protected readonly _injector: Injector,+@Inject(LifecycleService) protected readonly _lifecycleService: LifecycleService) {super();this.disposeWithMe(this._lifecycleService.lifecycle$.pipe(skip(1)).subscribe((stage) => {- this._awaitingPlugins.forEach((plugins) => this._runStage(plugins, stage));+ // Lifecycle of plugins should be coordinated. For example, if a plugin A depends on another plugin B, B should go+ // through the lifecycle first. As a temporary solution, we make sure that plugin with type Common goes through the lifecycle first.+ this._pluginsInBatches.forEach((plugins) => this._runStage(plugins, stage));}));}@@ -205,7 +210,7 @@ export class PluginHolder extends Disposable {this._pluginRegistry.removePlugins();- this._awaitingPlugins.length = 0;+ this._pluginsInBatches.length = 0;}register<T extends PluginCtor<Plugin>>(pluginCtor: T, config?: ConstructorParameters<T>[0]): void {@@ -278,7 +283,7 @@ export class PluginHolder extends Disposable {// Let plugins go through already reached lifecycle stages.getLifecycleStagesAndBefore(this._lifecycleService.stage).subscribe((stage) => this._runStage(plugins, stage));// Push to the queue for later lifecycle.- this._awaitingPlugins.push(plugins);+ this._pluginsInBatches.push(plugins);}private _runStage(plugins: Plugin[], stage: LifecycleStages): void {@@ -310,3 +315,4 @@ export class PluginHolder extends Disposable {});}}+diff --git a/packages/core/src/services/plugin/plugin.ts b/packages/core/src/services/plugin/plugin.tsindex d17e2ff57c..8133700d93 100644--- a/packages/core/src/services/plugin/plugin.ts+++ b/packages/core/src/services/plugin/plugin.ts@@ -15,8 +15,8 @@*/import type { Ctor, Injector } from '../../common/di';-import { Disposable } from '../../shared';import { UniverInstanceType } from '../../common/unit';+import { Disposable } from '../../shared';export const DependentOnSymbol = Symbol('DependentOn');diff --git a/packages/drawing-ui/src/controllers/drawing-update.controller.ts b/packages/drawing-ui/src/controllers/drawing-update.controller.tsindex f1b01c34da..da1bc9f915 100644--- a/packages/drawing-ui/src/controllers/drawing-update.controller.ts+++ b/packages/drawing-ui/src/controllers/drawing-update.controller.ts@@ -574,23 +574,19 @@ export class DrawingUpdateController extends Disposable {private _insertDrawing(params: IDrawingSearch[]) {const sceneList: Scene[] = [];(params).forEach((param) => {- const { unitId, subUnitId, drawingId } = param;+ const { unitId } = param;const drawingParam = this._drawingManagerService.getDrawingByParam(param) as IDrawingParam;-if (drawingParam == null) {return;}- const { transform, drawingType } = drawingParam;-const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);-if (renderObject == null) {return;}- const { scene, transformer } = renderObject;+ const { scene } = renderObject;if (!sceneList.includes(scene)) {sceneList.push(scene);}diff --git a/packages/drawing-ui/src/plugin.ts b/packages/drawing-ui/src/plugin.tsindex 7e569eeef6..376ea3616c 100644--- a/packages/drawing-ui/src/plugin.ts+++ b/packages/drawing-ui/src/plugin.ts@@ -49,8 +49,8 @@ export class UniverDrawingUIPlugin extends Plugin {}override onRendered(): void {- this._injector.get(DrawingUIController);this._injector.get(DrawingUpdateController);+ this._injector.get(DrawingUIController);this._injector.get(ImageCropperController);this._injector.get(ImageUpdateController);}diff --git a/packages/engine-render/src/components/sheets/spreadsheet.ts b/packages/engine-render/src/components/sheets/spreadsheet.tsindex 0209ec19b3..3705dec707 100644--- a/packages/engine-render/src/components/sheets/spreadsheet.ts+++ b/packages/engine-render/src/components/sheets/spreadsheet.ts@@ -14,30 +14,25 @@* limitations under the License.*/-import { BooleanNumber, sortRules, Tools } from '@univerjs/core';import type { IRange, ISelectionCellWithMergeInfo, Nullable, ObjectMatrix } from '@univerjs/core';--import { FIX_ONE_PIXEL_BLUR_OFFSET, RENDER_CLASS_TYPE } from '../../basics/const';--// import { clearLineByBorderType } from '../../basics/draw';-import { getCellPositionByIndex, getColor } from '../../basics/tools';-import { Documents } from '../docs/document';-import { SpreadsheetExtensionRegistry } from '../extension';-import { SHEET_EXTENSION_PREFIX } from './extensions/sheet-extension';-import { type IPaintForRefresh, type IPaintForScrolling, SHEET_VIEWPORT_KEY } from './interfaces';-// import type { BorderCacheItem } from './interfaces';-import { SheetComponent } from './sheet-component';import type { IBoundRectNoAngle, IViewportInfo, Vector2 } from '../../basics/vector2';import type { Canvas } from '../../canvas';import type { UniverRenderingContext2D } from '../../context';import type { Engine } from '../../engine';import type { Scene } from '../../scene';import type { SceneViewer } from '../../scene-viewer';-import type { Background } from './extensions/background';import type { Border } from './extensions/border';import type { Font } from './extensions/font';import type { SpreadsheetSkeleton } from './sheet-skeleton';+import { BooleanNumber, sortRules, Tools } from '@univerjs/core';+import { FIX_ONE_PIXEL_BLUR_OFFSET, RENDER_CLASS_TYPE } from '../../basics/const';+import { getCellPositionByIndex, getColor } from '../../basics/tools';+import { Documents } from '../docs/document';+import { SpreadsheetExtensionRegistry } from '../extension';+import { SHEET_EXTENSION_PREFIX } from './extensions/sheet-extension';+import { type IPaintForRefresh, type IPaintForScrolling, SHEET_VIEWPORT_KEY } from './interfaces';+import { SheetComponent } from './sheet-component';const OBJECT_KEY = '__SHEET_EXTENSION_FONT_DOCUMENT_INSTANCE__';diff --git a/packages/sheets-drawing-ui/src/plugin.ts b/packages/sheets-drawing-ui/src/plugin.tsindex 6786acf40e..134302f025 100644--- a/packages/sheets-drawing-ui/src/plugin.ts+++ b/packages/sheets-drawing-ui/src/plugin.ts@@ -22,6 +22,8 @@ import {Inject,Injector,Plugin,+ registerDependencies,+ touchDependencies,UniverInstanceType,} from '@univerjs/core';import { UniverDrawingPlugin } from '@univerjs/drawing';@@ -63,40 +65,40 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {}override onStarting(): void {- this._initDependencies();+ registerDependencies(this._injector, [+ [SheetCanvasFloatDomManagerService],+ [SheetDrawingUIController],+ [DrawingPopupMenuController],+ [SheetDrawingPrintingController],+ [SheetDrawingPermissionController],+ [SheetsDrawingCopyPasteController],+ ]);- this._injector.get(SheetCanvasFloatDomManagerService);+ touchDependencies(this._injector, [+ [SheetCanvasFloatDomManagerService],+ ]);}override onReady(): void {- this._injector.get(SheetsDrawingCopyPasteController);+ touchDependencies(this._injector, [+ [SheetsDrawingCopyPasteController],+ ]);}override onRendered(): void {this._registerRenderModules();- this._injector.get(SheetDrawingPermissionController);- this._injector.get(SheetDrawingPrintingController);- this._injector.get(SheetDrawingUIController);+ touchDependencies(this._injector, [+ [SheetDrawingPermissionController],+ [SheetDrawingPrintingController],+ [SheetDrawingUIController],+ ]);}override onSteady(): void {this._injector.get(DrawingPopupMenuController);}- private _initDependencies(): void {- const dependencies: Dependency[] = [- [SheetCanvasFloatDomManagerService],- [SheetDrawingUIController],- [DrawingPopupMenuController],- [SheetDrawingPrintingController],- [SheetDrawingPermissionController],- [SheetsDrawingCopyPasteController],- ];-- dependencies.forEach((dependency) => this._injector.add(dependency));- }-private _registerRenderModules(): void {([[SheetDrawingUpdateController],diff --git a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.tsindex 5701f54afd..cbe8deee07 100644--- a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts+++ b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts@@ -71,4 +71,3 @@ export class SheetsDrawingLoadController extends Disposable {);}}-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 bd08128b51..29b7c05311 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@@ -84,7 +84,7 @@ export class SheetsFilterRenderController extends RxDisposable implements IRendereturn fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) =>command.type === CommandType.MUTATION- && (command.params as ISheetCommandSharedParams).unitId === workbook.getUnitId()+ && (command.params as Partial<ISheetCommandSharedParams>)?.unitId === workbook.getUnitId()&& (FILTER_MUTATIONS.has(command.id) || command.id === SetRangeValuesMutation.id)),throttleTime(20, undefined, { leading: false, trailing: true }),diff --git a/packages/sheets-filter/src/services/sheet-filter.service.ts b/packages/sheets-filter/src/services/sheet-filter.service.tsindex 73a30d6a55..2dfa5fa431 100644--- a/packages/sheets-filter/src/services/sheet-filter.service.ts+++ b/packages/sheets-filter/src/services/sheet-filter.service.ts@@ -14,6 +14,8 @@* limitations under the License.*/+import type { Nullable, Workbook } from '@univerjs/core';+import type { IAutoFilter } from '../models/types';import {CommandType, Disposable,fromCallback,@@ -23,8 +25,6 @@ import {UniverInstanceType,} from '@univerjs/core';import { BehaviorSubject, filter, merge, of, switchMap } from 'rxjs';-import type { Nullable, Workbook } from '@univerjs/core';-import {ReCalcSheetsFilterMutation,RemoveSheetsFilterMutation,@@ -32,7 +32,6 @@ import {SetSheetsFilterRangeMutation,} from '../commands/mutations/sheets-filter.mutation';import { FilterModel } from '../models/filter-model';-import type { IAutoFilter } from '../models/types';export const FILTER_MUTATIONS = new Set([SetSheetsFilterRangeMutation.id,