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): performance monitor to show fps (#731)
Ran Luo2d684bae0ab6
diff --git a/examples/docs/package.json b/examples/docs/package.jsonindex 7990ce9a1a..ccac9a2fa8 100644--- a/examples/docs/package.json+++ b/examples/docs/package.json@@ -15,7 +15,8 @@"@univerjs/docs-ui": "workspace:*","@univerjs/engine-render": "workspace:*","@univerjs/ui": "workspace:*",- "data": "workspace:*"+ "data": "workspace:*",+ "univer-plugin-debugger": "workspace:*"},"devDependencies": {"esbuild": "^0.19.8",diff --git a/examples/docs/src/main.ts b/examples/docs/src/main.tsindex fea06ddd12..25714168af 100644--- a/examples/docs/src/main.ts+++ b/examples/docs/src/main.ts@@ -21,6 +21,7 @@ import { UniverDocsUIPlugin } from '@univerjs/docs-ui';import { UniverRenderEnginePlugin } from '@univerjs/engine-render';import { UniverUIPlugin } from '@univerjs/ui';import { DEFAULT_DOCUMENT_DATA_CN } from 'data';+import { DebuggerPlugin } from 'univer-plugin-debugger';import { locales } from './locales';@@ -41,6 +42,7 @@ const univer = new Univer({// core pluginsuniver.registerPlugin(UniverRenderEnginePlugin);+univer.registerPlugin(DebuggerPlugin);univer.registerPlugin(UniverUIPlugin, {container: 'univer-container',header: true,diff --git a/examples/sheets/package.json b/examples/sheets/package.jsonindex f29a546bd2..2825aec0e7 100644--- a/examples/sheets/package.json+++ b/examples/sheets/package.json@@ -25,7 +25,8 @@"@univerjs/uniscript": "workspace:*","@wendellhu/redi": "^0.12.12","data": "workspace:*",- "monaco-editor": "0.45.0"+ "monaco-editor": "0.45.0",+ "univer-plugin-debugger": "workspace:*"},"devDependencies": {"esbuild": "^0.19.8",diff --git a/examples/sheets/src/main.ts b/examples/sheets/src/main.tsindex a781d704db..4c51322282 100644--- a/examples/sheets/src/main.ts+++ b/examples/sheets/src/main.ts@@ -29,9 +29,9 @@ import { UniverUIPlugin } from '@univerjs/ui';import type { IUniscriptConfig } from '@univerjs/uniscript';import { UniverUniscriptPlugin } from '@univerjs/uniscript';import { DEFAULT_WORKBOOK_DATA_DEMO } from 'data';+import { DebuggerPlugin } from 'univer-plugin-debugger';import { locales } from './locales';-import { DebuggerPlugin } from './sheets-plugin-debugger';// package infoconsole.table({diff --git a/examples/univer-plugin-debugger/README.md b/examples/univer-plugin-debugger/README.mdnew file mode 100644index 0000000000..fbe5b0ac30--- /dev/null+++ b/examples/univer-plugin-debugger/README.md@@ -0,0 +1 @@+## Debugger.Debug("Hello World")\ No newline at end of filediff --git a/examples/univer-plugin-debugger/package.json b/examples/univer-plugin-debugger/package.jsonnew file mode 100644index 0000000000..c81d873481--- /dev/null+++ b/examples/univer-plugin-debugger/package.json@@ -0,0 +1,31 @@+{+ "name": "univer-plugin-debugger",+ "description": "Used for debugger",+ "author": "DreamNum <[email protected]>",+ "license": "Apache-2.0",+ "private": true,+ "main": "./src/index.ts",+ "exports": {+ ".": "./src/index.ts",+ "./*": "./src/*"+ },+ "dependencies": {+ "@univerjs/core": "workspace:*",+ "@univerjs/design": "workspace:*",+ "@univerjs/docs": "workspace:*",+ "@univerjs/docs-ui": "workspace:*",+ "@univerjs/engine-formula": "workspace:*",+ "@univerjs/engine-render": "workspace:*",+ "@univerjs/local-save": "workspace:*",+ "@univerjs/rpc": "workspace:*",+ "@univerjs/sheets": "workspace:*",+ "@univerjs/sheets-formula": "workspace:*",+ "@univerjs/sheets-numfmt": "workspace:*",+ "@univerjs/sheets-ui": "workspace:*",+ "@univerjs/ui": "workspace:*",+ "@univerjs/uniscript": "workspace:*",+ "@wendellhu/redi": "^0.12.12",+ "monaco-editor": "0.45.0",+ "rxjs": "^7.8.1"+ }+}diff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/confirm.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/confirm.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/confirm.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/confirm.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/dialog.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/dialog.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/dialog.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/dialog.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/locale.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/locale.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/locale.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/locale.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/message.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/message.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/message.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/message.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/notification.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/notification.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/notification.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/notification.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/numfmt.operations.ts b/examples/univer-plugin-debugger/src/commands/operations/numfmt.operations.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/numfmt.operations.tsrename to examples/univer-plugin-debugger/src/commands/operations/numfmt.operations.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/save-snapshot.operations.ts b/examples/univer-plugin-debugger/src/commands/operations/save-snapshot.operations.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/save-snapshot.operations.tsrename to examples/univer-plugin-debugger/src/commands/operations/save-snapshot.operations.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/set.editable.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/set.editable.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/set.editable.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/set.editable.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/sidebar.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/sidebar.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/sidebar.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/sidebar.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/theme.operation.ts b/examples/univer-plugin-debugger/src/commands/operations/theme.operation.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/commands/operations/theme.operation.tsrename to examples/univer-plugin-debugger/src/commands/operations/theme.operation.tsdiff --git a/examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.ts b/examples/univer-plugin-debugger/src/controllers/debugger.controller.tssimilarity index 95%rename from examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.tsrename to examples/univer-plugin-debugger/src/controllers/debugger.controller.tsindex 6e316e5255..8951122a8c 100644--- a/examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.ts+++ b/examples/univer-plugin-debugger/src/controllers/debugger.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { Disposable, ICommandService, ISnapshotPersistenceService } from '@univerjs/core';+import { Disposable, ICommandService, ISnapshotPersistenceService, IUniverInstanceService } from '@univerjs/core';import { ExportController, LocalSnapshotService, RecordController } from '@univerjs/local-save';import { IMenuService } from '@univerjs/ui';import { Inject, Injector } from '@wendellhu/redi';@@ -44,7 +44,8 @@ export class DebuggerController extends Disposable {constructor(@Inject(Injector) private readonly _injector: Injector,@IMenuService private readonly _menuService: IMenuService,- @ICommandService private readonly _commandService: ICommandService+ @ICommandService private readonly _commandService: ICommandService,+ @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService) {super();this._initializeContextMenu();diff --git a/examples/sheets/src/sheets-plugin-debugger/controllers/menu.ts b/examples/univer-plugin-debugger/src/controllers/menu.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/controllers/menu.tsrename to examples/univer-plugin-debugger/src/controllers/menu.tsdiff --git a/examples/univer-plugin-debugger/src/controllers/performance-monitor.controller.ts b/examples/univer-plugin-debugger/src/controllers/performance-monitor.controller.tsnew file mode 100644index 0000000000..7f973212df--- /dev/null+++ b/examples/univer-plugin-debugger/src/controllers/performance-monitor.controller.ts@@ -0,0 +1,65 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';+import { DocCanvasView } from '@univerjs/docs/views/doc-canvas-view.js';+import { Inject } from '@wendellhu/redi';+import { interval, takeUntil, throttle } from 'rxjs';++@OnLifecycle(LifecycleStages.Rendered, PerformanceMonitorController)+export class PerformanceMonitorController extends RxDisposable {+ constructor(@Inject(DocCanvasView) private _docCanvasView: DocCanvasView) {+ super();++ this._initialize();+ }++ private _initialize() {+ this._showFPS();+ }++ private _showFPS() {+ const container = document.createElement('div');+ container.classList.add('fps-monitor');+ const THROTTLE_TIME = 500;+ document.body.appendChild(container);++ const style = `+ .fps-monitor {+ position: absolute;+ top: 0;+ left: 10px;+ width: 100px;+ height: 32px;+ line-height: 32px;+ color: rgba(32, 32, 32, .8);+ font-size: 14px;+ font-family: sans-serif;+ z-index: 1000;+ pointer-events: none;+ }+ `;++ document.head.appendChild(document.createElement('style')).innerText = style;++ this._docCanvasView.fps$+ .pipe(takeUntil(this.dispose$))+ .pipe(throttle(() => interval(THROTTLE_TIME)))+ .subscribe((fps) => {+ container.innerText = `FPS: ${fps}`;+ });+ }+}diff --git a/examples/sheets/src/sheets-plugin-debugger/debugger-plugin.ts b/examples/univer-plugin-debugger/src/debugger-plugin.tssimilarity index 80%rename from examples/sheets/src/sheets-plugin-debugger/debugger-plugin.tsrename to examples/univer-plugin-debugger/src/debugger-plugin.tsindex 2fff6c45b0..66a268503c 100644--- a/examples/sheets/src/sheets-plugin-debugger/debugger-plugin.ts+++ b/examples/univer-plugin-debugger/src/debugger-plugin.ts@@ -15,14 +15,16 @@*/import { LocaleService, Plugin, PluginType } from '@univerjs/core';+import type { Dependency } from '@wendellhu/redi';import { Inject, Injector } from '@wendellhu/redi';import { DebuggerController } from './controllers/debugger.controller';+import { PerformanceMonitorController } from './controllers/performance-monitor.controller';export interface IDebuggerPluginConfig {}export class DebuggerPlugin extends Plugin {- static override type = PluginType.Sheet;+ static override type = PluginType.Doc;private _debuggerController!: DebuggerController;@@ -32,6 +34,7 @@ export class DebuggerPlugin extends Plugin {@Inject(LocaleService) private readonly _localeService: LocaleService) {super('debugger');+ this._initializeDependencies(_injector);}initialize(): void {@@ -43,6 +46,10 @@ export class DebuggerPlugin extends Plugin {registerExtension() {}+ private _initializeDependencies(injector: Injector) {+ ([[PerformanceMonitorController]] as Dependency[]).forEach((d) => injector.add(d));+ }+override onRendered(): void {this.initialize();}diff --git a/examples/sheets/src/sheets-plugin-debugger/index.ts b/examples/univer-plugin-debugger/src/index.tssimilarity index 100%rename from examples/sheets/src/sheets-plugin-debugger/index.tsrename to examples/univer-plugin-debugger/src/index.tsdiff --git a/examples/univer-plugin-debugger/tsconfig.json b/examples/univer-plugin-debugger/tsconfig.jsonnew file mode 100644index 0000000000..d0ab2f2912--- /dev/null+++ b/examples/univer-plugin-debugger/tsconfig.json@@ -0,0 +1,11 @@+{+ "extends": "../../tsconfig.json",+ "compilerOptions": {+ "rootDir": "./src",+ "outDir": "lib",+ "esModuleInterop": true,+ "strictPropertyInitialization": false+ },+ "include": ["src/**/*"],+ "exclude": ["node_modules", "local"]+}diff --git a/packages/docs/src/views/doc-canvas-view.ts b/packages/docs/src/views/doc-canvas-view.tsindex 74c002e79c..f3586566b3 100644--- a/packages/docs/src/views/doc-canvas-view.ts+++ b/packages/docs/src/views/doc-canvas-view.ts@@ -21,10 +21,12 @@ import {IUniverInstanceService,LifecycleStages,OnLifecycle,+ RxDisposable,} from '@univerjs/core';import type { IRender, IWheelEvent, RenderManagerService, Scene } from '@univerjs/engine-render';import { Documents, EVENT_TYPE, IRenderManagerService, Layer, ScrollBar, Viewport } from '@univerjs/engine-render';import { Inject } from '@wendellhu/redi';+import { BehaviorSubject } from 'rxjs';import {DOCS_COMPONENT_DEFAULT_Z_INDEX,@@ -36,19 +38,24 @@ import {import { DocViewModelManagerService } from '../services/doc-view-model-manager.service';@OnLifecycle(LifecycleStages.Ready, DocCanvasView)-export class DocCanvasView {+export class DocCanvasView extends RxDisposable {private _scene!: Scene;private _currentDocumentModel!: DocumentDataModel;private _loadedMap = new Set();+ private readonly _fps$ = new BehaviorSubject<string>('');++ readonly fps$ = this._fps$.asObservable();+constructor(@IRenderManagerService private readonly _renderManagerService: RenderManagerService,@IConfigService private readonly _configService: IConfigService,@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,@Inject(DocViewModelManagerService) private readonly _docViewModelManagerService: DocViewModelManagerService) {+ super();this._initialize();}@@ -71,6 +78,10 @@ export class DocCanvasView {});}+ override dispose(): void {+ this._fps$.complete();+ }+private _addNewRender() {const documentModel = this._currentDocumentModel;@@ -157,10 +168,7 @@ export class DocCanvasView {if (should) {engine.runRenderLoop(() => {scene.render();- // const app = document.getElementById('app');- // if (app) {- // app.innerText = `fps:${Math.round(engine.getFps()).toString()}`;- // }+ this._fps$.next(Math.round(engine.getFps()).toString());});}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex a9121265c6..72cb7e1fa9 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -219,6 +219,9 @@ importers:data:specifier: workspace:*version: link:../data+ univer-plugin-debugger:+ specifier: workspace:*+ version: link:../univer-plugin-debuggerdevDependencies:esbuild:specifier: ^0.19.8@@ -295,6 +298,9 @@ importers:monaco-editor:specifier: 0.45.0version: 0.45.0+ univer-plugin-debugger:+ specifier: workspace:*+ version: link:../univer-plugin-debuggerdevDependencies:esbuild:specifier: ^0.19.8@@ -364,6 +370,60 @@ importers:specifier: ^5.3.3version: 5.3.3+ examples/univer-plugin-debugger:+ dependencies:+ '@univerjs/core':+ specifier: workspace:*+ version: link:../../packages/core+ '@univerjs/design':+ specifier: workspace:*+ version: link:../../packages/design+ '@univerjs/docs':+ specifier: workspace:*+ version: link:../../packages/docs+ '@univerjs/docs-ui':+ specifier: workspace:*+ version: link:../../packages/docs-ui+ '@univerjs/engine-formula':+ specifier: workspace:*+ version: link:../../packages/engine-formula+ '@univerjs/engine-render':+ specifier: workspace:*+ version: link:../../packages/engine-render+ '@univerjs/local-save':+ specifier: workspace:*+ version: link:../../packages/local-save+ '@univerjs/rpc':+ specifier: workspace:*+ version: link:../../packages/rpc+ '@univerjs/sheets':+ specifier: workspace:*+ version: link:../../packages/sheets+ '@univerjs/sheets-formula':+ specifier: workspace:*+ version: link:../../packages/sheets-formula+ '@univerjs/sheets-numfmt':+ specifier: workspace:*+ version: link:../../packages/sheets-numfmt+ '@univerjs/sheets-ui':+ specifier: workspace:*+ version: link:../../packages/sheets-ui+ '@univerjs/ui':+ specifier: workspace:*+ version: link:../../packages/ui+ '@univerjs/uniscript':+ specifier: workspace:*+ version: link:../../packages/uniscript+ '@wendellhu/redi':+ specifier: ^0.12.12+ version: 0.12.12+ monaco-editor:+ specifier: 0.45.0+ version: 0.45.0+ rxjs:+ specifier: ^7.8.1+ version: 7.8.1+packages/core:dependencies:dayjs:@@ -16591,7 +16651,6 @@ packages:resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==}dependencies:tslib: 2.6.2- dev: trueresolution: {integrity: sha512-6XbUAseYE2KtOuGueyeobCySj9L4+66Tn6KQMOPQJrAJEowYKW/YR/MGJZl7FdydUdaFu4LYyDZjxf4/Nmo23Q==}diff --git a/tsconfig.json b/tsconfig.jsonindex feb63a9557..9ef3b703d0 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -91,6 +91,9 @@{"path": "./examples/data"},+ {+ "path": "./examples/univer-plugin-debugger"+ },{"path": "./examples/docs"},