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 19 commits
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
2 changes: 1 addition & 1 deletion e2e/disposing/disposing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('no error on constructing and disposing', async ({ page }) => {
await page.waitForTimeout(2000);

await page.evaluate(() => window.E2EControllerAPI.loadDefaultSheet());
await page.waitForTimeout(2000);
await page.waitForTimeout(6000); // wait for features loaded in STEADY stage (5s)

await page.evaluate(() => window.E2EControllerAPI.disposeUniver());
await page.waitForTimeout(2000);
Expand Down
9 changes: 3 additions & 6 deletions examples/src/docs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
*/

/* eslint-disable node/prefer-global/process */

import { LocaleType, Univer, UniverInstanceType } from '@univerjs/core';
import { defaultTheme } from '@univerjs/design';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { UniverUIPlugin } from '@univerjs/ui';
import { UniverDrawingPlugin } from '@univerjs/drawing';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverDebuggerPlugin } from '@univerjs/debugger';
import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui';
import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing';
import { UniverDocsDrawingUIPlugin } from '@univerjs/docs-drawing-ui';

import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
import { enUS, ruRU, zhCN } from '../locales';

Expand Down Expand Up @@ -58,7 +57,7 @@ univer.registerPlugin(UniverUIPlugin, {
container: 'app',
footer: false,
});
univer.registerPlugin(UniverDrawingPlugin);

univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverDocsUIPlugin, {
container: 'univerdoc',
Expand All @@ -69,8 +68,6 @@ univer.registerPlugin(UniverDocsUIPlugin, {
},
});

univer.registerPlugin(UniverDrawingUIPlugin);
univer.registerPlugin(UniverDocsDrawingPlugin);
univer.registerPlugin(UniverDocsDrawingUIPlugin);

univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_CN);
Expand Down
2 changes: 1 addition & 1 deletion examples/src/sheets/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc';
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula';
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
import { UniverSheetsDrawingUIPlugin } from '@univerjs/sheets-drawing-ui';
import { FUniver } from '@univerjs/facade';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { enUS, ruRU, zhCN } from '../locales';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '../data/sheets/demo/default-workbook-data-demo';

Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/common/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
* limitations under the License.
*/

export const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = '__defaultDocumentNormalEditorSpecialUnitId_20231006__';
const PREFIX = '__INTERNAL_EDITOR__';

export const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = '__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__';
export const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = `${PREFIX}DOCS_NORMAL`;

export const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = `${PREFIX}DOCS_FORMULA_BAR`;

export const DEFAULT_EMPTY_DOCUMENT_VALUE = '\r\n';

export function createInternalEditorID(id: string) {
return `__internalEditorId__${id}`;
return `${PREFIX}${id}`;
}

export function isInternalEditorID(id: string) {
return id.startsWith('__');
return id.startsWith(PREFIX);
}
2 changes: 1 addition & 1 deletion packages/core/src/services/instance/instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface IUniverInstanceService {
/** Subscribe to curtain type of units' creation. */
getTypeOfUnitAdded$<T extends UnitModel>(type: UnitType): Observable<T>;

/** @interal */
/** @ignore */
__addUnit(unit: UnitModel): void;

/** Omits value when a UnitModel is disposed. */
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/undoredo/undoredo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface IUndoRedoService {
popUndoToRedo(): void;
popRedoToUndo(): void;

clearUndoRedo(unitID: string): void;
clearUndoRedo(unitId: string): void;

/**
* Batch undo redo elements into a single `IUndoRedoItem` util the returned `IDisposable` is called.
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export interface IInsertImageOperationParams {
files: Nullable<File[]>;
};

/**
* @deprecated Do not use command as event!
*/
export const InsertDocImageOperation: IOperation<IInsertImageOperationParams> = {
id: 'doc.operation.insert-float-image',
type: CommandType.OPERATION,
handler: (accessor, params) => {
return true;
},
handler: () => true,
};