Skip to content

Commit

Permalink
chore: better code
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Aug 14, 2024
1 parent ff8300b commit 7b092a1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 64 deletions.
13 changes: 2 additions & 11 deletions packages/slides-ui/src/controllers/canvas-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { IPageElement, Nullable } from '@univerjs/core';
import { Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
import { LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
import type {
BaseObject,
IRenderModule,
Expand All @@ -24,25 +24,16 @@ import {
IRenderManagerService,
} from '@univerjs/engine-render';

import type { PageID } from '../type';
import { SlideRenderController } from './slide.render-controller';

export enum SLIDE_KEY {
COMPONENT = '__slideRender__',
SCENE = '__mainScene__',
VIEW = '__mainView__',
}

export type PageID = string;

// export const ICanvasView = createIdentifier<IUniverInstanceService>('univer.slide.canvas-view');
@OnLifecycle(LifecycleStages.Ready, CanvasView)
export class CanvasView extends RxDisposable implements IRenderModule {
constructor(
// this controller needs by commands. root injector. T
// That means this controller is not init by renderUnit ---> no renderContext.
// private readonly _renderContext: IRenderContext<UnitModel>,
@Inject(Injector) private readonly _injector: Injector,
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService
) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import type {
IDocumentBody,
IPosition,
Nullable,
UnitModel,
} from '@univerjs/core';
SlideDataModel,

UnitModel } from '@univerjs/core';
import {
DEFAULT_EMPTY_DOCUMENT_VALUE,
Direction,
Expand All @@ -35,11 +36,11 @@ import {
ICommandService,
IContextService,
Inject,
IResourceLoaderService,
IUndoRedoService,
IUniverInstanceService,
LocaleService,
toDisposable,
UniverInstanceType,
VerticalAlign,
WrapStrategy,
} from '@univerjs/core';
Expand Down Expand Up @@ -124,41 +125,36 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(LocaleService) protected readonly _localService: LocaleService,
@IEditorService private readonly _editorService: IEditorService,
@IResourceLoaderService private readonly _resourceLoaderService: IResourceLoaderService
@IEditorService private readonly _editorService: IEditorService
) {
super();

// this._workbookSelections = selectionManagerService.getWorkbookSelections(this._context.unitId);

// EditingRenderController is per unit. It should only handle keyboard events when the unit is
// the current of its type.
// this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
// if (workbook?.getUnitId() === this._context.unitId) {
// this._d = this._init();
// } else {
// this._disposeCurrent();

// // Force ending editor when he switch to another workbook.
// if (this._isUnitEditing) {
// this._handleEditorInvisible({
// visible: false,
// eventType: DeviceInputEventType.Keyboard,
// keycode: KeyCode.ESC,
// unitId: this._context.unitId,
// });

// this._isUnitEditing = false;
// }
// }
// }));
this._d = this._init();
this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE).subscribe((slideDataModel) => {
if (slideDataModel && slideDataModel.getUnitId() === this._renderContext.unitId) {
this._d = this._init();
} else {
this._disposeCurrent();

// Force ending editor when he switch to another workbook.
if (this._isUnitEditing) {
this._handleEditorInvisible({
visible: false,
eventType: DeviceInputEventType.Keyboard,
keycode: KeyCode.ESC,
unitId: this._renderContext.unitId,
});

this._isUnitEditing = false;
}
}
}));
this._initEditorVisibilityListener();
}

override dispose(): void {
super.dispose();

this._disposeCurrent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/

import type { IDisposable, Nullable, SlideDataModel, UnitModel } from '@univerjs/core';
import { DisposableCollection, ICommandService, IContextService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import {
TextSelectionManagerService,
} from '@univerjs/docs';
import { DisposableCollection, ICommandService, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';

import type { BaseObject, IRenderContext, IRenderModule, RichText, Scene, Slide } from '@univerjs/engine-render';
import { DeviceInputEventType, ITextSelectionRenderManager, ObjectType } from '@univerjs/engine-render';
import { DeviceInputEventType, ObjectType } from '@univerjs/engine-render';
import { Subject } from 'rxjs';
import { UpdateSlideElementOperation } from '../commands/operations/update-element.operation';
import type { ISetEditorInfo } from '../services/slide-editor-bridge.service';
Expand Down Expand Up @@ -50,31 +48,35 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I
setSlideTextEditor$: Subject<ISlideRichTextProps> = new Subject();

private _curRichText = null as RichText | null;

private _d: Nullable<IDisposable>;

constructor(
private readonly _renderContext: IRenderContext<UnitModel>,
@IContextService private readonly _contextService: IContextService,
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@ICommandService private readonly _commandService: ICommandService,
@ISlideEditorBridgeService private readonly _editorBridgeService: ISlideEditorBridgeService,
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
@ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager
@ISlideEditorBridgeService private readonly _editorBridgeService: ISlideEditorBridgeService
) {
super();
//wait for sceneMap
Promise.resolve().then(() => this._init());

this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE).subscribe((slideDataModel) => {
if (slideDataModel && slideDataModel.getUnitId() === this._renderContext.unitId) {
this._d = this._init();
} else {
this._disposeCurrent();
}
}));
}

private _init(): IDisposable {
const d = new DisposableCollection();
this._initSubjectListener(d);
this._initEventListener(d);
return d;
}

private _initSubjectListener(d: DisposableCollection) {
// d.add(this.setSlideTextEditor$.subscribe((param: ISlideTextEditorParam) => {
// this._updateEditor(param);
// }));
private _disposeCurrent(): void {
this._d?.dispose();
this._d = null;
}

private _setEditorRect(pageId: string, targetObject: RichText) {
Expand Down
11 changes: 2 additions & 9 deletions packages/slides-ui/src/controllers/slide.render-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ import {
Viewport,
} from '@univerjs/engine-render';

import { ObjectProvider } from '@univerjs/slides';

export enum SLIDE_KEY {
COMPONENT = '__slideRender__',
SCENE = '__mainScene__',
VIEW = '__mainView__',
}

export type PageID = string;
import { ObjectProvider, SLIDE_KEY } from '@univerjs/slides';
import type { PageID } from '../type';

// export const ICanvasView = createIdentifier<IUniverInstanceService>('univer.slide.canvas-view');
export class SlideRenderController extends RxDisposable implements IRenderModule {
Expand Down
2 changes: 2 additions & 0 deletions packages/slides-ui/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export enum CursorChange {
StartEditor,
CursorChange,
}

export type PageID = string;

0 comments on commit 7b092a1

Please sign in to comment.