refactor!: remove runOnLifecycle and add smoking tests (#3672)

Co-authored-by: GitHub Actions <actions@github.com>
This commit is contained in:
Wenzhao Hu
2024-10-10 19:22:32 +08:00
committed by GitHub
parent a2f22158ff
commit f5e97b186b
275 changed files with 1502 additions and 1486 deletions
+4 -6
View File
@@ -14,11 +14,7 @@
* limitations under the License.
*/
import React from 'react';
import type { Preview } from '@storybook/react';
import { ConfigProvider, defaultTheme, greenTheme, themeInstance } from '@univerjs/design';
import zhCN from '@univerjs/design/locale/zh-CN';
import enUS from '@univerjs/design/locale/en-US';
import {
CommandService,
ConfigService,
@@ -35,7 +31,6 @@ import {
IResourceManagerService,
IUndoRedoService,
IUniverInstanceService,
LifecycleInitializerService,
LifecycleService,
LocaleService,
LocaleType,
@@ -46,7 +41,11 @@ import {
ThemeService,
UniverInstanceService,
} from '@univerjs/core';
import { ConfigProvider, defaultTheme, greenTheme, themeInstance } from '@univerjs/design';
import enUS from '@univerjs/design/locale/en-US';
import zhCN from '@univerjs/design/locale/zh-CN';
import { DesktopLocalStorageService } from '@univerjs/ui';
import React from 'react';
export const themes: Record<string, Record<string, string>> = {
default: defaultTheme,
@@ -94,7 +93,6 @@ const preview: Preview = {
[LocaleService],
[ThemeService],
[LifecycleService],
[LifecycleInitializerService],
[ILogService, { useClass: DesktopLogService, lazy: true }],
[ICommandService, { useClass: CommandService, lazy: true }],
[IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],
-1
View File
@@ -65,7 +65,6 @@ test('no error on constructing and disposing sheet unit', async ({ page }) => {
});
test('no error when dispose a unit', async ({ page }) => {
// test.setTimeout(40 * 1000);
let errored = false;
page.on('pageerror', (error) => {
+6
View File
@@ -0,0 +1,6 @@
# Notes on Smoking
These tests make sure that all the demo pages can be loaded without any errors. Some demos are implemented in visual comparison tests, so they are not included in this suite.
- docs
- sheets
@@ -0,0 +1,31 @@
/**
* 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 { expect, test } from '@playwright/test';
test('ensure mobile-s boots up without errors', async ({ page }) => {
let errored = false;
page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});
await page.goto('http://localhost:3000/mobile-s/');
await page.waitForTimeout(10000);
expect(errored).toBeFalsy();
});
@@ -0,0 +1,31 @@
/**
* 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 { expect, test } from '@playwright/test';
test('ensure sheets-multi boots up without errors', async ({ page }) => {
let errored = false;
page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});
await page.goto('http://localhost:3000/sheets-multi/');
await page.waitForTimeout(10000);
expect(errored).toBeFalsy();
});
@@ -14,11 +14,18 @@
* limitations under the License.
*/
import { Disposable, Inject, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
import { expect, test } from '@playwright/test';
@OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController)
export class NumfmtI18nController extends Disposable {
constructor(@Inject(LocaleService) private _localeService: LocaleService) {
super();
}
}
test('ensure uni boots up without errors', async ({ page }) => {
let errored = false;
page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});
await page.goto('http://localhost:3000/uni/');
await page.waitForTimeout(10000);
expect(errored).toBeFalsy();
});
+3 -1
View File
@@ -1,4 +1,6 @@
# Notes on visual comparison
# Notes on Visual Comparison
You should set `maxDiffPixels` on a minimum value. The cursor may be different in snapshots because it is blinking,
especially in rich-text editors.
For more instructions, please read related part in [CONTRIBUTING.md](../../CONTRIBUTING.md).
@@ -18,6 +18,13 @@ import { expect, test } from '@playwright/test';
import { generateSnapshotName } from '../const';
test('diff default doc content', async ({ page }) => {
let errored = false;
page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});
await page.goto('http://localhost:3000/docs/');
await page.waitForTimeout(2000);
@@ -25,4 +32,5 @@ test('diff default doc content', async ({ page }) => {
await page.waitForTimeout(5000);
await expect(page).toHaveScreenshot(generateSnapshotName('default-doc'), { maxDiffPixels: 30 });
expect(errored).toBeFalsy();
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB

@@ -28,6 +28,13 @@ test('diff default sheet content', async ({ page }) => {
});
test('diff demo sheet content', async ({ page }) => {
let errored = false;
page.on('pageerror', (error) => {
console.error('Page error:', error);
errored = true;
});
await page.goto('http://localhost:3000/sheets/');
await page.waitForTimeout(2000);
@@ -35,4 +42,5 @@ test('diff demo sheet content', async ({ page }) => {
await page.waitForTimeout(5000);
await expect(page).toHaveScreenshot(generateSnapshotName('demo-sheet'), { maxDiffPixels: 5 });
expect(errored).toBeFalsy();
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

+4 -2
View File
@@ -27,9 +27,10 @@ import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { UniverSheetsPlugin } from '@univerjs/sheets';
import { UniverSheetsConditionalFormattingMobileUIPlugin } from '@univerjs/sheets-conditional-formatting-ui';
import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
import { UniverSheetsDataValidationMobileUIPlugin } from '@univerjs/sheets-data-validation-ui';
import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';
import { UniverSheetsFilterMobileUIPlugin } from '@univerjs/sheets-filter-ui';
import { UniverSheetsFormulaMobilePlugin } from '@univerjs/sheets-formula';
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula';
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsMobileUIPlugin } from '@univerjs/sheets-ui';
import { UniverMobileUIPlugin } from '@univerjs/ui';
@@ -65,9 +66,10 @@ univer.registerPlugin(UniverSheetsMobileUIPlugin);
univer.registerPlugin(UniverSheetsFilterPlugin);
univer.registerPlugin(UniverSheetsFilterMobileUIPlugin);
univer.registerPlugin(UniverSheetsNumfmtPlugin);
univer.registerPlugin(UniverSheetsFormulaMobilePlugin);
univer.registerPlugin(UniverSheetsFormulaPlugin);
univer.registerPlugin(UniverSheetsConditionalFormattingMobileUIPlugin);
univer.registerPlugin(UniverSheetsDataValidationPlugin);
univer.registerPlugin(UniverSheetsDataValidationMobileUIPlugin);
const mockUser = {
userID: 'Owner_qxVnhPbQ',
+3 -1
View File
@@ -19,6 +19,7 @@ import { defaultTheme } from '@univerjs/design';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';
import { UniverSheetsPlugin } from '@univerjs/sheets';
@@ -29,8 +30,8 @@ import { UniverUIPlugin } from '@univerjs/ui';
import React, { useEffect } from 'react';
import { createRoot } from 'react-dom/client';
import { Mosaic, MosaicWindow } from 'react-mosaic-component';
import { enUS, ruRU, zhCN } from '../locales';
import { enUS, ruRU, zhCN } from '../locales';
import 'react-mosaic-component/react-mosaic-component.css';
import './index.css';
@@ -47,6 +48,7 @@ function factory(id: string) {
logLevel: LogLevel.VERBOSE,
});
univer.registerPlugin(UniverFormulaEnginePlugin);
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, {
container: id,
+1 -1
View File
@@ -25,8 +25,8 @@ import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { FUniver } from '@univerjs/facade';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { UniverSheetsPlugin } from '@univerjs/sheets';
import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
+3 -8
View File
@@ -48,9 +48,6 @@ import { UniSlidesUIController } from '@univerjs/uni-slides-ui';
import { UniverUniUIPlugin } from '@univerjs/uniui';
import { enUS } from '../locales';
/* eslint-disable-next-line node/prefer-global/process */
const IS_E2E: boolean = !!process.env.IS_E2E;
const LOAD_LAZY_PLUGINS_TIMEOUT = 4_000;
// univer
@@ -99,11 +96,9 @@ class CustomMentionDataService implements IThreadCommentMentionDataService {
}
// create univer instances
if (!IS_E2E) {
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_EN);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO1);
}
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_EN);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO1);
// debugger plugin
univer.registerPlugin(UniverDebuggerPlugin);
@@ -14,9 +14,8 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject, Injector } from '@univerjs/core';
import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';
import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand, LoadSheetSnapshotCommand } from '../commands/commands/unit.command';
import { ShowCellContentOperation } from '../commands/operations/cell.operation';
@@ -28,19 +27,18 @@ import { MessageOperation } from '../commands/operations/message.operation';
import { NotificationOperation } from '../commands/operations/notification.operation';
import { SaveSnapshotOptions } from '../commands/operations/save-snapshot.operations';
import { SetEditable } from '../commands/operations/set.editable.operation';
import { SidebarOperation } from '../commands/operations/sidebar.operation';
import { ThemeOperation } from '../commands/operations/theme.operation';
import { ImageDemo } from '../components/Image';
// @ts-ignore
import VueI18nIcon from '../components/VueI18nIcon.vue';
import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-name';
import { TestEditorContainer } from '../views/test-editor/TestTextEditor';
import { RecordController } from './local-save/record.controller';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, DebuggerController)
export class DebuggerController extends Disposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
@@ -14,13 +14,12 @@
* limitations under the License.
*/
import { Inject, IUniverInstanceService, LifecycleService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { distinctUntilChanged, filter, take, takeUntil } from 'rxjs';
import type { Nullable } from '@univerjs/core';
import type { Subscription } from 'rxjs';
import { Inject, IUniverInstanceService, LifecycleService, LifecycleStages, RxDisposable } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { distinctUntilChanged, filter, take, takeUntil } from 'rxjs';
@OnLifecycle(LifecycleStages.Rendered, PerformanceMonitorController)
export class PerformanceMonitorController extends RxDisposable {
private _initListener = false;
private _containerElement!: HTMLDivElement;
@@ -52,6 +52,14 @@ export class UniverDebuggerPlugin extends Plugin {
this._injector.get(E2EController);
}
override onReady(): void {
this._injector.get(DebuggerController);
}
override onRendered(): void {
this._injector.get(PerformanceMonitorController);
}
getDebuggerController() {
this._debuggerController = this._injector.get(DebuggerController);
return this._debuggerController;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IMAGE_MENU_ID as DocsImageMenuId } from '@univerjs/docs-drawing-ui';
import { BulletListCommand, DocCreateTableOperation, DocUIController, OrderListCommand, SetInlineFormatBoldCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '@univerjs/docs-ui';
import { ComponentManager, ILayoutService, IMenuManagerService, IShortcutService, IUIPartsService } from '@univerjs/ui';
@@ -22,7 +22,6 @@ import { BuiltinUniToolbarItemId, generateCloneMutation, UniToolbarService } fro
import { DOC_BOLD_MUTATION_ID, DOC_ITALIC_MUTATION_ID, DOC_STRIKE_MUTATION_ID, DOC_TABLE_MUTATION_ID, DOC_UNDERLINE_MUTATION_ID } from './menu';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, UniDocsUIController)
export class UniDocsUIController extends DocUIController {
constructor(
@Inject(Injector) injector: Injector,
@@ -14,23 +14,22 @@
* limitations under the License.
*/
import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { DocumentDataModel } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import type { IShowFormulaPopupOperationParams } from '../commands/operations/operation';
import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { DeleteLeftCommand, DocEventManagerService, IEditorService, InsertCommand, MoveCursorOperation } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { filter, map, mergeMap } from 'rxjs';
import type { DocumentDataModel } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import { AddDocUniFormulaCommand, RemoveDocUniFormulaCommand, UpdateDocUniFormulaCommand } from '../commands/commands/doc.command';
import { CloseFormulaPopupOperation, ShowFormulaPopupOperation } from '../commands/operations/operation';
import { UniFormulaPopupService } from '../services/formula-popup.service';
import { UNI_FORMULA_EDITOR_ID } from '../views/components/DocFormulaPopup';
import type { IShowFormulaPopupOperationParams } from '../commands/operations/operation';
const FORMULA_INPUT_TRIGGER_CHAR = '=';
@OnLifecycle(LifecycleStages.Steady, DocUniFormulaInputController)
export class DocUniFormulaInputController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -14,20 +14,19 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import type { IShowFormulaPopupOperationParams, ISlidePopupPosition } from '../commands/operations/operation';
import { Disposable, ICommandService, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { IEditorService, InsertCommand } from '@univerjs/docs-ui';
import { ISlideEditorBridgeService } from '@univerjs/slides-ui';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import { AddSlideUniFormulaCommand } from '../commands/commands/slide.command';
import { CloseFormulaPopupOperation, ShowFormulaPopupOperation } from '../commands/operations/operation';
import { UniFormulaPopupService } from '../services/formula-popup.service';
import { UNI_FORMULA_EDITOR_ID } from '../views/components/DocFormulaPopup';
import type { IShowFormulaPopupOperationParams, ISlidePopupPosition } from '../commands/operations/operation';
const FORMULA_INPUT_TRIGGER_CHAR = '=';
@OnLifecycle(LifecycleStages.Steady, SlideUniFormulaInputController)
export class SlideUniFormulaInputController extends Disposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
@@ -14,12 +14,11 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { ComponentManager } from '@univerjs/ui';
import { UniFormulaPopup } from '../views/components/DocFormulaPopup';
import { CloseFormulaPopupOperation, ConfirmFormulaPopupCommand, ShowFormulaPopupOperation } from '../commands/operations/operation';
import { UniFormulaPopup } from '../views/components/DocFormulaPopup';
@OnLifecycle(LifecycleStages.Steady, UniFormulaUniController)
export class UniFormulaUniController extends Disposable {
constructor(
@ICommandService private readonly _commandSrv: ICommandService,
@@ -19,12 +19,12 @@ import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univ
import { IUniFormulaService, UniverDocUniFormulaPlugin } from '@univerjs/uni-formula';
import { DOC_FORMULA_UI_PLUGIN_NAME } from './const';
import { UniFormulaPopupService } from './services/formula-popup.service';
import { DocUniFormulaInputController } from './controllers/doc-formula-input.controller';
import { UniFormulaService } from './services/uni-formula.service';
import { UniFormulaUniController } from './controllers/uni-formula-ui.controller';
import { SlideUniFormulaInputController } from './controllers/slide-formula-input.controller';
import { UniFormulaUniController } from './controllers/uni-formula-ui.controller';
import { UniFormulaPopupService } from './services/formula-popup.service';
import { SlideUIFormulaCacheService } from './services/slide-ui-formula-cache.service';
import { UniFormulaService } from './services/uni-formula.service';
@DependentOn(UniverDocUniFormulaPlugin)
export class UniverDocUniFormulaUIPlugin extends Plugin {
@@ -52,4 +52,10 @@ export class UniverDocUniFormulaUIPlugin extends Plugin {
override onReady(): void {
this._injector.get(IUniFormulaService);
}
override onSteady(): void {
this._injector.get(UniFormulaUniController);
this._injector.get(DocUniFormulaInputController);
this._injector.get(SlideUniFormulaInputController);
}
}
@@ -15,7 +15,7 @@
*/
import type { Workbook } from '@univerjs/core';
import { connectInjector, ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, useDependency } from '@univerjs/core';
import { connectInjector, ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';
import { SetBackgroundColorCommand } from '@univerjs/sheets';
import { IMAGE_MENU_ID as SheetsImageMenuId } from '@univerjs/sheets-drawing-ui';
import { RenderSheetContent, SetRangeBoldCommand, SetRangeFontFamilyCommand, SetRangeFontSizeCommand, SetRangeItalicCommand, SetRangeStrickThroughCommand, SetRangeTextColorCommand, SetRangeUnderlineCommand, SheetUIController } from '@univerjs/sheets-ui';
@@ -26,7 +26,6 @@ import { UniSheetBar } from '../views/uni-sheet-bar/UniSheetBar';
import { SHEET_BOLD_MUTATION_ID, SHEET_ITALIC_MUTATION_ID, SHEET_STRIKE_MUTATION_ID, SHEET_UNDERLINE_MUTATION_ID } from './menu';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, SheetUIController)
export class UniSheetsUIController extends SheetUIController {
constructor(
@Inject(Injector) injector: Injector,
@@ -14,16 +14,15 @@
* limitations under the License.
*/
import React from 'react';
import type { SlideDataModel } from '@univerjs/core';
import { connectInjector, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, useDependency } from '@univerjs/core';
import { connectInjector, ICommandService, Inject, Injector, IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';
import { IMAGE_MENU_ID, SHAPE_MENU_ID, SlideAddTextCommand, SlideEditorContainer, SlidesUIController } from '@univerjs/slides-ui';
import { BuiltInUIPart, ComponentManager, IMenuManagerService, IShortcutService, IUIPartsService, useObservable } from '@univerjs/ui';
import { BuiltinUniToolbarItemId, UniToolbarService, UniUIPart } from '@univerjs/uniui';
import React from 'react';
import { UniSlideSideBar } from '../views/UniSlideSideBar';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, UniSlidesUIController)
export class UniSlidesUIController extends SlidesUIController {
constructor(
@Inject(Injector) _injector: Injector,
@@ -14,14 +14,13 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { IFlowViewport } from '../services/flow/flow-manager.service';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { auditTime, throttleTime } from 'rxjs';
import { SetFlowViewportOperation } from '../commands/operations/set-flow-viewport.operation';
import type { IFlowViewport } from '../services/flow/flow-manager.service';
import { FlowManagerService } from '../services/flow/flow-manager.service';
import { UniFocusUnitOperation } from '../commands/operations/uni-focus-unit.operation';
import { FlowManagerService } from '../services/flow/flow-manager.service';
@OnLifecycle(LifecycleStages.Ready, UniuiFlowController)
export class UniuiFlowController extends Disposable {
constructor(
@ICommandService protected readonly _commandService: ICommandService,
@@ -14,15 +14,14 @@
* limitations under the License.
*/
import { Disposable, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { ISidebarService } from '@univerjs/ui';
import { Disposable, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { ComponentManager, ILeftSidebarService } from '@univerjs/ui';
import { distinctUntilChanged, map } from 'rxjs';
import { Outline } from '../views/outline/Outline';
const OUTLINE_COMPONENT = 'OUTLINE_COMPONENT';
@OnLifecycle(LifecycleStages.Ready, UniuiLeftSidebarController)
export class UniuiLeftSidebarController extends Disposable {
constructor(
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@@ -14,9 +14,9 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { DeleteSingle, DownloadSingle, LockSingle, PivotTableSingle, PrintSingle, ShareSingle, ZenSingle } from '@univerjs/icons';
import type { MenuConfig } from '@univerjs/ui';
import { Disposable, ICommandService, Inject, Injector } from '@univerjs/core';
import { DeleteSingle, DownloadSingle, LockSingle, PivotTableSingle, PrintSingle, ShareSingle, ZenSingle } from '@univerjs/icons';
import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
import { DisposeUnitOperation } from '../commands/operations/uni.operation';
import { UniToolbarService } from '../services/toolbar/uni-toolbar-service';
@@ -28,7 +28,6 @@ export interface IUniuiToolbarConfig {
export const DefaultUniuiToolbarConfig = {};
@OnLifecycle(LifecycleStages.Ready, UniuiToolbarController)
export class UniuiToolbarController extends Disposable {
constructor(
@IMenuManagerService protected readonly _menuManagerService: IMenuManagerService,
+13 -7
View File
@@ -14,8 +14,9 @@
* limitations under the License.
*/
import type { Dependency } from '@univerjs/core';
import type { IUniverUIConfig } from '@univerjs/ui';
import { DependentOn, IContextService, ILocalStorageService, Inject, Injector, mergeOverrideWithDependencies, Plugin, Tools } from '@univerjs/core';
import { EditorService, IEditorService, IRangeSelectorService, RangeSelectorService } from '@univerjs/docs-ui';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import {
BrowserClipboardService,
@@ -28,6 +29,7 @@ import {
DesktopDialogService,
DesktopGlobalZoneService,
DesktopLayoutService,
DesktopLocalFileService,
DesktopLocalStorageService,
DesktopMessageService,
DesktopNotificationService,
@@ -44,6 +46,7 @@ import {
IGlobalZoneService,
ILayoutService,
ILeftSidebarService,
ILocalFileService,
IMenuManagerService,
IMenuService,
IMessageService,
@@ -67,8 +70,6 @@ import {
UNIVER_UI_PLUGIN_NAME,
ZIndexManager,
} from '@univerjs/ui';
import type { Dependency } from '@univerjs/core';
import type { IUniverUIConfig } from '@univerjs/ui';
import { UniverUniUIController } from './controllers/uniui-desktop.controller';
import { UniuiFlowController } from './controllers/uniui-flow.controller';
import { UniuiLeftSidebarController } from './controllers/uniui-leftsidebar.controller';
@@ -77,8 +78,6 @@ import { FlowManagerService } from './services/flow/flow-manager.service';
import { UniToolbarService } from './services/toolbar/uni-toolbar-service';
import { IUnitGridService, UnitGridService } from './services/unit-grid/unit-grid.service';
const UI_BOOTSTRAP_DELAY = 16;
/**
* This plugin enables the Uni Mode of Univer. It should replace
* `UniverUIPlugin` when registered.
@@ -126,8 +125,7 @@ export class UniverUniUIPlugin extends Plugin {
[IMessageService, { useClass: DesktopMessageService, lazy: true }],
[ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
[IBeforeCloseService, { useClass: DesktopBeforeCloseService }],
[IEditorService, { useClass: EditorService }],
[IRangeSelectorService, { useClass: RangeSelectorService }],
[ILocalFileService, { useClass: DesktopLocalFileService }],
[ICanvasPopupService, { useClass: CanvasPopupService }],
[IProgressService, { useClass: ProgressService }],
[CanvasFloatDomService],
@@ -142,5 +140,13 @@ export class UniverUniUIPlugin extends Plugin {
[UniuiFlowController],
], this._config.override);
dependencies.forEach((dependency) => this._injector.add(dependency));
this._injector.get(IUIController);
}
override onReady(): void {
this._injector.get(UniuiFlowController);
this._injector.get(UniuiLeftSidebarController);
this._injector.get(UniuiToolbarController);
}
}
@@ -14,10 +14,8 @@
* limitations under the License.
*/
import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type {
ReactFlowInstance,
} from '@xyflow/react';
import type { ReactFlowInstance } from '@xyflow/react';
import { Disposable } from '@univerjs/core';
import { BehaviorSubject } from 'rxjs';
@@ -27,7 +25,6 @@ export interface IFlowViewport {
y: number;
}
@OnLifecycle(LifecycleStages.Ready, FlowManagerService)
export class FlowManagerService extends Disposable {
private readonly _viewportChanged$ = new BehaviorSubject<IFlowViewport | null>(null);
readonly viewportChanged$ = this._viewportChanged$.asObservable();
+1 -2
View File
@@ -93,9 +93,8 @@ export { ContextService, IContextService } from './services/context/context.serv
export { ErrorService, type IError } from './services/error/error.service';
export { IUniverInstanceService } from './services/instance/instance.service';
export { UniverInstanceService } from './services/instance/instance.service';
export { LifecycleStages, OnLifecycle, runOnLifecycle } from './services/lifecycle/lifecycle';
export { LifecycleStages } from './services/lifecycle/lifecycle';
export { LifecycleService } from './services/lifecycle/lifecycle.service';
export { LifecycleInitializerService } from './services/lifecycle/lifecycle.service';
export { ILocalStorageService } from './services/local-storage/local-storage.service';
export { LocaleService } from './services/locale/locale.service';
export { DesktopLogService, ILogService, LogLevel } from './services/log/log.service';
@@ -370,13 +370,15 @@ export class CommandService extends Disposable implements ICommandService {
return result;
}
throw new Error(`[CommandService]: command "${id}" is not registered.`);
} catch (error) {
this._logService.error(error);
if (error instanceof CustomCommandExecutionError) {
// If need custom logic, can add it here
return false as R;
} else {
this._logService.error(error);
throw error;
}
}
@@ -19,13 +19,12 @@ import { Injector } from '../../../common/di';
import { DesktopLogService, ILogService } from '../../log/log.service';
import { LifecycleStages } from '../lifecycle';
import { LifecycleInitializerService, LifecycleService } from '../lifecycle.service';
import { LifecycleService } from '../lifecycle.service';
function createLifecycleTestBed() {
const injector = new Injector();
injector.add([ILogService, { useClass: DesktopLogService }]);
injector.add([LifecycleInitializerService]);
injector.add([LifecycleService]);
return {
@@ -117,34 +116,4 @@ describe('Test LifecycleService', () => {
expect(lifecycleStages4).toEqual(steadyStages);
expect(lifecycleStages5).toEqual(steadyStages);
});
// describe('Test automatically instantiate modules on lifecycle stages', () => {
// let initializer: LifecycleInitializerService;
// it('Should instantiate modules on lifecycle stages', () => {
// injector = createLifecycleTestBed().injector;
// initializer = injector.get(LifecycleInitializerService);
// lifecycleService = injector.get(LifecycleService);
// initializer.start();
// initializer.start(); // For just test coverage.
// const initModules: string[] = [];
// @OnLifecycle(LifecycleStages.Rendered, TestModule1)
// class TestModule1 {
// constructor() {
// initModules.push('test1');
// }
// }
// injector.add([TestModule1]);
// lifecycleService.stage = LifecycleStages.Starting;
// lifecycleService.stage = LifecycleStages.Ready;
// expect(initModules).toEqual([]);
// lifecycleService.stage = LifecycleStages.Rendered;
// expect(initModules).toEqual(['test1']);
// });
// });
});
@@ -16,13 +16,11 @@
import type { Observable } from 'rxjs';
import { BehaviorSubject, merge, of, skip } from 'rxjs';
import type { DependencyIdentifier } from '../../common/di';
import { Inject, Injector } from '../../common/di';
import { Disposable } from '../../shared/lifecycle';
import { ILogService } from '../log/log.service';
import { takeAfter } from '../../shared/rxjs';
import { LifecycleNameMap, LifecycleStages, LifecycleToModules } from './lifecycle';
import { ILogService } from '../log/log.service';
import { LifecycleNameMap, LifecycleStages } from './lifecycle';
/**
* This service controls the lifecycle of a Univer instance. Other modules can
@@ -76,33 +74,6 @@ export class LifecycleService extends Disposable {
}
}
/**
* This service is used to initialize modules on a certain lifecycle stage.
* Refer to `runOnLifecycle` and `OnLifecycle` for more details.
*
* @internal
*/
export class LifecycleInitializerService extends Disposable {
private _seenTokens = new Set<DependencyIdentifier<unknown>>();
constructor(
@Inject(Injector) private readonly _injector: Injector
) {
super();
}
initModulesOnStage(stage: LifecycleStages): void {
LifecycleToModules.get(stage)?.forEach((m) => {
if (this._injector.has(m) && !this._seenTokens.has(m)) {
this._injector.get(m);
// swap these two lines and they will be fixed
this._seenTokens.add(m);
}
});
}
}
export function getLifecycleStagesAndBefore(lifecycleStage: LifecycleStages): Observable<LifecycleStages> {
switch (lifecycleStage) {
case LifecycleStages.Starting:
@@ -14,8 +14,6 @@
* limitations under the License.
*/
import type { Ctor, DependencyIdentifier } from '../../common/di';
/**
* This enum defines multiple lifecycle stages in Univer SDK.
*/
@@ -48,59 +46,3 @@ export const LifecycleNameMap = {
[LifecycleStages.Rendered]: 'Rendered',
[LifecycleStages.Steady]: 'Steady',
};
export const LifecycleToModules = new Map<LifecycleStages, Array<DependencyIdentifier<unknown>>>();
/**
* Register the decorated class to be automatically instantiated when Univer progresses to the certain lifecycle stage.
*
* @param lifecycleStage The lifecycle stage to instantiate this class.
* @param identifier The dependency identifier of the class. Usually, it is the class itself unless you bind this class
* with another injection identifier.
*
* @deprecated This API does not work as expected and will be removed in future versions. Please call
* `this._injector.get(YourDependency)` in plugins' lifecycle hooks instead.
*
* @example
* // Ignore the `\` below. This is JSDoc's bug.
* \@OnLifecycle(LifecycleStages.Ready, MyService)
* class MyService {
* }
*
* @example
* // Ignore the `\` below. This is JSDoc's bug.
* \@OnLifecycle(LifecycleStages.Rendered, IMyService)
* class MyService implements IMyService {
* }
*/
export function OnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>) {
const decorator = function decorator(_: Ctor<unknown>) {
runOnLifecycle(lifecycleStage, identifier);
};
return decorator;
}
/**
* Register a dependency to be automatically instantiated when Univer progresses to the certain lifecycle stage.
*
* @param lifecycleStage The lifecycle stage to instantiate this dependency.
* @param identifier The dependencies' identifier. **Beware** that if the dependency (e.g. a class) is bound to an
* identifier, you should register the identifier instead of the dependency itself.
*
* @deprecated This API does not work as expected and will be removed in future versions. Please call
* `this._injector.get(YourDependency)` in plugins' lifecycle hooks instead.
*
* @example
* runOnLifecycle(LifecycleStages.Ready, MyService);
*
* @example
* runOnLifecycle(LifecycleStages.Rendered, IMyService);
*/
export function runOnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>) {
if (!LifecycleToModules.has(lifecycleStage)) {
LifecycleToModules.set(lifecycleStage, []);
}
LifecycleToModules.get(lifecycleStage)!.push(identifier);
}
@@ -15,10 +15,10 @@
*/
import type { Observable } from 'rxjs';
import type { IPermissionPoint, IPermissionService } from './type';
import { BehaviorSubject, combineLatest, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { Disposable } from '../../shared';
import type { IPermissionPoint, IPermissionService } from './type';
import { PermissionStatus } from './type';
export class PermissionService extends Disposable implements IPermissionService {
@@ -14,12 +14,11 @@
* limitations under the License.
*/
import type { BehaviorSubject, Observable } from 'rxjs';
import type { UnitAction, UnitObject } from '@univerjs/protocol';
import { createIdentifier } from '../../common/di';
import { LifecycleStages, runOnLifecycle } from '../lifecycle/lifecycle';
import type { IRange } from '../../sheets/typedef';
import type { BehaviorSubject, Observable } from 'rxjs';
import type { Nullable } from '../../shared/types';
import type { IRange } from '../../sheets/typedef';
import { createIdentifier } from '../../common/di';
export enum PermissionStatus {
INIT = 'init',
@@ -66,4 +65,3 @@ export interface IPermissionService {
}
export const IPermissionService = createIdentifier<IPermissionService>('univer.permission-service');
runOnLifecycle(LifecycleStages.Starting, IPermissionService);
@@ -14,14 +14,13 @@
* limitations under the License.
*/
import { skip } from 'rxjs';
import type { Ctor, IDisposable } from '../../common/di';
import { skip } from 'rxjs';
import { Inject, Injector } from '../../common/di';
import { Disposable } from '../../shared/lifecycle';
import { type UnitType, UniverInstanceType } from '../../common/unit';
import { Disposable } from '../../shared/lifecycle';
import { LifecycleStages } from '../lifecycle/lifecycle';
import { getLifecycleStagesAndBefore, LifecycleInitializerService, LifecycleService } from '../lifecycle/lifecycle.service';
import { getLifecycleStagesAndBefore, LifecycleService } from '../lifecycle/lifecycle.service';
import { ILogService } from '../log/log.service';
import { DependentOnSymbol, Plugin, type PluginCtor, PluginRegistry, PluginStore } from './plugin';
@@ -189,8 +188,7 @@ export class PluginHolder extends Disposable {
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,
@Inject(LifecycleInitializerService) protected readonly _lifecycleInitializerService: LifecycleInitializerService
@Inject(LifecycleService) protected readonly _lifecycleService: LifecycleService
) {
super();
@@ -310,8 +308,5 @@ export class PluginHolder extends Disposable {
break;
}
});
// Plugins run first, and then we should run the modules.
this._lifecycleInitializerService.initModulesOnStage(stage);
}
}
@@ -14,12 +14,10 @@
* limitations under the License.
*/
import { createIdentifier } from '../../common/di';
import { LifecycleStages, runOnLifecycle } from '../lifecycle/lifecycle';
import type { IResources } from '../resource-manager/type';
import { createIdentifier } from '../../common/di';
export const IResourceLoaderService = createIdentifier<IResourceLoaderService>('resource-loader-service');
export interface IResourceLoaderService {
saveUnit<T = object>(unitId: string): T & { resources: IResources } | null;
}
export const IResourceLoaderService = createIdentifier<IResourceLoaderService>('resource-loader-service');
runOnLifecycle(LifecycleStages.Ready, IResourceLoaderService);
@@ -15,13 +15,12 @@
*/
import { BehaviorSubject, Subject } from 'rxjs';
import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle';
import { createDefaultUser } from './const';
export interface IUser {
userID: string; name: string; avatar?: string;
};
@OnLifecycle(LifecycleStages.Starting, UserManagerService)
export class UserManagerService {
private _model = new Map<string, IUser>();
private _userChange$ = new Subject<{ type: 'add' | 'delete'; user: IUser } | { type: 'clear' }>();
+22 -15
View File
@@ -14,23 +14,33 @@
* limitations under the License.
*/
import type { Dependency } from './common/di';
import type { UnitModel, UnitType } from './common/unit';
import type { LogLevel } from './services/log/log.service';
import type { Plugin, PluginCtor } from './services/plugin/plugin';
import type { DependencyOverride } from './services/plugin/plugin-override';
import type { IStyleSheet } from './services/theme/theme.service';
import type { ILocales } from './shared';
import type { IWorkbookData } from './sheets/typedef';
import type { LocaleType } from './types/enum/locale-type';
import type { IDocumentData, ISlideData } from './types/interfaces';
import { Injector } from './common/di';
import { UniverInstanceType } from './common/unit';
import { DocumentDataModel } from './docs/data-model/document-data-model';
import { AuthzIoLocalService } from './services/authz-io/authz-io-local.service';
import { IAuthzIoService } from './services/authz-io/type';
import { CommandService, ICommandService } from './services/command/command.service';
import { ConfigService, IConfigService } from './services/config/config.service';
import { ContextService, IContextService } from './services/context/context.service';
import { ErrorService } from './services/error/error.service';
import { IUniverInstanceService, UniverInstanceService } from './services/instance/instance.service';
import { LifecycleStages } from './services/lifecycle/lifecycle';
import { LifecycleInitializerService, LifecycleService } from './services/lifecycle/lifecycle.service';
import { LifecycleService } from './services/lifecycle/lifecycle.service';
import { LocaleService } from './services/locale/locale.service';
import { DesktopLogService, ILogService } from './services/log/log.service';
import { PermissionService } from './services/permission/permission.service';
import { IPermissionService } from './services/permission/type';
import { PluginService } from './services/plugin/plugin.service';
import { mergeOverrideWithDependencies } from './services/plugin/plugin-override';
@@ -43,16 +53,6 @@ import { IUndoRedoService, LocalUndoRedoService } from './services/undoredo/undo
import { UserManagerService } from './services/user-manager/user-manager.service';
import { Workbook } from './sheets/workbook';
import { SlideDataModel } from './slides/slide-model';
import type { Dependency } from './common/di';
import type { UnitModel, UnitType } from './common/unit';
import type { LogLevel } from './services/log/log.service';
import type { Plugin, PluginCtor } from './services/plugin/plugin';
import type { DependencyOverride } from './services/plugin/plugin-override';
import type { IStyleSheet } from './services/theme/theme.service';
import type { ILocales } from './shared';
import type { IWorkbookData } from './sheets/typedef';
import type { LocaleType } from './types/enum/locale-type';
import type { IDocumentData, ISlideData } from './types/interfaces';
export interface IUniverConfig {
theme: IStyleSheet;
@@ -180,7 +180,6 @@ function createUniverInjector(parentInjector?: Injector, override?: DependencyOv
[LocaleService],
[ThemeService],
[LifecycleService],
[LifecycleInitializerService],
[PluginService],
[UserManagerService],
@@ -197,5 +196,13 @@ function createUniverInjector(parentInjector?: Injector, override?: DependencyOv
[IAuthzIoService, { useClass: AuthzIoLocalService, lazy: true }],
], override);
return parentInjector ? parentInjector.createChild(dependencies) : new Injector(dependencies);
const injector = parentInjector ? parentInjector.createChild(dependencies) : new Injector(dependencies);
inintialzeStaringModules(injector);
return injector;
}
function inintialzeStaringModules(injector: Injector): void {
injector.get(UserManagerService);
injector.get(IResourceLoaderService);
}
@@ -14,15 +14,14 @@
* limitations under the License.
*/
import { Disposable, Inject, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { ISheetDataValidationRule } from '@univerjs/core';
import { Disposable, Inject, IResourceManagerService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DataValidationModel } from '../models/data-validation-model';
type DataValidationJSON = Record<string, ISheetDataValidationRule[]>;
const DATA_VALIDATION_PLUGIN_NAME = 'SHEET_DATA_VALIDATION_PLUGIN';
@OnLifecycle(LifecycleStages.Ready, DataValidationResourceController)
export class DataValidationResourceController extends Disposable {
constructor(
@IResourceManagerService private readonly _resourceManagerService: IResourceManagerService,
+6 -2
View File
@@ -14,15 +14,15 @@
* limitations under the License.
*/
import { ICommandService, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import type { IUniverDataValidationConfig } from './controllers/config.schema';
import { ICommandService, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { AddDataValidationCommand, RemoveAllDataValidationCommand, RemoveDataValidationCommand, UpdateDataValidationOptionsCommand, UpdateDataValidationSettingCommand } from './commands/commands/data-validation.command';
import { AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation } from './commands/mutations/data-validation.mutation';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DataValidationResourceController } from './controllers/dv-resource.controller';
import { DataValidationModel } from './models/data-validation-model';
import { DataValidatorRegistryService } from './services/data-validator-registry.service';
import type { IUniverDataValidationConfig } from './controllers/config.schema';
const PLUGIN_NAME = 'UNIVER_DATA_VALIDATION_PLUGIN';
@@ -66,4 +66,8 @@ export class UniverDataValidationPlugin extends Plugin {
this._commandService.registerCommand(command);
});
}
override onReady(): void {
this._injector.get(DataValidationResourceController);
}
}
@@ -17,21 +17,19 @@
/* eslint-disable ts/no-explicit-any */
import type { ICommandInfo, JSONXActions, Nullable } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { IDocDrawing } from '@univerjs/docs-drawing';
import type { IDrawingJsonUndo1, IDrawingOrderMapParam, IDrawingSearch } from '@univerjs/drawing';
import {
Disposable,
ICommandService,
IUniverInstanceService,
JSONX,
LifecycleStages,
OnLifecycle,
RedoCommand,
UndoCommand,
} from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import { RichTextEditingMutation } from '@univerjs/docs';
import type { IDocDrawing } from '@univerjs/docs-drawing';
import { IDocDrawingService } from '@univerjs/docs-drawing';
import type { IDrawingJsonUndo1, IDrawingOrderMapParam, IDrawingSearch } from '@univerjs/drawing';
import { IDrawingManagerService } from '@univerjs/drawing';
import { IRenderManagerService } from '@univerjs/engine-render';
@@ -117,7 +115,6 @@ function getReOrderedDrawings(actions: JSONXActions): number[] {
return drawingIndexes;
}
@OnLifecycle(LifecycleStages.Ready, DocDrawingAddRemoveController)
export class DocDrawingAddRemoveController extends Disposable {
constructor(
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@@ -14,20 +14,20 @@
* limitations under the License.
*/
import type { IDocDrawingBase, IDocDrawingPosition, Nullable } from '@univerjs/core';
import type { BaseObject, Documents, IDocumentSkeletonGlyph, IDocumentSkeletonPage, Image, INodeSearch, IPoint, Viewport } from '@univerjs/engine-render';
import type { IDrawingDocTransform } from '../commands/commands/update-doc-drawing.command';
import {
BooleanNumber,
COLORS,
Disposable, ICommandService, IUniverInstanceService, LifecycleStages, ObjectRelativeFromH, ObjectRelativeFromV,
OnLifecycle, PositionedObjectLayoutType, throttle, toDisposable, Tools,
Disposable, ICommandService, IUniverInstanceService, ObjectRelativeFromH, ObjectRelativeFromV,
PositionedObjectLayoutType, throttle, toDisposable, Tools,
} from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocSelectionRenderService, getAnchorBounding, getDocObject, getOneTextSelectionRange, NodePositionConvertToCursor, TEXT_RANGE_LAYER_INDEX } from '@univerjs/docs-ui';
import { IDrawingManagerService } from '@univerjs/drawing';
import { DocumentSkeletonPageType, getColor, IRenderManagerService, Liquid, PageLayoutType, Rect, Vector2 } from '@univerjs/engine-render';
import type { IDocDrawingBase, IDocDrawingPosition, Nullable } from '@univerjs/core';
import type { BaseObject, Documents, IDocumentSkeletonGlyph, IDocumentSkeletonPage, Image, INodeSearch, IPoint, Viewport } from '@univerjs/engine-render';
import { IMoveInlineDrawingCommand, ITransformNonInlineDrawingCommand, UpdateDrawingDocTransformCommand } from '../commands/commands/update-doc-drawing.command';
import type { IDrawingDocTransform } from '../commands/commands/update-doc-drawing.command';
const INLINE_DRAWING_ANCHOR_KEY_PREFIX = '__InlineDrawingAnchor__';
@@ -55,8 +55,6 @@ function isInTableCell(nodePosition: INodeSearch) {
}
// Listen doc drawing transformer change, and update drawing data.
@OnLifecycle(LifecycleStages.Rendered, DocDrawingTransformerController)
export class DocDrawingTransformerController extends Disposable {
private _liquid = new Liquid();
private _listenerOnImageMap = new Set();
@@ -14,30 +14,29 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { ComponentManager, IMenuManagerService, IShortcutService } from '@univerjs/ui';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { AddImageSingle } from '@univerjs/icons';
import { ImageUploadIcon } from '../views/menu/image.menu';
import { COMPONENT_DOC_DRAWING_PANEL } from '../views/doc-image-panel/component-name';
import { DocDrawingPanel } from '../views/doc-image-panel/DocDrawingPanel';
import { ComponentManager, IMenuManagerService, IShortcutService } from '@univerjs/ui';
import { DeleteDocDrawingsCommand } from '../commands/commands/delete-doc-drawing.command';
import { GroupDocDrawingCommand } from '../commands/commands/group-doc-drawing.command';
import { InsertDocDrawingCommand } from '../commands/commands/insert-doc-drawing.command';
import { InsertDocImageCommand } from '../commands/commands/insert-image.command';
import { MoveDocDrawingsCommand } from '../commands/commands/move-drawings.command';
import { RemoveDocDrawingCommand } from '../commands/commands/remove-doc-drawing.command';
import { SetDocDrawingArrangeCommand } from '../commands/commands/set-drawing-arrange.command';
import { UngroupDocDrawingCommand } from '../commands/commands/ungroup-doc-drawing.command';
import { IMoveInlineDrawingCommand, ITransformNonInlineDrawingCommand, UpdateDocDrawingDistanceCommand, UpdateDocDrawingWrappingStyleCommand, UpdateDocDrawingWrapTextCommand, UpdateDrawingDocTransformCommand } from '../commands/commands/update-doc-drawing.command';
import { ClearDocDrawingTransformerOperation } from '../commands/operations/clear-drawing-transformer.operation';
import { EditDocDrawingOperation } from '../commands/operations/edit-doc-drawing.operation';
import { SidebarDocDrawingOperation } from '../commands/operations/open-drawing-panel.operation';
import { MoveDocDrawingsCommand } from '../commands/commands/move-drawings.command';
import { DeleteDocDrawingsCommand } from '../commands/commands/delete-doc-drawing.command';
import { SetDocDrawingArrangeCommand } from '../commands/commands/set-drawing-arrange.command';
import { RemoveDocDrawingCommand } from '../commands/commands/remove-doc-drawing.command';
import { UngroupDocDrawingCommand } from '../commands/commands/ungroup-doc-drawing.command';
import { GroupDocDrawingCommand } from '../commands/commands/group-doc-drawing.command';
import { InsertDocDrawingCommand } from '../commands/commands/insert-doc-drawing.command';
import { IMoveInlineDrawingCommand, ITransformNonInlineDrawingCommand, UpdateDocDrawingDistanceCommand, UpdateDocDrawingWrappingStyleCommand, UpdateDocDrawingWrapTextCommand, UpdateDrawingDocTransformCommand } from '../commands/commands/update-doc-drawing.command';
import { InsertDocImageCommand } from '../commands/commands/insert-image.command';
import { DeleteDrawingsShortcutItem, MoveDrawingDownShortcutItem, MoveDrawingLeftShortcutItem, MoveDrawingRightShortcutItem, MoveDrawingUpShortcutItem } from './shortcuts/drawing.shortcut';
import { COMPONENT_DOC_DRAWING_PANEL } from '../views/doc-image-panel/component-name';
import { DocDrawingPanel } from '../views/doc-image-panel/DocDrawingPanel';
import { ImageUploadIcon } from '../views/menu/image.menu';
import { menuSchema } from './menu.schema';
import { DeleteDrawingsShortcutItem, MoveDrawingDownShortcutItem, MoveDrawingLeftShortcutItem, MoveDrawingRightShortcutItem, MoveDrawingUpShortcutItem } from './shortcuts/drawing.shortcut';
@OnLifecycle(LifecycleStages.Ready, DocDrawingUIController)
export class DocDrawingUIController extends Disposable {
constructor(
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@@ -15,17 +15,16 @@
*/
import type { DocumentDataModel, IDisposable, Nullable } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, IContextService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';
import { takeUntil } from 'rxjs';
import { FOCUSING_COMMON_DRAWINGS, IContextService, Inject, IUniverInstanceService, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
import { IDrawingManagerService } from '@univerjs/drawing';
import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { takeUntil } from 'rxjs';
import { RemoveDocDrawingCommand } from '../commands/commands/remove-doc-drawing.command';
import { EditDocDrawingOperation } from '../commands/operations/edit-doc-drawing.operation';
@OnLifecycle(LifecycleStages.Rendered, DocDrawingPopupMenuController)
export class DocDrawingPopupMenuController extends RxDisposable {
private _initImagePopupMenu = new Set<string>();
@@ -14,6 +14,11 @@
* limitations under the License.
*/
import type { DocumentDataModel, ICommandInfo, IDocDrawingPosition, Nullable } from '@univerjs/core';
import type { IDocDrawing } from '@univerjs/docs-drawing';
import type { IImageIoServiceParam } from '@univerjs/drawing';
import type { Documents, Image, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import type { IInsertDrawingCommandParams } from '../../commands/commands/interfaces';
import { BooleanNumber, Disposable, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, Inject, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, WrapTextType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
@@ -21,18 +26,13 @@ import { IDocDrawingService } from '@univerjs/docs-drawing';
import { docDrawingPositionToTransform, DocSelectionRenderService } from '@univerjs/docs-ui';
import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, getImageSize, IDrawingManagerService, IImageIoService, ImageUploadStatusType } from '@univerjs/drawing';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
import { ILocalFileService, IMessageService } from '@univerjs/ui';
import type { DocumentDataModel, ICommandInfo, IDocDrawingPosition, Nullable } from '@univerjs/core';
import type { IDocDrawing } from '@univerjs/docs-drawing';
import type { IImageIoServiceParam } from '@univerjs/drawing';
import type { Documents, Image, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { ILocalFileService, IMessageService } from '@univerjs/ui';
import { GroupDocDrawingCommand } from '../../commands/commands/group-doc-drawing.command';
import { InsertDocDrawingCommand } from '../../commands/commands/insert-doc-drawing.command';
import { type ISetDrawingArrangeCommandParams, SetDocDrawingArrangeCommand } from '../../commands/commands/set-drawing-arrange.command';
import { UngroupDocDrawingCommand } from '../../commands/commands/ungroup-doc-drawing.command';
import { DocRefreshDrawingsService } from '../../services/doc-refresh-drawings.service';
import type { IInsertDrawingCommandParams } from '../../commands/commands/interfaces';
export class DocDrawingUpdateRenderController extends Disposable implements IRenderModule {
constructor(
+17 -9
View File
@@ -14,25 +14,26 @@
* limitations under the License.
*/
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui';
import { UniverDrawingPlugin } from '@univerjs/drawing';
import type { IUniverDocsDrawingUIConfig } from './controllers/config.schema';
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing';
import { UniverDrawingPlugin } from '@univerjs/drawing';
import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { DocDrawingPopupMenuController } from './controllers/drawing-popup-menu.controller';
import { UniverUIPlugin } from '@univerjs/ui';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DocDrawingUIController } from './controllers/doc-drawing.controller';
import { DocDrawingUpdateRenderController } from './controllers/render-controllers/doc-drawing-update.render-controller';
import { DocDrawingTransformUpdateController } from './controllers/render-controllers/doc-drawing-transform-update.controller';
import { DocDrawingAddRemoveController } from './controllers/doc-drawing-notification.controller';
import { DocDrawingTransformerController } from './controllers/doc-drawing-transformer-update.controller';
import { DocDrawingPopupMenuController } from './controllers/drawing-popup-menu.controller';
import { DocDrawingTransformUpdateController } from './controllers/render-controllers/doc-drawing-transform-update.controller';
import { DocDrawingUpdateRenderController } from './controllers/render-controllers/doc-drawing-update.render-controller';
import { DocRefreshDrawingsService } from './services/doc-refresh-drawings.service';
import type { IUniverDocsDrawingUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'DOC_DRAWING_UI_PLUGIN';
@DependentOn(UniverDrawingUIPlugin, UniverDrawingPlugin, UniverDocsDrawingPlugin)
@DependentOn(UniverDrawingUIPlugin, UniverDrawingPlugin, UniverDocsDrawingPlugin, UniverUIPlugin)
export class UniverDocsDrawingUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_DOC;
static override pluginName = PLUGIN_NAME;
@@ -67,5 +68,12 @@ export class UniverDocsDrawingUIPlugin extends Plugin {
[DocDrawingUpdateRenderController],
[DocDrawingTransformUpdateController],
] as Dependency[]).forEach((m) => this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, m));
this._injector.get(DocDrawingAddRemoveController);
this._injector.get(DocDrawingUIController);
}
override onRendered(): void {
this._injector.get(DocDrawingPopupMenuController);
}
}
@@ -14,25 +14,15 @@
* limitations under the License.
*/
import { Disposable, ICommandService, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { IDrawingManagerService } from '@univerjs/drawing';
import type { DocumentDataModel, IDocumentData } from '@univerjs/core';
import type { IDrawingMapItem, IDrawingMapItemData } from '@univerjs/drawing';
import { Disposable, IResourceManagerService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IDrawingManagerService } from '@univerjs/drawing';
import { type IDocDrawing, IDocDrawingService } from '../services/doc-drawing.service';
export const DOCS_DRAWING_PLUGIN = 'DOC_DRAWING_PLUGIN';
export interface IDocDrawingModel { drawings?: IDocumentData['drawings']; drawingsOrder?: IDocumentData['drawingsOrder'] };
@OnLifecycle(LifecycleStages.Starting, DocDrawingLoadController)
export class DocDrawingLoadController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService
) {
super();
}
}
@OnLifecycle(LifecycleStages.Starting, DocDrawingController)
export class DocDrawingController extends Disposable {
constructor(
@IDocDrawingService private readonly _docDrawingService: IDocDrawingService,
+5 -4
View File
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DocDrawingController, DocDrawingLoadController, DOCS_DRAWING_PLUGIN } from './controllers/doc-drawing.controller';
import { DocDrawingService, IDocDrawingService } from './services/doc-drawing.service';
import type { IUniverDocsDrawingConfig } from './controllers/config.schema';
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DocDrawingController, DOCS_DRAWING_PLUGIN } from './controllers/doc-drawing.controller';
import { DocDrawingService, IDocDrawingService } from './services/doc-drawing.service';
export class UniverDocsDrawingPlugin extends Plugin {
static override pluginName = DOCS_DRAWING_PLUGIN;
@@ -39,12 +39,13 @@ export class UniverDocsDrawingPlugin extends Plugin {
override onStarting(): void {
([
[DocDrawingLoadController],
[DocDrawingController],
[DocDrawingService],
[IDocDrawingService, { useClass: DocDrawingService }],
] as Dependency[
]).forEach((dependency) => this._injector.add(dependency));
this._injector.get(DocDrawingController);
}
}
@@ -15,12 +15,11 @@
*/
import type { DocumentDataModel } from '@univerjs/core';
import { Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { ISetTextSelectionsOperationParams } from '@univerjs/docs';
import { Disposable, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { SetTextSelectionsOperation } from '@univerjs/docs';
import { DocHyperLinkPopupService } from '../services/hyper-link-popup.service';
@OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController)
export class DocHyperLinkSelectionController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -14,15 +14,15 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuManagerService, IShortcutService } from '@univerjs/ui';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { LinkSingle } from '@univerjs/icons';
import { DocHyperLinkEdit } from '../views/hyper-link-edit';
import { ComponentManager, IMenuManagerService, IShortcutService } from '@univerjs/ui';
import { AddDocHyperLinkCommand } from '../commands/commands/add-link.command';
import { UpdateDocHyperLinkCommand } from '../commands/commands/update-link.command';
import { DeleteDocHyperLinkCommand } from '../commands/commands/delete-link.command';
import { UpdateDocHyperLinkCommand } from '../commands/commands/update-link.command';
import { ClickDocHyperLinkOperation, ShowDocHyperLinkEditPopupOperation, ToggleDocHyperLinkInfoPopupOperation } from '../commands/operations/popup.operation';
import { DocHyperLinkEdit } from '../views/hyper-link-edit';
import { DocLinkPopup } from '../views/hyper-link-popup';
import { addLinkShortcut, DOC_LINK_ICON } from './menu';
import { menuSchema } from './menu.schema';
@@ -31,13 +31,11 @@ export interface IDocHyperLinkUIConfig {
menu: MenuConfig;
}
@OnLifecycle(LifecycleStages.Starting, DocHyperLinkUIController)
export class DocHyperLinkUIController extends Disposable {
constructor(
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@ICommandService private readonly _commandService: ICommandService,
@IMenuManagerService private readonly _menuManagerService: IMenuManagerService,
@Inject(Injector) private readonly _injector: Injector,
@IShortcutService private readonly _shortcutService: IShortcutService
) {
super();
+8 -3
View File
@@ -14,10 +14,11 @@
* limitations under the License.
*/
import type { Dependency } from '@univerjs/core';
import type { IUniverDocsHyperLinkUIConfig } from './controllers/config.schema';
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { Dependency } from '@univerjs/core';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DocHyperLinkSelectionController } from './controllers/doc-hyper-link-selection.controller';
import { DocHyperLinkEventRenderController } from './controllers/render-controllers/hyper-link-event.render-controller';
@@ -25,7 +26,6 @@ import { DocHyperLinkRenderController } from './controllers/render-controllers/r
import { DocHyperLinkUIController } from './controllers/ui.controller';
import { DocHyperLinkPopupService } from './services/hyper-link-popup.service';
import { DOC_HYPER_LINK_UI_PLUGIN } from './types/const';
import type { IUniverDocsHyperLinkUIConfig } from './controllers/config.schema';
@DependentOn(UniverDocsHyperLinkPlugin)
export class UniverDocsHyperLinkUIPlugin extends Plugin {
@@ -54,10 +54,15 @@ export class UniverDocsHyperLinkUIPlugin extends Plugin {
[DocHyperLinkUIController],
[DocHyperLinkSelectionController],
];
deps.forEach((dep) => {
this._injector.add(dep);
});
this._injector.get(DocHyperLinkUIController);
}
override onReady(): void {
this._injector.get(DocHyperLinkSelectionController);
}
override onRendered(): void {
@@ -15,7 +15,7 @@
*/
import type { DocumentDataModel, ICustomRange } from '@univerjs/core';
import { CustomRangeType, Disposable, Inject, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { CustomRangeType, Disposable, Inject, IResourceManagerService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
export const DOC_HYPER_LINK_PLUGIN = 'DOC_HYPER_LINK_PLUGIN';
@@ -23,7 +23,6 @@ interface IDocHyperLinkJSON {
links: { id: string; payload: string }[];
}
@OnLifecycle(LifecycleStages.Starting, DocHyperLinkResourceController)
export class DocHyperLinkResourceController extends Disposable {
constructor(
@Inject(IResourceManagerService) private readonly _resourceManagerService: IResourceManagerService,
+6 -9
View File
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { ICommandService, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import type { IUniverDocsHyperLinkConfig } from './controllers/config.schema';
import { ICommandService, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { AddHyperLinkMuatation, DeleteHyperLinkMuatation, UpdateHyperLinkMuatation } from './commands/mutations/hyper-link.mutation';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DOC_HYPER_LINK_PLUGIN, DocHyperLinkResourceController } from './controllers/resource.controller';
import type { IUniverDocsHyperLinkConfig } from './controllers/config.schema';
export class UniverDocsHyperLinkPlugin extends Plugin {
static override pluginName = DOC_HYPER_LINK_PLUGIN;
@@ -39,16 +39,13 @@ export class UniverDocsHyperLinkPlugin extends Plugin {
}
override onStarting(): void {
const deps: Dependency[] = [
[DocHyperLinkResourceController],
];
deps.forEach((dep) => {
this._injector.add(dep);
});
const deps: Dependency[] = [[DocHyperLinkResourceController]];
deps.forEach((dep) => this._injector.add(dep));
[AddHyperLinkMuatation, DeleteHyperLinkMuatation, UpdateHyperLinkMuatation].forEach((mutation) => {
this.disposeWithMe(this._commandService.registerCommand(mutation));
});
this._injector.get(DocHyperLinkResourceController);
}
}
@@ -14,15 +14,14 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import { Disposable, ICommandService, Inject, Tools } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { DeleteLeftCommand, InsertCommand, MoveCursorOperation } from '@univerjs/docs-ui';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import { CloseMentionEditPopupOperation, ShowMentionEditPopupOperation } from '../commands/operations/mention-popup.operation';
import { DocMentionService } from '../services/doc-mention.service';
import { DocMentionPopupService } from '../services/doc-mention-popup.service';
@OnLifecycle(LifecycleStages.Rendered, DocMentionTriggerController)
export class DocMentionTriggerController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -14,13 +14,12 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { ComponentManager } from '@univerjs/ui';
import { AddDocMentionCommand, DeleteDocMentionCommand } from '../commands/commands/doc-mention.command';
import { CloseMentionEditPopupOperation, CloseMentionInfoPopupOperation, ShowMentionEditPopupOperation, ShowMentionInfoPopupOperation } from '../commands/operations/mention-popup.operation';
import { MentionEditPopup } from '../views/mention-edit-popup';
import { AddDocMentionCommand, DeleteDocMentionCommand } from '../commands/commands/doc-mention.command';
@OnLifecycle(LifecycleStages.Starting, DocMentionUIController)
export class DocMentionUIController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
+15 -10
View File
@@ -14,15 +14,15 @@
* limitations under the License.
*/
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DOC_MENTION_UI_PLUGIN } from './types/const/const';
import { DocMentionPopupService } from './services/doc-mention-popup.service';
import { DocMentionUIController } from './controllers/doc-mention-ui.controller';
import { DocMentionTriggerController } from './controllers/doc-mention-trigger.controller';
import { DocMentionService } from './services/doc-mention.service';
import type { IUniverDocsMentionUIConfig } from './controllers/config.schema';
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DocMentionTriggerController } from './controllers/doc-mention-trigger.controller';
import { DocMentionUIController } from './controllers/doc-mention-ui.controller';
import { DocMentionService } from './services/doc-mention.service';
import { DocMentionPopupService } from './services/doc-mention-popup.service';
import { DOC_MENTION_UI_PLUGIN } from './types/const/const';
export class UniverDocsMentionUIPlugin extends Plugin {
static override pluginName = DOC_MENTION_UI_PLUGIN;
@@ -44,15 +44,20 @@ export class UniverDocsMentionUIPlugin extends Plugin {
}
override onStarting(): void {
const deps: Dependency[] = [
([
[DocMentionService],
[DocMentionPopupService],
[DocMentionUIController],
[DocMentionTriggerController],
];
deps.forEach((dep) => {
] as Dependency[]).forEach((dep) => {
this._injector.add(dep);
});
this._injector.get(DocMentionUIController);
}
override onRendered(): void {
this._injector.get(DocMentionTriggerController);
this._injector.get(DocMentionPopupService);
}
}
@@ -15,13 +15,12 @@
*/
import type { IDisposable, Nullable } from '@univerjs/core';
import { Disposable, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, Inject } from '@univerjs/core';
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
import { BehaviorSubject } from 'rxjs';
import { MentionEditPopup } from '../views/mention-edit-popup';
import { DocMentionService } from './doc-mention.service';
@OnLifecycle(LifecycleStages.Rendered, DocMentionPopupService)
export class DocMentionPopupService extends Disposable {
private readonly _infoPopup$ = new BehaviorSubject(undefined);
readonly infoPopup$ = this._infoPopup$.asObservable();
@@ -14,20 +14,19 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { DocumentDataModel, ITextRange } from '@univerjs/core';
import type { ISetTextSelectionsOperationParams } from '@univerjs/docs';
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
import { Disposable, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { SetTextSelectionsOperation } from '@univerjs/docs';
import { DocBackScrollRenderController } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { ThreadCommentModel } from '@univerjs/thread-comment';
import { SetActiveCommentOperation, ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
import type { DocumentDataModel, ITextRange } from '@univerjs/core';
import type { ISetTextSelectionsOperationParams } from '@univerjs/docs';
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
import { ShowCommentPanelOperation } from '../commands/operations/show-comment-panel.operation';
import { DEFAULT_DOC_SUBUNIT_ID } from '../common/const';
import { DocThreadCommentService } from '../services/doc-thread-comment.service';
@OnLifecycle(LifecycleStages.Rendered, DocThreadCommentSelectionController)
export class DocThreadCommentSelectionController extends Disposable {
constructor(
@Inject(ThreadCommentPanelService) private readonly _threadCommentPanelService: ThreadCommentPanelService,
@@ -14,16 +14,15 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { CommentSingle } from '@univerjs/icons';
import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
import { AddDocCommentComment } from '../commands/commands/add-doc-comment.command';
import { DocThreadCommentPanel } from '../views/doc-thread-comment-panel';
import { ShowCommentPanelOperation, StartAddCommentOperation, ToggleCommentPanelOperation } from '../commands/operations/show-comment-panel.operation';
import { DeleteDocCommentComment } from '../commands/commands/delete-doc-comment.command';
import { ShowCommentPanelOperation, StartAddCommentOperation, ToggleCommentPanelOperation } from '../commands/operations/show-comment-panel.operation';
import { DocThreadCommentPanel } from '../views/doc-thread-comment-panel';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Rendered, DocThreadCommentUIController)
export class DocThreadCommentUIController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -15,15 +15,14 @@
*/
import type { DocumentDataModel } from '@univerjs/core';
import { Disposable, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { Disposable, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DOC_INTERCEPTOR_POINT, DocInterceptorService } from '@univerjs/docs';
import { DocRenderController } from '@univerjs/docs-ui';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { ThreadCommentModel } from '@univerjs/thread-comment';
import { ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
import { DEFAULT_DOC_SUBUNIT_ID } from '../../common/const';
@OnLifecycle(LifecycleStages.Starting, DocThreadCommentRenderController)
export class DocThreadCommentRenderController extends Disposable implements IRenderModule {
constructor(
private readonly _context: IRenderContext<DocumentDataModel>,
+11 -9
View File
@@ -14,17 +14,17 @@
* limitations under the License.
*/
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { PLUGIN_NAME } from './common/const';
import { DocThreadCommentUIController } from './controllers/doc-thread-comment-ui.controller';
import { DocThreadCommentService } from './services/doc-thread-comment.service';
import { DocThreadCommentSelectionController } from './controllers/doc-thread-comment-selection.controller';
import { DocThreadCommentRenderController } from './controllers/render-controllers/render.controller';
import type { IUniverDocsThreadCommentUIConfig } from './controllers/config.schema';
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
import { PLUGIN_NAME } from './common/const';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DocThreadCommentSelectionController } from './controllers/doc-thread-comment-selection.controller';
import { DocThreadCommentUIController } from './controllers/doc-thread-comment-ui.controller';
import { DocThreadCommentRenderController } from './controllers/render-controllers/render.controller';
import { DocThreadCommentService } from './services/doc-thread-comment.service';
@DependentOn(UniverThreadCommentUIPlugin)
export class UniverDocsThreadCommentUIPlugin extends Plugin {
@@ -51,7 +51,6 @@ export class UniverDocsThreadCommentUIPlugin extends Plugin {
([
[DocThreadCommentUIController],
[DocThreadCommentSelectionController],
[DocThreadCommentService],
] as Dependency[]).forEach((dep) => {
this._injector.add(dep);
@@ -60,6 +59,9 @@ export class UniverDocsThreadCommentUIPlugin extends Plugin {
override onRendered(): void {
this._initRenderModule();
this._injector.get(DocThreadCommentSelectionController);
this._injector.get(DocThreadCommentUIController);
}
private _initRenderModule() {
@@ -16,6 +16,8 @@
/* eslint-disable ts/no-explicit-any */
import type { Ctor, Dependency, DependencyIdentifier, DocumentDataModel, IDocumentData, Nullable } from '@univerjs/core';
import type { DocumentSkeleton, IRender, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import {
BooleanNumber,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
@@ -31,11 +33,9 @@ import {
UniverInstanceType,
} from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService } from '@univerjs/docs';
import { DocumentViewModel, IRenderManagerService } from '@univerjs/engine-render';
import { BehaviorSubject, takeUntil } from 'rxjs';
import type { Ctor, Dependency, DependencyIdentifier, DocumentDataModel, IDocumentData, Nullable } from '@univerjs/core';
import type { DocumentSkeleton, IRender, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { DocIMEInputManagerService } from '../../../services/doc-ime-input-manager.service';
import { DocStateChangeManagerService } from '../../../services/doc-state-change-manager.service';
import { DocSelectionRenderService } from '../../../services/selection/doc-selection-render.service';
@@ -124,6 +124,10 @@ export function createCommandTestBed(docData?: IDocumentData, dependencies?: Dep
dependencies?.forEach((d) => injector.add(d));
}
override onReady(): void {
this._injector.get(DocStateChangeManagerService);
}
}
univer.registerPlugin(TestPlugin);
@@ -14,11 +14,10 @@
* limitations under the License.
*/
import type { DocumentDataModel, ICommand, Injector, IStyleBase, Univer } from '@univerjs/core';
import { BooleanNumber, ICommandService, IUniverInstanceService, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService, RichTextEditingMutation, SetTextSelectionsOperation } from '@univerjs/docs';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import type { DocumentDataModel, ICommand, Injector, IStyleBase, Univer } from '@univerjs/core';
import {
SetInlineFormatBoldCommand,
SetInlineFormatCommand,
@@ -14,17 +14,16 @@
* limitations under the License.
*/
import { Disposable, Inject, LifecycleStages, OnLifecycle, QuickListTypeMap } from '@univerjs/core';
import type { Nullable } from 'vitest';
import type { ITabCommandParams } from '../commands/commands/auto-format.command';
import { Disposable, Inject, QuickListTypeMap } from '@univerjs/core';
import { AfterSpaceCommand, EnterCommand, TabCommand } from '../commands/commands/auto-format.command';
import { BreakLineCommand } from '../commands/commands/break-line.command';
import { ChangeListNestingLevelCommand, ChangeListNestingLevelType, ListOperationCommand, QuickListCommand } from '../commands/commands/list.command';
import { DocTableTabCommand } from '../commands/commands/table/doc-table-tab.command';
import { DocAutoFormatService } from '../services/doc-auto-format.service';
import { isInSameTableCell } from '../services/selection/convert-rect-range';
import type { ITabCommandParams } from '../commands/commands/auto-format.command';
@OnLifecycle(LifecycleStages.Rendered, DocAutoFormatController)
export class DocAutoFormatController extends Disposable {
constructor(
@Inject(DocAutoFormatService) private readonly _docAutoFormatService: DocAutoFormatService
@@ -14,19 +14,6 @@
* limitations under the License.
*/
import {
DataStreamTreeTokenType,
Direction,
Disposable,
ICommandService,
Inject,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
RANGE_DIRECTION,
} from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentSkeletonPageType, IRenderManagerService } from '@univerjs/engine-render';
import type { ICommandInfo, Nullable } from '@univerjs/core';
import type {
DocumentSkeleton,
@@ -38,16 +25,26 @@ import type {
INodePosition,
INodeSearch,
} from '@univerjs/engine-render';
import type { Subscription } from 'rxjs';
import type { IMoveCursorOperationParams } from '../commands/operations/doc-cursor.operation';
import {
DataStreamTreeTokenType,
Direction,
Disposable,
ICommandService,
Inject,
IUniverInstanceService,
RANGE_DIRECTION,
} from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentSkeletonPageType, IRenderManagerService } from '@univerjs/engine-render';
import { getDocObject } from '../basics/component-tools';
import { findAboveCell, findBellowCell, findLineBeforeAndAfterTable, findTableAfterLine, findTableBeforeLine, firstLineInCell, firstLineInTable, lastLineInCell, lastLineInTable } from '../basics/table';
import { MoveCursorOperation, MoveSelectionOperation } from '../commands/operations/doc-cursor.operation';
import { NodePositionConvertToCursor } from '../services/selection/convert-text-range';
import { DocBackScrollRenderController } from './render-controllers/back-scroll.render-controller';
import type { IMoveCursorOperationParams } from '../commands/operations/doc-cursor.operation';
@OnLifecycle(LifecycleStages.Rendered, DocMoveCursorController)
export class DocMoveCursorController extends Disposable {
private _onInputSubscription: Nullable<Subscription>;
@@ -14,13 +14,12 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { ComponentManager, ISidebarService } from '@univerjs/ui';
import { ParagraphSettingIndex } from '../views/paragraph-setting/index';
const paragraphSettingIndexKey = 'doc_ui_paragraph-setting-panel';
@OnLifecycle(LifecycleStages.Rendered, DocParagraphSettingController)
export class DocParagraphSettingController extends Disposable {
private _id: 'DocParagraphSetting';
@@ -14,14 +14,12 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { ComponentManager } from '@univerjs/ui';
import { DocCreateTableOperation } from '../commands/operations/doc-create-table.operation';
import { COMPONENT_DOC_CREATE_TABLE_CONFIRM } from '../views/table/create/component-name';
import { DocCreateTableConfirm } from '../views/table/create/TableCreate';
import { DocCreateTableOperation } from '../commands/operations/doc-create-table.operation';
@OnLifecycle(LifecycleStages.Rendered, DocTableController)
export class DocTableController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import type { IUniverDocsUIConfig } from './config.schema';
import {
connectInjector,
Disposable,
@@ -22,12 +23,10 @@ import {
Inject,
Injector,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
UniverInstanceType,
} from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import { TodoList } from '@univerjs/icons';
import { BuiltInUIPart, ComponentManager, ILayoutService, IMenuManagerService, IShortcutService, IUIPartsService } from '@univerjs/ui';
import { CoreHeaderFooterCommand, OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
@@ -60,10 +59,7 @@ import {
import { DocFooter } from '../views/doc-footer';
import { PLUGIN_CONFIG_KEY } from './config.schema';
import { menuSchema } from './menu.schema';
import type { IUniverDocsUIConfig } from './config.schema';
// FIXME: LifecycleStages.Rendered must be used, otherwise the menu cannot be added to the DOM, but the sheet ui plug-in can be added in LifecycleStages.Ready
@OnLifecycle(LifecycleStages.Rendered, DocUIController)
export class DocUIController extends Disposable {
constructor(
@Inject(Injector) protected readonly _injector: Injector,
+16 -9
View File
@@ -115,6 +115,7 @@ export class UniverDocsUIPlugin extends Plugin {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
this._initDependencies(_injector);
this._initializeShortcut();
this._initCommand();
@@ -123,11 +124,23 @@ export class UniverDocsUIPlugin extends Plugin {
override onReady(): void {
this._initRenderBasics();
this._markDocAsFocused();
this._injector.get(DocStateChangeManagerService);
this._injector.get(DocsRenderService);
}
override onRendered(): void {
this._initUI();
this._initRenderModules();
this._injector.get(DocAutoFormatController);
this._injector.get(DocMoveCursorController);
this._injector.get(DocParagraphSettingController);
this._injector.get(DocTableController);
// FIXME: LifecycleStages.Rendered must be used, otherwise the menu cannot be added to the DOM, but the sheet ui
// plugin can be added in LifecycleStages.Ready
this._injector.get(DocUIController);
}
private _initCommand() {
@@ -220,18 +233,15 @@ export class UniverDocsUIPlugin extends Plugin {
}
private _initDependencies(injector: Injector) {
const dependencies: Dependency[] = [
const dependencies = mergeOverrideWithDependencies([
[DocClipboardController],
[DocEditorBridgeController],
// Controller
[DocUIController],
[DocAutoFormatController],
[DocTableController],
[DocMoveCursorController],
[AppUIController],
[DocParagraphSettingController],
// Services
[IEditorService, { useClass: EditorService }],
[IRangeSelectorService, { useClass: RangeSelectorService }],
[IDocClipboardService, { useClass: DocClipboardService }],
@@ -239,11 +249,8 @@ export class UniverDocsUIPlugin extends Plugin {
[DocsRenderService],
[DocStateChangeManagerService],
[DocAutoFormatService],
];
const dependency = mergeOverrideWithDependencies(dependencies, this._config.override);
dependency.forEach((d) => injector.add(d));
], this._config.override);
dependencies.forEach((d) => injector.add(d));
}
private _markDocAsFocused() {
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { ICommandService, Inject, IUndoRedoService, IUniverInstanceService, JSONX, LifecycleStages, OnLifecycle, RedoCommandId, RxDisposable, UndoCommandId } from '@univerjs/core';
import type { JSONXActions, Nullable } from '@univerjs/core';
import { ICommandService, Inject, IUndoRedoService, IUniverInstanceService, JSONX, RedoCommandId, RxDisposable, UndoCommandId } from '@univerjs/core';
import { DocStateEmitService, type IDocStateChangeParams, type IRichTextEditingMutationParams } from '@univerjs/docs';
import { IRenderManagerService } from '@univerjs/engine-render';
import { BehaviorSubject, takeUntil } from 'rxjs';
import type { JSONXActions, Nullable } from '@univerjs/core';
import { DocIMEInputManagerService } from './doc-ime-input-manager.service';
type ChangeStateCacheType = 'history' | 'collaboration';
@@ -28,7 +28,6 @@ const DEBOUNCE_DELAY = 300;
// This class sends out state-changing events, what is the state, the data model,
// and the cursor & selection, and this class mainly serves the History(undo/redo) module and
// the collaboration module.
@OnLifecycle(LifecycleStages.Ready, DocStateChangeManagerService)
export class DocStateChangeManagerService extends RxDisposable {
private readonly _docStateChange$ = new BehaviorSubject<Nullable<IDocStateChangeParams>>(null);
readonly docStateChange$ = this._docStateChange$.asObservable();
@@ -14,12 +14,11 @@
* limitations under the License.
*/
import { IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, UniverInstanceType } from '@univerjs/core';
import type { DocumentDataModel } from '@univerjs/core';
import { IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { takeUntil } from 'rxjs';
import type { DocumentDataModel } from '@univerjs/core';
@OnLifecycle(LifecycleStages.Ready, DocsRenderService)
export class DocsRenderService extends RxDisposable {
constructor(
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@@ -14,14 +14,13 @@
* limitations under the License.
*/
import { BuildTextUtils, Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { DocumentDataModel } from '@univerjs/core';
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
import type { ISetTextSelectionsOperationParams } from '../commands/operations/text-selection.operation';
import { BuildTextUtils, Disposable, ICommandService, Inject, IUniverInstanceService } from '@univerjs/core';
import { SetTextSelectionsOperation } from '../commands/operations/text-selection.operation';
import { DocSelectionManagerService } from '../services/doc-selection-manager.service';
import type { ISetTextSelectionsOperationParams } from '../commands/operations/text-selection.operation';
@OnLifecycle(LifecycleStages.Ready, DocCustomRangeController)
export class DocCustomRangeController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
+11 -9
View File
@@ -14,6 +14,8 @@
* limitations under the License.
*/
import type { Dependency, ICommand } from '@univerjs/core';
import type { IUniverDocsConfig } from './controllers/config.schema';
import {
ICommandService,
IConfigService,
@@ -21,7 +23,6 @@ import {
Injector,
Plugin,
} from '@univerjs/core';
import type { Dependency, ICommand } from '@univerjs/core';
import { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
import { DocsRenameMutation } from './commands/mutations/docs-rename.mutation';
import { SetTextSelectionsOperation } from './commands/operations/text-selection.operation';
@@ -29,7 +30,6 @@ import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.sch
import { DocCustomRangeController } from './controllers/custom-range.controller';
import { DocSelectionManagerService } from './services/doc-selection-manager.service';
import { DocStateEmitService } from './services/doc-state-emit.service';
import type { IUniverDocsConfig } from './controllers/config.schema';
const PLUGIN_NAME = 'DOCS_PLUGIN';
@@ -47,9 +47,10 @@ export class UniverDocsPlugin extends Plugin {
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
this._initializeDependencies(_injector);
override onStarting(): void {
this._initializeDependencies();
this._initializeCommands();
}
@@ -65,16 +66,17 @@ export class UniverDocsPlugin extends Plugin {
});
}
private _initializeDependencies(docInjector: Injector) {
private _initializeDependencies() {
(
[
// services
[DocSelectionManagerService],
[DocStateEmitService],
// controllers
[DocCustomRangeController],
] as Dependency[]
).forEach((d) => docInjector.add(d));
).forEach((d) => this._injector.add(d));
}
override onReady(): void {
this._injector.get(DocCustomRangeController);
}
}
@@ -15,12 +15,11 @@
*/
import type { DocumentDataModel, ICustomDecorationForInterceptor, ICustomRangeForInterceptor, IInterceptor, Nullable } from '@univerjs/core';
import { composeInterceptors, Disposable, DisposableCollection, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, Inject, LifecycleStages, OnLifecycle, remove, toDisposable } from '@univerjs/core';
import type { DocumentViewModel, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { composeInterceptors, Disposable, DisposableCollection, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, Inject, remove, toDisposable } from '@univerjs/core';
import { DocSkeletonManagerService } from '../doc-skeleton-manager.service';
import { DOC_INTERCEPTOR_POINT } from './interceptor-const';
@OnLifecycle(LifecycleStages.Starting, DocInterceptorService)
export class DocInterceptorService extends Disposable implements IRenderModule {
private _interceptorsByName: Map<string, Array<IInterceptor<unknown, unknown>>> = new Map();
@@ -14,17 +14,16 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { ComponentManager } from '@univerjs/ui';
import { SetDrawingAlignOperation } from '../commands/operations/drawing-align.operation';
import { AutoImageCropOperation, CloseImageCropOperation, OpenImageCropOperation } from '../commands/operations/image-crop.operation';
import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';
import { COMPONENT_IMAGE_POPUP_MENU } from '../views/image-popup-menu/component-name';
import { ImagePopupMenu } from '../views/image-popup-menu/ImagePopupMenu';
import { AutoImageCropOperation, CloseImageCropOperation, OpenImageCropOperation } from '../commands/operations/image-crop.operation';
import { ImageViewer } from '../views/image-viewer/ImageViewer';
import { COMPONENT_IMAGE_VIEWER } from '../views/image-viewer/component-name';
import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';
import { SetDrawingAlignOperation } from '../commands/operations/drawing-align.operation';
import { ImageViewer } from '../views/image-viewer/ImageViewer';
@OnLifecycle(LifecycleStages.Rendered, DrawingUIController)
export class DrawingUIController extends Disposable {
constructor(
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@@ -18,20 +18,18 @@ import type {
ICommandInfo,
Nullable,
} from '@univerjs/core';
import type { DrawingTypeEnum, IDrawingGroupUpdateParam, IDrawingOrderMapParam, IDrawingParam, IDrawingSearch, ITransformState } from '@univerjs/drawing';
import type { BaseObject, Image, IShapeProps, Scene, Shape } from '@univerjs/engine-render';
import type { ISetDrawingAlignOperationParams } from '../commands/operations/drawing-align.operation';
import {
checkIfMove,
Disposable,
ICommandService,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
toDisposable,
} from '@univerjs/core';
import type { BaseObject, Image, IShapeProps, Scene, Shape } from '@univerjs/engine-render';
import { DRAWING_OBJECT_LAYER_INDEX, Group, IRenderManagerService, RENDER_CLASS_TYPE } from '@univerjs/engine-render';
import type { DrawingTypeEnum, IDrawingGroupUpdateParam, IDrawingOrderMapParam, IDrawingParam, IDrawingSearch, ITransformState } from '@univerjs/drawing';
import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import type { ISetDrawingAlignOperationParams } from '../commands/operations/drawing-align.operation';
import { DRAWING_OBJECT_LAYER_INDEX, Group, IRenderManagerService, RENDER_CLASS_TYPE } from '@univerjs/engine-render';
import { AlignType, SetDrawingAlignOperation } from '../commands/operations/drawing-align.operation';
import { CloseImageCropOperation } from '../commands/operations/image-crop.operation';
import { getUpdateParams } from '../utils/get-update-params';
@@ -45,7 +43,6 @@ interface IDrawingTransformCache {
transform: ITransformState;
}
@OnLifecycle(LifecycleStages.Rendered, DrawingUpdateController)
export class DrawingUpdateController extends Disposable {
constructor(
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@@ -15,19 +15,18 @@
*/
import type { ICommandInfo, ISrcRect, Nullable, Workbook } from '@univerjs/core';
import { checkIfMove, Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import type { IDrawingSearch, IImageData, ITransformState } from '@univerjs/drawing';
import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import type { IOpenImageCropOperationBySrcRectParams } from '../commands/operations/image-crop.operation';
import { checkIfMove, Disposable, ICommandService, Inject, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import { CURSOR_TYPE, degToRad, Image, IRenderManagerService, precisionTo, Vector2 } from '@univerjs/engine-render';
import { IMessageService } from '@univerjs/ui';
import { filter, switchMap } from 'rxjs';
import type { IOpenImageCropOperationBySrcRectParams } from '../commands/operations/image-crop.operation';
import { AutoImageCropOperation, CloseImageCropOperation, CropType, OpenImageCropOperation } from '../commands/operations/image-crop.operation';
import { ImageCropperObject } from '../views/crop/image-cropper-object';
@OnLifecycle(LifecycleStages.Rendered, ImageCropperController)
export class ImageCropperController extends Disposable {
private _sceneListenerOnImageMap: WeakSet<Scene> = new WeakSet();
@@ -15,28 +15,25 @@
*/
import type { ICommandInfo, Nullable } from '@univerjs/core';
import type { IDrawingSearch, IImageData } from '@univerjs/drawing';
import type { Image, Scene } from '@univerjs/engine-render';
import {
Disposable,
ICommandService,
Inject,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
toDisposable,
} from '@univerjs/core';
import type { Image, Scene } from '@univerjs/engine-render';
import { CURSOR_TYPE, IRenderManagerService } from '@univerjs/engine-render';
import type { IDrawingSearch, IImageData } from '@univerjs/drawing';
import { DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, IImageIoService } from '@univerjs/drawing';
import { CURSOR_TYPE, IRenderManagerService } from '@univerjs/engine-render';
import { IDialogService } from '@univerjs/ui';
import { COMPONENT_IMAGE_VIEWER } from '../views/image-viewer/component-name';
import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';
import { DrawingRenderService } from '../services/drawing-render.service';
import { COMPONENT_IMAGE_VIEWER } from '../views/image-viewer/component-name';
import { getCurrentUnitInfo } from './utils';
const IMAGE_VIEWER_DROPDOWN_PADDING = 50;
@OnLifecycle(LifecycleStages.Rendered, ImageUpdateController)
export class ImageUpdateController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
+11 -7
View File
@@ -14,15 +14,15 @@
* limitations under the License.
*/
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DrawingUpdateController } from './controllers/drawing-update.controller';
import type { IUniverDrawingUIConfig } from './controllers/config.schema';
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DrawingUIController } from './controllers/drawing-ui.controller';
import { DrawingUpdateController } from './controllers/drawing-update.controller';
import { ImageCropperController } from './controllers/image-cropper.controller';
import { ImageUpdateController } from './controllers/image-update.controller';
import { DrawingRenderService } from './services/drawing-render.service';
import type { IUniverDrawingUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'UNIVER_DRAWING_UI_PLUGIN';
@@ -48,12 +48,16 @@ export class UniverDrawingUIPlugin extends Plugin {
this._initDependencies();
}
override onRendered(): void {
this._injector.get(DrawingUIController);
this._injector.get(DrawingUpdateController);
this._injector.get(ImageCropperController);
this._injector.get(ImageUpdateController);
}
private _initDependencies(): void {
const dependencies: Dependency[] = [
// services
[DrawingRenderService],
// controllers
[DrawingUpdateController],
[DrawingUIController],
[ImageCropperController],
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { type Observable, Subject } from 'rxjs';
import type { Nullable } from '@univerjs/core';
import { sortRules, sortRulesByDesc } from '@univerjs/core';
import type { JSONOp, JSONOpList } from 'ot-json1';
import * as json1 from 'ot-json1';
import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItemData, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingParam, IDrawingSearch, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService } from './drawing-manager.service';
import { sortRules, sortRulesByDesc } from '@univerjs/core';
import * as json1 from 'ot-json1';
import { type Observable, Subject } from 'rxjs';
export interface IDrawingJsonUndo1 {
undo: JSONOp;
@@ -137,7 +137,7 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawing
}
getDrawingDataForUnit(unitId: string) {
return this.drawingManagerData[unitId];
return this.drawingManagerData[unitId] || {};
}
removeDrawingDataForUnit(unitId: string) {
@@ -21,7 +21,7 @@ import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/s
import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import type { IAllRuntimeData } from '../services/runtime.service';
import { Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { convertRuntimeToUnitData } from '../basics/runtime';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import {
@@ -35,12 +35,10 @@ import { FormulaDataModel } from '../models/formula-data.model';
import { CalculateFormulaService } from '../services/calculate-formula.service';
import { FormulaExecutedStateType } from '../services/runtime.service';
@OnLifecycle(LifecycleStages.Ready, CalculateController)
export class CalculateController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@Inject(CalculateFormulaService) private readonly _calculateFormulaService: CalculateFormulaService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel
) {
super();
@@ -57,7 +55,7 @@ export class CalculateController extends Disposable {
private _commandExecutedListener() {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo, options) => {
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (command.id === SetFormulaCalculationStopMutation.id) {
this._calculateFormulaService.stopFormulaExecution();
} else if (command.id === SetFormulaDataMutation.id) {
@@ -14,11 +14,13 @@
* limitations under the License.
*/
import { Disposable, ICommandService, IConfigService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { IFunctionNames } from '../basics/function';
import type { BaseFunction } from '../functions/base-function';
import type { IUniverEngineFormulaConfig } from './config.schema';
import { Disposable, ICommandService, IConfigService } from '@univerjs/core';
import { type Ctor, Optional } from '@univerjs/core';
import { DataSyncPrimaryController } from '@univerjs/rpc';
import type { IFunctionNames } from '../basics/function';
import { RegisterFunctionMutation } from '../commands/mutations/register-function.mutation';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '../commands/mutations/set-defined-name.mutation';
@@ -40,7 +42,6 @@ import {
SetSuperTableOptionMutation,
} from '../commands/mutations/set-super-table.mutation';
import { functionArray } from '../functions/array/function-map';
import type { BaseFunction } from '../functions/base-function';
import { functionCompatibility } from '../functions/compatibility/function-map';
import { functionCube } from '../functions/cube/function-map';
import { functionDatabase } from '../functions/database/function-map';
@@ -57,10 +58,8 @@ import { functionText } from '../functions/text/function-map';
import { functionUniver } from '../functions/univer/function-map';
import { functionWeb } from '../functions/web/function-map';
import { IFunctionService } from '../services/function.service';
import type { IUniverEngineFormulaConfig } from './config.schema';
import { PLUGIN_CONFIG_KEY } from './config.schema';
@OnLifecycle(LifecycleStages.Ready, FormulaController)
export class FormulaController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -15,16 +15,15 @@
*/
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type {
ISetDefinedNameMutationParam,
ISetDefinedNameMutationSearchParam,
} from '../commands/mutations/set-defined-name.mutation';
import { Disposable, ICommandService } from '@univerjs/core';
import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '../commands/mutations/set-defined-name.mutation';
import { IDefinedNamesService } from '../services/defined-names.service';
@OnLifecycle(LifecycleStages.Ready, SetDefinedNameController)
export class SetDefinedNameController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -14,9 +14,14 @@
* limitations under the License.
*/
import { Disposable, ICommandService, LifecycleStages, ObjectMatrix, OnLifecycle } from '@univerjs/core';
import type { ICommandInfo } from '@univerjs/core';
import type {
IRemoveFeatureCalculationMutationParam,
ISetFeatureCalculationMutation } from '../commands/mutations/set-feature-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation';
import { Disposable, ICommandService, ObjectMatrix } from '@univerjs/core';
import {
RemoveFeatureCalculationMutation,
SetFeatureCalculationMutation,
@@ -25,13 +30,7 @@ import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.m
import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation';
import { IDependencyManagerService } from '../services/dependency-manager.service';
import { IFeatureCalculationManagerService } from '../services/feature-calculation-manager.service';
import type {
IRemoveFeatureCalculationMutationParam,
ISetFeatureCalculationMutation } from '../commands/mutations/set-feature-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation';
@OnLifecycle(LifecycleStages.Ready, SetDependencyController)
export class SetDependencyController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -15,18 +15,17 @@
*/
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type {
IRemoveFeatureCalculationMutationParam,
ISetFeatureCalculationMutation } from '../commands/mutations/set-feature-calculation.mutation';
ISetFeatureCalculationMutation,
} from '../commands/mutations/set-feature-calculation.mutation';
import { Disposable, ICommandService } from '@univerjs/core';
import {
RemoveFeatureCalculationMutation,
SetFeatureCalculationMutation,
} from '../commands/mutations/set-feature-calculation.mutation';
import { IFeatureCalculationManagerService } from '../services/feature-calculation-manager.service';
@OnLifecycle(LifecycleStages.Ready, SetFeatureCalculationController)
export class SetFeatureCalculationController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -15,16 +15,15 @@
*/
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation';
import { Disposable, ICommandService } from '@univerjs/core';
import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation';
import { IDependencyManagerService } from '../services/dependency-manager.service';
import {
IOtherFormulaManagerService,
} from '../services/other-formula-manager.service';
import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation';
import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation';
import { IDependencyManagerService } from '../services/dependency-manager.service';
@OnLifecycle(LifecycleStages.Ready, SetOtherFormulaController)
export class SetOtherFormulaController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -15,18 +15,17 @@
*/
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { ISuperTableOptionParam } from '../services/super-table.service';
import { Disposable, ICommandService } from '@univerjs/core';
import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '../commands/mutations/set-defined-name.mutation';
import {
type ISetSuperTableMutationParam,
type ISetSuperTableMutationSearchParam,
SetSuperTableOptionMutation,
} from '../commands/mutations/set-super-table.mutation';
import type { ISuperTableOptionParam } from '../services/super-table.service';
import { ISuperTableService } from '../services/super-table.service';
@OnLifecycle(LifecycleStages.Ready, SetSuperTableController)
export class SetSuperTableController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@@ -15,33 +15,32 @@
*/
import type { IRange, Nullable } from '@univerjs/core';
import { Disposable, Inject, LifecycleStages, ObjectMatrix, OnLifecycle } from '@univerjs/core';
import { FormulaAstLRU } from '../../basics/cache-lru';
import type { IDirtyUnitSheetNameMap, IFeatureDirtyRangeType, IFormulaData, IOtherFormulaData, IUnitData } from '../../basics/common';
import type { ErrorType } from '../../basics/error-type';
import { ERROR_TYPE_SET } from '../../basics/error-type';
import { prefixToken, suffixToken } from '../../basics/token';
import type { IFormulaDirtyData } from '../../services/current-data.service';
import { IFormulaCurrentConfigService } from '../../services/current-data.service';
import type { IFeatureCalculationManagerParam } from '../../services/feature-calculation-manager.service';
import { IFeatureCalculationManagerService } from '../../services/feature-calculation-manager.service';
import { IOtherFormulaManagerService } from '../../services/other-formula-manager.service';
import type { IAllRuntimeData } from '../../services/runtime.service';
import { IFormulaRuntimeService } from '../../services/runtime.service';
import { Lexer } from '../analysis/lexer';
import type { LexerNode } from '../analysis/lexer-node';
import { AstTreeBuilder } from '../analysis/parser';
import type { AstRootNode, FunctionNode, PrefixNode, SuffixNode } from '../ast-node';
import type { BaseAstNode } from '../ast-node/base-ast-node';
import type { BaseReferenceObject } from '../reference-object/base-reference-object';
import type { PreCalculateNodeType } from '../utils/node-type';
import type { IUnitRangeWithToken } from './dependency-tree';
import { Disposable, Inject, ObjectMatrix } from '@univerjs/core';
import { FormulaAstLRU } from '../../basics/cache-lru';
import { ERROR_TYPE_SET } from '../../basics/error-type';
import { prefixToken, suffixToken } from '../../basics/token';
import { IFormulaCurrentConfigService } from '../../services/current-data.service';
import { IDependencyManagerService } from '../../services/dependency-manager.service';
import { IFeatureCalculationManagerService } from '../../services/feature-calculation-manager.service';
import { IOtherFormulaManagerService } from '../../services/other-formula-manager.service';
import { IFormulaRuntimeService } from '../../services/runtime.service';
import { Lexer } from '../analysis/lexer';
import { AstTreeBuilder } from '../analysis/parser';
import { ErrorNode } from '../ast-node/base-ast-node';
import { NodeType } from '../ast-node/node-type';
import { Interpreter } from '../interpreter/interpreter';
import type { BaseReferenceObject } from '../reference-object/base-reference-object';
import type { PreCalculateNodeType } from '../utils/node-type';
import { serializeRangeToRefString } from '../utils/reference';
import { IDependencyManagerService } from '../../services/dependency-manager.service';
import type { IUnitRangeWithToken } from './dependency-tree';
import { FormulaDependencyTree, FormulaDependencyTreeCache } from './dependency-tree';
const FORMULA_CACHE_LRU_COUNT = 100000;
@@ -52,7 +51,6 @@ interface IFeatureFormulaParam {
featureId: string;
}
@OnLifecycle(LifecycleStages.Rendered, FormulaDependencyGenerator)
export class FormulaDependencyGenerator extends Disposable {
private _updateRangeFlattenCache = new Map<string, Map<string, IRange[]>>();
+26 -7
View File
@@ -14,12 +14,14 @@
* limitations under the License.
*/
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import type { IUniverEngineFormulaConfig } from './controller/config.schema';
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import { CalculateController } from './controller/calculate.controller';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controller/config.schema';
import { FormulaController } from './controller/formula.controller';
import { SetDefinedNameController } from './controller/set-defined-name.controller';
import { SetDependencyController } from './controller/set-dependency.controller';
import { SetFeatureCalculationController } from './controller/set-feature-calculation.controller';
import { SetOtherFormulaController } from './controller/set-other-formula.controller';
import { SetSuperTableController } from './controller/set-super-table.controller';
@@ -39,9 +41,11 @@ import { ValueNodeFactory } from './engine/ast-node/value-node';
import { FormulaDependencyGenerator } from './engine/dependency/formula-dependency';
import { Interpreter } from './engine/interpreter/interpreter';
import { FormulaDataModel } from './models/formula-data.model';
import { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service';
import { CalculateFormulaService } from './services/calculate-formula.service';
import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from './services/current-data.service';
import { DefinedNamesService, IDefinedNamesService } from './services/defined-names.service';
import { DependencyManagerService, IDependencyManagerService } from './services/dependency-manager.service';
import {
FeatureCalculationManagerService,
IFeatureCalculationManagerService,
@@ -50,11 +54,6 @@ import { FunctionService, IFunctionService } from './services/function.service';
import { IOtherFormulaManagerService, OtherFormulaManagerService } from './services/other-formula-manager.service';
import { FormulaRuntimeService, IFormulaRuntimeService } from './services/runtime.service';
import { ISuperTableService, SuperTableService } from './services/super-table.service';
import { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service';
import { DependencyManagerService, IDependencyManagerService } from './services/dependency-manager.service';
import { SetDependencyController } from './controller/set-dependency.controller';
import type { IUniverEngineFormulaConfig } from './controller/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controller/config.schema';
const PLUGIN_NAME = 'UNIVER_ENGINE_FORMULA_PLUGIN';
@@ -77,6 +76,26 @@ export class UniverFormulaEnginePlugin extends Plugin {
this._initialize();
}
override onReady(): void {
this._injector.get(FormulaController);
this._injector.get(SetDefinedNameController);
this._injector.get(SetSuperTableController);
if (!this._config?.notExecuteFormula) {
this._injector.get(SetOtherFormulaController);
this._injector.get(SetFeatureCalculationController);
this._injector.get(SetDependencyController);
this._injector.get(CalculateController);
}
}
override onRendered(): void {
if (!this._config?.notExecuteFormula) {
this._injector.get(CalculateFormulaService);
this._injector.get(FormulaDependencyGenerator);
}
}
private _initialize() {
// worker and main thread
const dependencies: Dependency[] = [
@@ -15,17 +15,6 @@
*/
import type { IUnitRange } from '@univerjs/core';
import {
Disposable,
IConfigService,
Inject,
LifecycleStages,
ObjectMatrix,
OnLifecycle,
requestImmediateMacroTask,
} from '@univerjs/core';
import { Subject } from 'rxjs';
import type {
IArrayFormulaRangeType,
IFeatureDirtyRangeType,
@@ -33,17 +22,26 @@ import type {
IRuntimeUnitDataType,
IUnitExcludedCell,
} from '../basics/common';
import type { LexerNode } from '../engine/analysis/lexer-node';
import type { IAllRuntimeData, IExecutionInProgressParams } from './runtime.service';
import {
Disposable,
IConfigService,
Inject,
ObjectMatrix,
requestImmediateMacroTask,
} from '@univerjs/core';
import { Subject } from 'rxjs';
import { ErrorType } from '../basics/error-type';
import { CELL_INVERTED_INDEX_CACHE } from '../basics/inverted-index-cache';
import { Lexer } from '../engine/analysis/lexer';
import type { LexerNode } from '../engine/analysis/lexer-node';
import { AstTreeBuilder } from '../engine/analysis/parser';
import { ErrorNode } from '../engine/ast-node/base-ast-node';
import { FormulaDependencyGenerator } from '../engine/dependency/formula-dependency';
import { Interpreter } from '../engine/interpreter/interpreter';
import { FORMULA_REF_TO_ARRAY_CACHE, type FunctionVariantType } from '../engine/reference-object/base-reference-object';
import { IFormulaCurrentConfigService } from './current-data.service';
import type { IAllRuntimeData, IExecutionInProgressParams } from './runtime.service';
import { FormulaExecuteStageType, IFormulaRuntimeService } from './runtime.service';
export const DEFAULT_CYCLE_REFERENCE_COUNT = 1;
@@ -52,7 +50,6 @@ export const CYCLE_REFERENCE_COUNT = 'cycleReferenceCount';
export const EVERY_N_FUNCTION_EXECUTION_PAUSE = 100;
@OnLifecycle(LifecycleStages.Rendered, CalculateFormulaService)
export class CalculateFormulaService extends Disposable {
private readonly _executionStartListener$ = new Subject<boolean>();
@@ -204,6 +204,15 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:
});
dependencies?.forEach((d) => injector.add(d));
this._injector.get(SheetInterceptorService);
this._injector.get(WorkbookPermissionService);
this._injector.get(WorksheetPermissionService);
this._injector.get(ConditionalFormattingService);
}
override onReady(): void {
this._injector.get(SheetsRenderService);
}
}
@@ -88,6 +88,11 @@ export function createTestBed(documentConfig?: IDocumentData, dependencies?: Dep
renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_DOC, [DocSkeletonManagerService] as Dependency);
renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_DOC, [DocIMEInputManagerService] as Dependency);
}
override onReady(): void {
this._injector.get(DocStateChangeManagerService);
this._injector.get(DocsRenderService);
}
}
injector.get(LocaleService).load({ zhCN, enUS });

Some files were not shown because too many files have changed in this diff Show More