Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(docs-ui): refactor to RenderUnit #2539

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(docs-ui): refactor doc rendering to render unit
  • Loading branch information
wzhudev committed Jun 17, 2024
commit 43f0031f5c6ce1cd72afe6c9127d53ebfc780e72
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import { IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DocCanvasView } from '@univerjs/docs-ui';
import { DocRenderController } from '@univerjs/docs-ui';
import { Inject, Injector } from '@wendellhu/redi';
import { interval, takeUntil, throttle } from 'rxjs';
import { takeUntil } from 'rxjs';

@OnLifecycle(LifecycleStages.Rendered, PerformanceMonitorController)
export class PerformanceMonitorController extends RxDisposable {
Expand All @@ -27,7 +27,7 @@ export class PerformanceMonitorController extends RxDisposable {
private _styleElement!: HTMLStyleElement;

constructor(
@Inject(DocCanvasView) private _docCanvasView: DocCanvasView,
@Inject(DocRenderController) private _DocRenderController: DocRenderController,
@Inject(Injector) private _injector: Injector,
@IUniverInstanceService private _instanceService: IUniverInstanceService
) {
Expand Down Expand Up @@ -86,13 +86,6 @@ export class PerformanceMonitorController extends RxDisposable {
this._styleElement = document.createElement('style');
document.head.appendChild(this._styleElement).innerText = style;

if (this._documentType === UniverInstanceType.UNIVER_DOC) {
this._docCanvasView.fps$
.pipe(takeUntil(this.dispose$))
.pipe(throttle(() => interval(THROTTLE_TIME)))
.subscribe((fps) => {
container.innerText = `FPS: ${fps}`;
});
}
// TODO@wzhudev: monitor fps from engine
}
}
3 changes: 1 addition & 2 deletions packages/debugger/src/debugger-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Inject, Injector } from '@wendellhu/redi';

import type { IUniverDebuggerConfig } from './controllers/debugger.controller';
import { DebuggerController, DefaultDebuggerConfig } from './controllers/debugger.controller';
import { PerformanceMonitorController } from './controllers/performance-monitor.controller';
import { E2EMemoryController } from './controllers/e2e/e2e-memory.controller';

export class UniverDebuggerPlugin extends Plugin {
Expand All @@ -39,7 +38,7 @@ export class UniverDebuggerPlugin extends Plugin {

override onStarting(injector: Injector): void {
([
[PerformanceMonitorController],
// [PerformanceMonitorController],
[E2EMemoryController],
] as Dependency[]).forEach((d) => injector.add(d));
}
Expand Down
173 changes: 0 additions & 173 deletions packages/docs-ui/src/controllers/doc-render.controller.ts

This file was deleted.

17 changes: 11 additions & 6 deletions packages/docs-ui/src/docs-ui-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Inject, Injector } from '@wendellhu/redi';

import { IEditorService, IShortcutService } from '@univerjs/ui';

import { IRenderManagerService } from '@univerjs/engine-render';
import {
MoveCursorDownShortcut,
MoveCursorLeftShortcut,
Expand All @@ -48,13 +49,13 @@ import { BreakLineShortcut, DeleteLeftShortcut, DeleteRightShortcut } from './sh
import { DocClipboardService, IDocClipboardService } from './services/clipboard/clipboard.service';
import { DocClipboardController } from './controllers/clipboard.controller';
import { DocEditorBridgeController } from './controllers/doc-editor-bridge.controller';
import { DocRenderController } from './controllers/doc-render.controller';
import { DocCanvasView } from './views/doc-canvas-view';
import { DocRenderController } from './views/doc-canvas-view';
import { DocFloatingObjectController } from './controllers/doc-floating-object.controller';
import { ZoomController } from './controllers/zoom.controller';
import { TextSelectionController } from './controllers/text-selection.controller';
import { BackScrollController } from './controllers/back-scroll.controller';
import { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
import { DocsRenderService } from './services/doc-render.service';

export class UniverDocsUIPlugin extends Plugin {
static override pluginName = DOC_UI_PLUGIN_NAME;
Expand All @@ -64,6 +65,7 @@ export class UniverDocsUIPlugin extends Plugin {
private readonly _config: IUniverDocsUIConfig,
@Inject(Injector) override _injector: Injector,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService,
@ILogService private _logService: ILogService
) {
super();
Expand Down Expand Up @@ -108,7 +110,7 @@ export class UniverDocsUIPlugin extends Plugin {
],
[DocClipboardController],
[DocEditorBridgeController],
[DocRenderController],
[DocsRenderService],
[DocFloatingObjectController],
[ZoomController],
[TextSelectionController],
Expand All @@ -127,9 +129,6 @@ export class UniverDocsUIPlugin extends Plugin {
},
],
[DocCanvasPopManagerService],

// Render views
[DocCanvasView],
];

dependencies.forEach((d) => {
Expand All @@ -155,5 +154,11 @@ export class UniverDocsUIPlugin extends Plugin {

private _initModules(): void {
this._injector.get(AppUIController);

([
DocRenderController,
]).forEach((m) => {
this._renderManagerSrv.registerRenderController(UniverInstanceType.UNIVER_DOC, m);
});
}
}
2 changes: 1 addition & 1 deletion packages/docs-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

export * from './basics';
export * from './docs-ui-plugin';
export { DocCanvasView } from './views/doc-canvas-view';
export { DocRenderController } from './views/doc-canvas-view';
export * from './services';
export { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
export { docDrawingPositionToTransform, transformToDocDrawingPosition } from './basics/transform-position';
57 changes: 57 additions & 0 deletions packages/docs-ui/src/services/doc-render.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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:https://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 type { DocumentDataModel } from '@univerjs/core';
import { IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { takeUntil } from 'rxjs';

@OnLifecycle(LifecycleStages.Ready, DocsRenderService)
export class DocsRenderService extends RxDisposable {
constructor(
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService
) {
super();

Promise.resolve().then(() => this._init());
}

private _init() {
this._instanceSrv.getTypeOfUnitAdded$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)
.pipe(takeUntil(this.dispose$))
.subscribe((doc) => this._createRenderer(doc));
this._instanceSrv.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)
.forEach((documentModel) => this._createRenderer(documentModel));

this._instanceSrv.getTypeOfUnitDisposed$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)
.pipe(takeUntil(this.dispose$))
.subscribe((doc) => this._disposeRenderer(doc));
}

private _createRenderer(doc: DocumentDataModel) {
const unitId = doc.getUnitId();
this._renderManagerService.createRender(unitId);

// NOTE@wzhudev: maybe not in univer mode
this._renderManagerService.setCurrent(unitId);
}

private _disposeRenderer(doc: DocumentDataModel) {
const unitId = doc.getUnitId();
this._renderManagerService.removeRender(unitId);
}
}