mirror of
https://github.com/dream-num/univer.git
synced 2026-09-24 15:32:18 +08:00
refactor: extract plugin service (#1993)
* refactor: extract plugin service * refactor: change how plugin name is provided * feat: change plugin names and types * feat: support register plugin with duplication detection * feat: find replace plugin register its dependency * fix: fix type error
This commit is contained in:
@@ -22,7 +22,7 @@ import { interval, takeUntil, throttle } from 'rxjs';
|
||||
|
||||
@OnLifecycle(LifecycleStages.Rendered, PerformanceMonitorController)
|
||||
export class PerformanceMonitorController extends RxDisposable {
|
||||
private _documentType: UniverInstanceType = UniverInstanceType.UNKNOWN;
|
||||
private _documentType: UniverInstanceType = UniverInstanceType.UNIVER;
|
||||
private _hasWatched = false;
|
||||
private _container!: HTMLDivElement;
|
||||
private _styleElement!: HTMLStyleElement;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -24,16 +24,16 @@ import { PerformanceMonitorController } from './controllers/performance-monitor.
|
||||
export interface IDebuggerPluginConfig {}
|
||||
|
||||
export class DebuggerPlugin extends Plugin {
|
||||
static override type = PluginType.Doc;
|
||||
static override pluginName = 'debugger';
|
||||
static override type = UniverInstanceType.DOC;
|
||||
|
||||
private _debuggerController!: DebuggerController;
|
||||
|
||||
constructor(
|
||||
config: IDebuggerPluginConfig,
|
||||
@Inject(Injector) override readonly _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
_config: IDebuggerPluginConfig,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('debugger');
|
||||
super();
|
||||
this._initializeDependencies(_injector);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ export class DebuggerPlugin extends Plugin {
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
override onDestroy(): void {}
|
||||
|
||||
getDebuggerController() {
|
||||
return this._debuggerController;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import { UniverDocsPlugin } from '@univerjs/docs';
|
||||
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
|
||||
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
|
||||
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
|
||||
import { UniverFindReplacePlugin } from '@univerjs/find-replace';
|
||||
import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc';
|
||||
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
|
||||
import { UniverSheetsPlugin } from '@univerjs/sheets';
|
||||
@@ -81,10 +80,6 @@ univer.registerPlugin(UniverRPCMainThreadPlugin, {
|
||||
workerURL: './worker.js',
|
||||
} as IUniverRPCMainThreadConfig);
|
||||
|
||||
// find replace
|
||||
univer.registerPlugin(UniverFindReplacePlugin);
|
||||
// univer.registerPlugin(UniverSheetsFindPlugin);
|
||||
|
||||
// data validation
|
||||
univer.registerPlugin(UniverDataValidationPlugin);
|
||||
univer.registerPlugin(UniverSheetsDataValidationPlugin);
|
||||
|
||||
@@ -20,7 +20,7 @@ import { Disposable } from '../shared';
|
||||
* Type of built-in univer document instances.
|
||||
*/
|
||||
export enum UniverInstanceType {
|
||||
UNKNOWN = 0,
|
||||
UNIVER = 0,
|
||||
DOC = 1,
|
||||
SHEET = 2,
|
||||
SLIDE = 3,
|
||||
|
||||
@@ -19,7 +19,7 @@ import { installShims } from './common/shims';
|
||||
export { type UnitType, UnitModel, UniverInstanceType } from './common/unit';
|
||||
export { Registry, RegistryAsMap } from './common/registry';
|
||||
export { Univer } from './univer';
|
||||
export { PluginHolder } from './common/plugin-holder';
|
||||
export { PluginHolder } from './services/plugin/plugin-holder';
|
||||
export { shallowEqual, isRangesEqual, isUnitRangesEqual } from './common/equal';
|
||||
export { dedupe, remove, rotate, groupBy } from './common/array';
|
||||
export {
|
||||
@@ -47,7 +47,8 @@ export { getBodySlice, composeBody } from './docs/data-model/text-x/utils';
|
||||
export { TextX } from './docs/data-model/text-x/text-x';
|
||||
export { replaceInDocumentBody } from './docs/data-model/replacement';
|
||||
export * from './observer';
|
||||
export { Plugin, PluginType } from './common/plugin';
|
||||
export { Plugin } from './services/plugin/plugin';
|
||||
export { PluginService } from './services/plugin/plugin.service';
|
||||
export {
|
||||
type CommandListener,
|
||||
CommandService,
|
||||
@@ -115,7 +116,7 @@ export { fromCallback } from './shared/rxjs';
|
||||
export type { IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';
|
||||
export { composeInterceptors, createInterceptorKey, InterceptorManager } from './common/interceptor';
|
||||
export { normalizeTextRuns } from './docs/data-model/apply-utils/common';
|
||||
export type { PluginCtor } from './common/plugin';
|
||||
export type { PluginCtor } from './services/plugin/plugin';
|
||||
export { Range } from './sheets/range';
|
||||
export { Styles } from './sheets/styles';
|
||||
export {
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/**
|
||||
* 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 type { Ctor, Injector } from '@wendellhu/redi';
|
||||
|
||||
export type PluginCtor<T extends Plugin> = Ctor<T> & { type: PluginType };
|
||||
|
||||
/** Plugin types for different kinds of business. */
|
||||
export enum PluginType {
|
||||
Univer,
|
||||
Doc,
|
||||
Sheet,
|
||||
Slide,
|
||||
}
|
||||
|
||||
/**
|
||||
* Plug-in base class, all plug-ins must inherit from this base class. Provide basic methods.
|
||||
*/
|
||||
export abstract class Plugin {
|
||||
static type: PluginType = PluginType.Univer;
|
||||
|
||||
protected abstract _injector: Injector;
|
||||
|
||||
private _name: string;
|
||||
|
||||
protected constructor(name: string) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
onStarting(injector: Injector): void {}
|
||||
|
||||
onReady(): void {}
|
||||
|
||||
onRendered(): void {}
|
||||
|
||||
onSteady(): void {}
|
||||
|
||||
onDestroy(): void {}
|
||||
|
||||
getPluginName(): string {
|
||||
return this._name;
|
||||
}
|
||||
}
|
||||
|
||||
interface IPluginRegistryItem {
|
||||
plugin: PluginCtor<Plugin>;
|
||||
options: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store plugin instances.
|
||||
*/
|
||||
export class PluginStore {
|
||||
private readonly _plugins: Plugin[] = [];
|
||||
|
||||
addPlugin(plugin: Plugin): void {
|
||||
this._plugins.push(plugin);
|
||||
}
|
||||
|
||||
removePlugins(): Plugin[] {
|
||||
const plugins = this._plugins.slice();
|
||||
this._plugins.length = 0;
|
||||
return plugins;
|
||||
}
|
||||
|
||||
forEachPlugin(callback: (plugin: Plugin) => void): void {
|
||||
this._plugins.forEach(callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store plugin registry items.
|
||||
*/
|
||||
export class PluginRegistry {
|
||||
private readonly _pluginsRegisteredByBusiness = new Map<PluginType, [IPluginRegistryItem]>();
|
||||
|
||||
registerPlugin(pluginCtor: PluginCtor<any>, options: any) {
|
||||
const type = pluginCtor.type;
|
||||
if (!this._pluginsRegisteredByBusiness.has(type)) {
|
||||
this._pluginsRegisteredByBusiness.set(type, [] as unknown[] as [IPluginRegistryItem]);
|
||||
}
|
||||
|
||||
this._pluginsRegisteredByBusiness.get(type)!.push({ plugin: pluginCtor, options });
|
||||
}
|
||||
|
||||
getRegisterPlugins(type: PluginType): [IPluginRegistryItem] {
|
||||
return this._pluginsRegisteredByBusiness.get(type) || ([] as unknown[] as [IPluginRegistryItem]);
|
||||
}
|
||||
|
||||
clearPluginsOfType(type: PluginType): void {
|
||||
this._pluginsRegisteredByBusiness.delete(type);
|
||||
}
|
||||
}
|
||||
+23
-6
@@ -18,18 +18,21 @@
|
||||
|
||||
import { type Ctor, Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
import { LifecycleStages } from '../services/lifecycle/lifecycle';
|
||||
import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
|
||||
import { Disposable } from '../shared/lifecycle';
|
||||
import { LifecycleStages } from '../lifecycle/lifecycle';
|
||||
import { LifecycleInitializerService, LifecycleService } from '../lifecycle/lifecycle.service';
|
||||
import { Disposable } from '../../shared/lifecycle';
|
||||
import { ILogService } from '../log/log.service';
|
||||
import { type Plugin, type PluginCtor, PluginRegistry, PluginStore } from './plugin';
|
||||
|
||||
export class PluginHolder extends Disposable {
|
||||
protected _started: boolean = false;
|
||||
|
||||
protected readonly _univerPluginStore = new PluginStore();
|
||||
protected readonly _pluginRegistered = new Set<string>();
|
||||
protected readonly _pluginStore = new PluginStore();
|
||||
protected readonly _pluginRegistry = new PluginRegistry();
|
||||
|
||||
constructor(
|
||||
@ILogService protected readonly _logService: ILogService,
|
||||
@Inject(Injector) protected readonly _injector: Injector,
|
||||
@Inject(LifecycleService) protected readonly _lifecycleService: LifecycleService,
|
||||
@Inject(LifecycleInitializerService) protected readonly _lifecycleInitializerService: LifecycleInitializerService
|
||||
@@ -37,7 +40,21 @@ export class PluginHolder extends Disposable {
|
||||
super();
|
||||
}
|
||||
|
||||
_registerPlugin<T extends PluginCtor<Plugin>>(pluginCtor: T, config?: ConstructorParameters<T>[0]): void {
|
||||
override dispose(): void {
|
||||
super.dispose();
|
||||
|
||||
this._pluginStore.forEachPlugin((plugin) => plugin.dispose());
|
||||
this._pluginStore.removePlugins();
|
||||
this._pluginRegistry.removePlugins();
|
||||
}
|
||||
|
||||
protected _registerPlugin<T extends PluginCtor<Plugin>>(pluginCtor: T, config?: ConstructorParameters<T>[0]): void {
|
||||
const { pluginName } = pluginCtor;
|
||||
if (this._pluginRegistered.has(pluginName)) {
|
||||
this._logService.warn('[PluginService]', `plugin ${pluginName} has already been registered. This registration will be ignored.`);
|
||||
return;
|
||||
}
|
||||
|
||||
this._pluginRegistry.registerPlugin(pluginCtor, config);
|
||||
}
|
||||
|
||||
@@ -52,7 +69,7 @@ export class PluginHolder extends Disposable {
|
||||
if (!this._started) return;
|
||||
|
||||
const plugins = this._pluginRegistry.getRegisterPlugins().map(({ plugin, options }) => this._initPlugin(plugin, options));
|
||||
this._pluginRegistry.clearPlugins();
|
||||
this._pluginRegistry.removePlugins();
|
||||
|
||||
this.disposeWithMe(this._lifecycleService.subscribeWithPrevious().subscribe((stage) => {
|
||||
this._pluginsRunLifecycle(plugins, stage);
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* 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 { Inject, Injector } from '@wendellhu/redi';
|
||||
import { type UnitType, UniverInstanceType } from '../../common/unit';
|
||||
import { LifecycleInitializerService, LifecycleService } from '../lifecycle/lifecycle.service';
|
||||
import { LifecycleStages } from '../lifecycle/lifecycle';
|
||||
import { ILogService } from '../log/log.service';
|
||||
import { PluginHolder } from './plugin-holder';
|
||||
import type { Plugin, PluginCtor } from './plugin';
|
||||
|
||||
const INIT_LAZY_PLUGINS_TIMEOUT = 200;
|
||||
|
||||
/**
|
||||
* This service manages plugin registration.
|
||||
*/
|
||||
export class PluginService extends PluginHolder {
|
||||
private _pluginHoldersForTypes = new Map<UnitType, PluginHolder>();
|
||||
|
||||
constructor(
|
||||
@ILogService _logService: ILogService,
|
||||
@Inject(Injector) _injector: Injector,
|
||||
@Inject(LifecycleService) _lifecycleService: LifecycleService,
|
||||
@Inject(LifecycleInitializerService) _lifecycleInitializerService: LifecycleInitializerService
|
||||
) {
|
||||
super(_logService, _injector, _lifecycleService, _lifecycleInitializerService);
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
this._clearFlushLazyPluginsTimer();
|
||||
|
||||
// Dispose all plugin holders including self.
|
||||
super.dispose();
|
||||
for (const holder of this._pluginHoldersForTypes.values()) {
|
||||
holder.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/** Register a plugin into univer. */
|
||||
registerPlugin<T extends PluginCtor<Plugin>>(plugin: T, config?: ConstructorParameters<T>[0]): void {
|
||||
this._assertPluginValid(plugin);
|
||||
|
||||
const { type } = plugin;
|
||||
if (type === UniverInstanceType.UNIVER) {
|
||||
return this._registerPlugin(plugin, config);
|
||||
}
|
||||
|
||||
// If it's type is for specific document, we should run them at specific time.
|
||||
const holder = this._ensurePluginHolderForType(type);
|
||||
|
||||
// @ts-ignore
|
||||
holder._registerPlugin(plugin, config);
|
||||
}
|
||||
|
||||
private _assertPluginValid(plugin: PluginCtor<Plugin>): void {
|
||||
const { type, pluginName } = plugin;
|
||||
|
||||
if (type === UniverInstanceType.UNRECOGNIZED) {
|
||||
throw new Error(`[PluginService]: invalid plugin type for ${plugin}. Please assign a "type" to your plugin.`);
|
||||
}
|
||||
|
||||
if (pluginName === '') {
|
||||
throw new Error(`[PluginService]: no plugin name for ${plugin}. Please assign a "pluginName" to your plugin.`);
|
||||
}
|
||||
}
|
||||
|
||||
protected override _registerPlugin<T extends PluginCtor<Plugin>>(pluginCtor: T, options?: ConstructorParameters<T>[0]): void {
|
||||
const { pluginName } = pluginCtor;
|
||||
if (this._pluginRegistered.has(pluginName)) {
|
||||
this._logService.warn('[PluginService]', `plugin ${pluginName} has already been registered. This registration will be ignored.`);
|
||||
return;
|
||||
}
|
||||
|
||||
this._pluginRegistered.add(pluginName);
|
||||
|
||||
if (this._started) {
|
||||
this._pluginRegistry.registerPlugin(pluginCtor, options);
|
||||
|
||||
// If Univer has already started, we should manually call onStarting for the plugin.
|
||||
// We do that in an asynchronous way, because user may lazy load several plugins at the same time.
|
||||
return this._scheduleInitPluginAfterStarted();
|
||||
} else {
|
||||
// For plugins at Univer level. Plugins would be initialized immediately so they can register dependencies.
|
||||
const pluginInstance: Plugin = this._injector.createInstance(pluginCtor, options);
|
||||
this._pluginStore.addPlugin(pluginInstance);
|
||||
this._pluginsRunLifecycle([pluginInstance], LifecycleStages.Starting);
|
||||
}
|
||||
}
|
||||
|
||||
_ensurePluginHolderForType(type: UnitType): PluginHolder {
|
||||
if (!this._pluginHoldersForTypes.has(type)) {
|
||||
const pluginHolder = this._injector.createInstance(PluginHolder);
|
||||
this._pluginHoldersForTypes.set(type, pluginHolder);
|
||||
return pluginHolder;
|
||||
}
|
||||
|
||||
return this._pluginHoldersForTypes.get(type)!;
|
||||
}
|
||||
|
||||
private _initLazyPluginsTimer?: number;
|
||||
private _scheduleInitPluginAfterStarted() {
|
||||
if (this._initLazyPluginsTimer === undefined) {
|
||||
this._initLazyPluginsTimer = setTimeout(
|
||||
() => this._flushLazyPlugins(),
|
||||
INIT_LAZY_PLUGINS_TIMEOUT
|
||||
) as unknown as number;
|
||||
}
|
||||
}
|
||||
|
||||
private _clearFlushLazyPluginsTimer() {
|
||||
if (this._initLazyPluginsTimer) {
|
||||
clearTimeout(this._initLazyPluginsTimer);
|
||||
this._initLazyPluginsTimer = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private _flushLazyPlugins() {
|
||||
this._flush();
|
||||
|
||||
for (const [_, holder] of this._pluginHoldersForTypes) {
|
||||
holder._flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,35 +15,21 @@
|
||||
*/
|
||||
|
||||
import type { Ctor, Injector } from '@wendellhu/redi';
|
||||
import { Disposable } from '../../shared';
|
||||
import { UniverInstanceType } from '../../common/unit';
|
||||
|
||||
export type PluginCtor<T extends Plugin> = Ctor<T> & { type: PluginType };
|
||||
|
||||
/**
|
||||
* Plugin types for different kinds of business.
|
||||
*
|
||||
* @deprecated use UnitType instead
|
||||
*/
|
||||
export enum PluginType {
|
||||
Univer = 0,
|
||||
Doc = 1,
|
||||
Sheet = 2,
|
||||
Slide = 3,
|
||||
}
|
||||
export type PluginCtor<T extends Plugin> = Ctor<T> & { type: UniverInstanceType; pluginName: string };
|
||||
|
||||
/**
|
||||
* Plug-in base class, all plug-ins must inherit from this base class. Provide basic methods.
|
||||
*/
|
||||
export abstract class Plugin {
|
||||
static type: PluginType = PluginType.Univer;
|
||||
export abstract class Plugin extends Disposable {
|
||||
static pluginName: string = '';
|
||||
static type: UniverInstanceType = UniverInstanceType.UNRECOGNIZED;
|
||||
|
||||
protected abstract _injector: Injector;
|
||||
|
||||
private _name: string;
|
||||
|
||||
protected constructor(name: string) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||
onStarting(injector: Injector): void {}
|
||||
|
||||
onReady(): void {}
|
||||
@@ -52,15 +38,18 @@ export abstract class Plugin {
|
||||
|
||||
onSteady(): void {}
|
||||
|
||||
onDestroy(): void {}
|
||||
getUniverInstanceType(): UniverInstanceType {
|
||||
return (this.constructor as typeof Plugin).type;
|
||||
}
|
||||
|
||||
getPluginName(): string {
|
||||
return this._name;
|
||||
return (this.constructor as typeof Plugin).pluginName;
|
||||
}
|
||||
}
|
||||
|
||||
interface IPluginRegistryItem {
|
||||
plugin: PluginCtor<Plugin>;
|
||||
// eslint-disable-next-line ts/no-explicit-any
|
||||
options: any;
|
||||
}
|
||||
|
||||
@@ -100,7 +89,7 @@ export class PluginRegistry {
|
||||
return this._pluginsRegistered.slice();
|
||||
}
|
||||
|
||||
clearPlugins(): void {
|
||||
removePlugins(): void {
|
||||
this._pluginsRegistered = [];
|
||||
}
|
||||
}
|
||||
+18
-67
@@ -17,8 +17,6 @@
|
||||
import { Injector } from '@wendellhu/redi';
|
||||
|
||||
import { DocumentDataModel } from './docs/data-model/document-data-model';
|
||||
import type { Plugin, PluginCtor } from './common/plugin';
|
||||
import { PluginType } from './common/plugin';
|
||||
import { CommandService, ICommandService } from './services/command/command.service';
|
||||
import { ConfigService, IConfigService } from './services/config/config.service';
|
||||
import { ContextService, IContextService } from './services/context/context.service';
|
||||
@@ -44,26 +42,25 @@ import { Workbook } from './sheets/workbook';
|
||||
import { SlideDataModel } from './slides/slide-model';
|
||||
import type { LocaleType } from './types/enum/locale-type';
|
||||
import type { IDocumentData, ISlideData, IUniverData, IWorkbookData } from './types/interfaces';
|
||||
import { PluginHolder } from './common/plugin-holder';
|
||||
import type { UnitModel, UnitType } from './common/unit';
|
||||
import { UniverInstanceType } from './common/unit';
|
||||
import { PluginService } from './services/plugin/plugin.service';
|
||||
import type { Plugin, PluginCtor } from './services/plugin/plugin';
|
||||
|
||||
const INIT_LAZY_PLUGINS_TIMEOUT = 200;
|
||||
|
||||
export class Univer extends PluginHolder {
|
||||
export class Univer {
|
||||
private _startedTypes = new Set<UnitType>();
|
||||
private _pluginHoldersForTypes = new Map<UnitType, PluginHolder>();
|
||||
private _injector: Injector;
|
||||
|
||||
private get _univerInstanceService(): IUniverInstanceService {
|
||||
return this._injector.get(IUniverInstanceService);
|
||||
}
|
||||
|
||||
constructor(univerData: Partial<IUniverData> = {}) {
|
||||
const injector = createUniverInjector();
|
||||
const lifecycleService = injector.get(LifecycleService);
|
||||
const lifecycleInitializerService = injector.get(LifecycleInitializerService);
|
||||
private get _pluginService(): PluginService {
|
||||
return this._injector.get(PluginService);
|
||||
}
|
||||
|
||||
super(injector, lifecycleService, lifecycleInitializerService);
|
||||
constructor(univerData: Partial<IUniverData> = {}) {
|
||||
const injector = this._injector = createUniverInjector();
|
||||
|
||||
const { theme, locale, locales, logLevel } = univerData;
|
||||
|
||||
@@ -79,10 +76,8 @@ export class Univer extends PluginHolder {
|
||||
return this._injector;
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
dispose(): void {
|
||||
this._injector.dispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
setLocale(locale: LocaleType) {
|
||||
@@ -124,12 +119,12 @@ export class Univer extends PluginHolder {
|
||||
const univerInstanceService = injector.get(IUniverInstanceService) as UniverInstanceService;
|
||||
univerInstanceService.__setCreateHandler(
|
||||
(type: UnitType, data, ctor) => {
|
||||
this._start();
|
||||
this._tryProgressToStart();
|
||||
|
||||
if (!this._startedTypes.has(type)) {
|
||||
this._startedTypes.add(type);
|
||||
|
||||
const pluginHolder = this._ensurePluginHolderForType(type);
|
||||
const pluginHolder = this._pluginService._ensurePluginHolderForType(type);
|
||||
pluginHolder._start();
|
||||
|
||||
const model = injector.createInstance(ctor, data);
|
||||
@@ -147,6 +142,10 @@ export class Univer extends PluginHolder {
|
||||
);
|
||||
}
|
||||
|
||||
private _tryProgressToStart(): void {
|
||||
this._pluginService._start();
|
||||
}
|
||||
|
||||
private _tryProgressToReady(): void {
|
||||
const lifecycleService = this._injector.get(LifecycleService);
|
||||
if (lifecycleService.stage < LifecycleStages.Ready) {
|
||||
@@ -154,59 +153,10 @@ export class Univer extends PluginHolder {
|
||||
}
|
||||
}
|
||||
|
||||
private _ensurePluginHolderForType(type: UnitType): PluginHolder {
|
||||
if (!this._pluginHoldersForTypes.has(type)) {
|
||||
const pluginHolder = this._injector.createInstance(PluginHolder);
|
||||
this._pluginHoldersForTypes.set(type, pluginHolder);
|
||||
return pluginHolder;
|
||||
}
|
||||
|
||||
return this._pluginHoldersForTypes.get(type)!;
|
||||
}
|
||||
|
||||
/** Register a plugin into univer. */
|
||||
registerPlugin<T extends PluginCtor<Plugin>>(plugin: T, config?: ConstructorParameters<T>[0]): void {
|
||||
const type = plugin.type;
|
||||
if (type === PluginType.Univer) {
|
||||
return this._registerPlugin(plugin, config);
|
||||
}
|
||||
|
||||
// If it's type is for specific document, we should run them at specific time.
|
||||
const holder = this._ensurePluginHolderForType(type);
|
||||
holder._registerPlugin(plugin, config);
|
||||
}
|
||||
|
||||
override _registerPlugin<T extends PluginCtor<Plugin>>(pluginCtor: T, options?: ConstructorParameters<T>[0]): void {
|
||||
if (this._started) {
|
||||
this._pluginRegistry.registerPlugin(pluginCtor, options);
|
||||
|
||||
// If Univer has already started, we should manually call onStarting for the plugin.
|
||||
// We do that in an asynchronous way, because user may lazy load several plugins at the same time.
|
||||
return this._scheduleInitPluginAfterStarted();
|
||||
} else {
|
||||
// For plugins at Univer level. Plugins would be initialized immediately so they can register dependencies.
|
||||
const pluginInstance: Plugin = this._injector.createInstance(pluginCtor, options);
|
||||
this._univerPluginStore.addPlugin(pluginInstance);
|
||||
this._pluginsRunLifecycle([pluginInstance], LifecycleStages.Starting);
|
||||
}
|
||||
}
|
||||
|
||||
private _initLazyPluginsTimer?: number;
|
||||
private _scheduleInitPluginAfterStarted() {
|
||||
if (this._initLazyPluginsTimer === undefined) {
|
||||
this._initLazyPluginsTimer = setTimeout(
|
||||
() => this._flushLazyPlugins(),
|
||||
INIT_LAZY_PLUGINS_TIMEOUT
|
||||
) as unknown as number;
|
||||
}
|
||||
}
|
||||
|
||||
private _flushLazyPlugins() {
|
||||
this._flush();
|
||||
|
||||
for (const [_, holder] of this._pluginHoldersForTypes) {
|
||||
holder._flush();
|
||||
}
|
||||
this._pluginService.registerPlugin(plugin, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +168,7 @@ function createUniverInjector() {
|
||||
[LifecycleService],
|
||||
[LifecycleInitializerService],
|
||||
[UniverPermissionService],
|
||||
[PluginService],
|
||||
[IUniverInstanceService, { useClass: UniverInstanceService }],
|
||||
[IPermissionService, { useClass: PermissionService }],
|
||||
[ILogService, { useClass: DesktopLogService, lazy: true }],
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ICommandService, Plugin } from '@univerjs/core';
|
||||
import { ICommandService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
import { DataValidatorRegistryService } from './services/data-validator-registry.service';
|
||||
@@ -28,12 +28,15 @@ import { DataValidationFormulaMarkDirty } from './commands/mutations/formula.mut
|
||||
const PLUGIN_NAME = 'data-validation';
|
||||
|
||||
export class UniverDataValidationPlugin extends Plugin {
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
_config: unknown,
|
||||
@Inject(Injector) protected _injector: Injector,
|
||||
@ICommandService private _commandService: ICommandService
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
IUniverInstanceService,
|
||||
LocaleService,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Tools,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -58,7 +58,8 @@ import { TextSelectionController } from './controllers/text-selection.controller
|
||||
import { BackScrollController } from './controllers/back-scroll.controller';
|
||||
|
||||
export class UniverDocsUIPlugin extends Plugin {
|
||||
static override type = PluginType.Doc;
|
||||
static override pluginName = DOC_UI_PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.DOC;
|
||||
|
||||
constructor(
|
||||
private readonly _config: IUniverDocsUIConfig,
|
||||
@@ -66,7 +67,7 @@ export class UniverDocsUIPlugin extends Plugin {
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService,
|
||||
@ILogService private _logService: ILogService
|
||||
) {
|
||||
super(DOC_UI_PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._localeService.load({
|
||||
zhCN,
|
||||
@@ -82,8 +83,6 @@ export class UniverDocsUIPlugin extends Plugin {
|
||||
this._markDocAsFocused();
|
||||
}
|
||||
|
||||
override onDestroy(): void {}
|
||||
|
||||
private _initializeCommands(): void {
|
||||
[
|
||||
MoveCursorUpShortcut,
|
||||
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
IUniverInstanceService,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -97,10 +97,11 @@ export function createCommandTestBed(workbookConfig?: IDocumentData, dependencie
|
||||
* This plugin hooks into Doc's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(_config: undefined, @Inject(Injector) override readonly _injector: Injector) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -18,7 +18,7 @@ import type { ICommand } from '@univerjs/core';
|
||||
import {
|
||||
ICommandService,
|
||||
Plugin,
|
||||
PluginType,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import { ITextSelectionRenderManager, TextSelectionRenderManager } from '@univerjs/engine-render';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
@@ -70,7 +70,8 @@ const DEFAULT_DOCUMENT_PLUGIN_DATA = {
|
||||
const PLUGIN_NAME = 'docs';
|
||||
|
||||
export class UniverDocsPlugin extends Plugin {
|
||||
static override type = PluginType.Doc;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.DOC;
|
||||
|
||||
private _config: IUniverDocsConfig;
|
||||
|
||||
@@ -78,7 +79,7 @@ export class UniverDocsPlugin extends Plugin {
|
||||
config: Partial<IUniverDocsConfig> = {},
|
||||
@Inject(Injector) override _injector: Injector
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._config = Object.assign(DEFAULT_DOCUMENT_PLUGIN_DATA, config);
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ import {
|
||||
LogLevel,
|
||||
ObjectMatrix,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -233,7 +233,8 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
private _formulaDataModel: FormulaDataModel | null = null;
|
||||
|
||||
@@ -241,7 +242,7 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -23,9 +23,9 @@ import {
|
||||
LogLevel,
|
||||
ObjectMatrix,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -156,7 +156,8 @@ export function createFunctionTestBed(workbookConfig?: IWorkbookData, dependenci
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
private _formulaDataModel: FormulaDataModel | null = null;
|
||||
|
||||
@@ -164,7 +165,7 @@ export function createFunctionTestBed(workbookConfig?: IWorkbookData, dependenci
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -59,13 +59,14 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Plugin } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Ctor, Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -66,11 +66,14 @@ interface IUniverFormulaEngine {
|
||||
}
|
||||
|
||||
export class UniverFormulaEnginePlugin extends Plugin {
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
|
||||
constructor(
|
||||
private _config: IUniverFormulaEngine,
|
||||
@Inject(Injector) protected override _injector: Injector
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import { createIdentifier, Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
import { Engine } from './engine';
|
||||
@@ -28,13 +28,14 @@ export const IRenderingEngine = createIdentifier<Engine>('univer.render-engine')
|
||||
const PLUGIN_NAME = 'render-engine';
|
||||
|
||||
export class UniverRenderEnginePlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import {
|
||||
LocaleType,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
ThemeService,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import { FunctionService, IFunctionService } from '@univerjs/engine-formula';
|
||||
import { ISocketService, WebSocketService } from '@univerjs/network';
|
||||
@@ -86,13 +86,14 @@ export function createTestBed(workbookConfig?: IWorkbookData, dependencies?: Dep
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
LocaleService,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import {
|
||||
enUS,
|
||||
@@ -67,13 +67,14 @@ export function createTestBed(documentConfig?: IDocumentData, dependencies?: Dep
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import {
|
||||
LocaleType,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import { FunctionService, IFunctionService } from '@univerjs/engine-formula';
|
||||
import { ISocketService, WebSocketService } from '@univerjs/network';
|
||||
@@ -73,13 +73,14 @@ export function createTestBed(workbookConfig?: IWorkbookData, dependencies?: Dep
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LocaleService, Plugin } from '@univerjs/core';
|
||||
import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import { type Dependency, Inject, type Injector } from '@wendellhu/redi';
|
||||
|
||||
import { FindReplaceController } from './controllers/find-replace.controller';
|
||||
@@ -24,11 +24,14 @@ import { FindReplaceService, IFindReplaceService } from './services/find-replace
|
||||
const PLUGIN_NAME = 'FIND_REPLACE';
|
||||
|
||||
export class UniverFindReplacePlugin extends Plugin {
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
protected readonly _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._localeService.load({
|
||||
zhCN,
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DEFAULT_DOCUMENT_SUB_COMPONENT_ID, LocaleService, Plugin } from '@univerjs/core';
|
||||
import { DEFAULT_DOCUMENT_SUB_COMPONENT_ID, Plugin } from '@univerjs/core';
|
||||
import type { Dependency, Injector } from '@wendellhu/redi';
|
||||
import { Inject } from '@wendellhu/redi';
|
||||
|
||||
import { ImageLoadController } from './controllers/image.load.controller';
|
||||
import { ImageModel } from './models/image-model';
|
||||
@@ -26,12 +25,13 @@ import { IImageRenderService, ImageRenderService } from './services/image-render
|
||||
const PLUGIN_NAME = 'IMAGE_PLUGIN';
|
||||
|
||||
export class UniverImagePlugin extends Plugin {
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
|
||||
constructor(
|
||||
config: undefined,
|
||||
protected _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
_config: undefined,
|
||||
protected _injector: Injector
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(_injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -41,13 +41,14 @@ export interface IUniverRPCMainThreadConfig {
|
||||
* is also responsible for booting up the Web Worker instance of Univer.
|
||||
*/
|
||||
export class UniverRPCMainThreadPlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = 'UNIVER_RPC_MAIN_THREAD_PLUGIN';
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
private readonly _config: IUniverRPCMainThreadConfig,
|
||||
@Inject(Injector) protected readonly _injector: Injector
|
||||
) {
|
||||
super('UNIVER_RPC_MAIN_THREAD_PLUGIN');
|
||||
super();
|
||||
}
|
||||
|
||||
override async onStarting(injector: Injector): Promise<void> {
|
||||
@@ -78,13 +79,14 @@ export interface IUniverRPCWorkerThreadPluginConfig {}
|
||||
* This plugin is used to register the RPC services on the worker thread.
|
||||
*/
|
||||
export class UniverRPCWorkerThreadPlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = 'UNIVER_RPC_WORKER_THREAD_PLUGIN';
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
private readonly _config: IUniverRPCWorkerThreadPluginConfig,
|
||||
@Inject(Injector) protected readonly _injector: Injector
|
||||
) {
|
||||
super('UNIVER_RPC_WORKER_THREAD_PLUGIN');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ICommandService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { ICommandService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
import { SHEET_CONDITIONAL_FORMATTING_PLUGIN, SheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
|
||||
import { AddAverageCfCommand } from './commands/commands/add-average-cf.command';
|
||||
@@ -44,7 +44,9 @@ import { ConditionalFormattingEditorController } from './controllers/cf.editor.c
|
||||
import { ConditionalFormattingClearController } from './controllers/cf.clear.controller';
|
||||
|
||||
export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = SHEET_CONDITIONAL_FORMATTING_PLUGIN;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
static commandList = [
|
||||
AddAverageCfCommand,
|
||||
AddColorScaleConditionalRuleCommand,
|
||||
@@ -69,7 +71,7 @@ export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
|
||||
@Inject(Injector) override readonly _injector: Injector,
|
||||
@Inject(ICommandService) private _commandService: ICommandService
|
||||
) {
|
||||
super(SHEET_CONDITIONAL_FORMATTING_PLUGIN);
|
||||
super();
|
||||
this._initCommand();
|
||||
SheetsConditionalFormattingPlugin.dependencyList.forEach((dependency) => {
|
||||
this._injector.add(dependency);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ICommandService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { ICommandService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
import { SHEET_CONDITIONAL_FORMATTING_PLUGIN } from './base/const';
|
||||
@@ -30,15 +30,18 @@ import { ConditionalFormattingFormulaService } from './services/conditional-form
|
||||
import { ConditionalFormattingFormulaMarkDirty } from './commands/mutations/formula-mark-dirty.mutation';
|
||||
|
||||
export class SheetsConditionalFormattingPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = SHEET_CONDITIONAL_FORMATTING_PLUGIN;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
static readonly dependencyList: Dependency[] = [[ConditionalFormattingService], [ConditionalFormattingFormulaService], [ConditionalFormattingRuleModel], [ConditionalFormattingViewModel]];
|
||||
static readonly mutationList = [AddConditionalRuleMutation, DeleteConditionalRuleMutation, SetConditionalRuleMutation, MoveConditionalRuleMutation, ConditionalFormattingFormulaMarkDirty];
|
||||
|
||||
constructor(
|
||||
_config: unknown,
|
||||
@Inject(Injector) override readonly _injector: Injector,
|
||||
@Inject(ICommandService) private _commandService: ICommandService
|
||||
) {
|
||||
super(SHEET_CONDITIONAL_FORMATTING_PLUGIN);
|
||||
super();
|
||||
this._initCommand();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ICommandService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ICommandService, IUniverInstanceService, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import {
|
||||
SheetInterceptorService,
|
||||
} from '@univerjs/sheets';
|
||||
@@ -60,13 +60,14 @@ export const createTestBed = (dependencies?: Dependency[]) => {
|
||||
const get = injector.get.bind(injector);
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ICommandService, LocaleService, Plugin } from '@univerjs/core';
|
||||
import { ICommandService, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import { type Dependency, Inject, Injector } from '@wendellhu/redi';
|
||||
import { DataValidationRenderController } from './controllers/dv-render.controller';
|
||||
import { DataValidationController } from './controllers/dv.controller';
|
||||
@@ -37,13 +37,16 @@ import { DataValidationRejectInputController } from './controllers/dv-reject-inp
|
||||
import { DataValidationPanelService } from './services/data-validation-panel.service';
|
||||
|
||||
export class UniverSheetsDataValidationPlugin extends Plugin {
|
||||
static override pluginName = DATA_VALIDATION_PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: unknown,
|
||||
@Inject(Injector) protected _injector: Injector,
|
||||
@ICommandService private readonly _commandService: ICommandService,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
) {
|
||||
super(DATA_VALIDATION_PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector) {
|
||||
|
||||
@@ -14,24 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, PluginService, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
import { UniverFindReplacePlugin } from '@univerjs/find-replace';
|
||||
import { SheetsFindReplaceController } from './controllers/sheet-find-replace.controller';
|
||||
|
||||
export interface IFindPluginConfig {}
|
||||
|
||||
const NAME = 'UNIVER_SHEETS_FIND_REPLACE_PLUGIN';
|
||||
|
||||
export class UniverSheetsFindReplacePlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = NAME;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: Partial<IFindPluginConfig>,
|
||||
@Inject(Injector) protected readonly _injector: Injector
|
||||
_config: unknown,
|
||||
@Inject(Injector) protected readonly _injector: Injector,
|
||||
@Inject(PluginService) private readonly _pluginService: PluginService
|
||||
) {
|
||||
super(NAME);
|
||||
super();
|
||||
|
||||
this._pluginService.registerPlugin(UniverFindReplacePlugin);
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -617,7 +617,7 @@ Uniscript 底层使用了 `@univerjs/facade`,你也可以直接在项目中使
|
||||
首先 `plugin.ts` 中就不需要注册 `CustomFunctionController` 了,同级目录新建一个 `custom-function-plugin.ts`,专门用于注册 `CustomFunctionController`。
|
||||
|
||||
```ts
|
||||
import { Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -625,10 +625,11 @@ import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';
|
||||
import { CustomFunctionController } from './controllers/custom-function.controller';
|
||||
|
||||
export class UniverSheetsCustomFunctionPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = FORMULA_UI_PLUGIN_NAME
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(@Inject(Injector) override readonly _injector: Injector) {
|
||||
super(FORMULA_UI_PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
initialize(): void {
|
||||
|
||||
@@ -617,7 +617,7 @@ In addition to registering through the `UniverFormulaEnginePlugin` configuration
|
||||
First of all, there is no need to register `CustomFunctionController` in `plugin.ts`. Create a new `custom-function-plugin.ts` in the same directory, specifically for registering `CustomFunctionController`.
|
||||
|
||||
```ts
|
||||
import { Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -625,10 +625,11 @@ import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';
|
||||
import { CustomFunctionController } from './controllers/custom-function.controller';
|
||||
|
||||
export class UniverSheetsCustomFunctionPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = FORMULA_UI_PLUGIN_NAME
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(@Inject(Injector) override readonly _injector: Injector) {
|
||||
super(FORMULA_UI_PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
initialize(): void {
|
||||
|
||||
+4
-3
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import { LexerTreeBuilder } from '@univerjs/engine-formula';
|
||||
import { SelectionManagerService } from '@univerjs/sheets';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
@@ -54,13 +54,14 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData, Workbook } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula';
|
||||
import { SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
@@ -62,7 +62,8 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
const get = injector.get.bind(injector);
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
private _formulaDataModel: FormulaDataModel | null = null;
|
||||
|
||||
@@ -70,7 +71,7 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { IUniverInstanceService, LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { BaseFunction, IFunctionInfo, IFunctionNames } from '@univerjs/engine-formula';
|
||||
import type { Ctor, Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -50,15 +50,15 @@ interface IFormulaUIConfig {
|
||||
function: Array<[Ctor<BaseFunction>, IFunctionNames]>;
|
||||
}
|
||||
export class UniverSheetsFormulaPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = FORMULA_UI_PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
private _config: Partial<IFormulaUIConfig>,
|
||||
@Inject(Injector) override readonly _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService,
|
||||
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
) {
|
||||
super(FORMULA_UI_PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
initialize(): void {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ICommandService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ICommandService, IUniverInstanceService, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import { LexerTreeBuilder } from '@univerjs/engine-formula';
|
||||
import {
|
||||
INumfmtService,
|
||||
@@ -53,13 +53,14 @@ export const createTestBed = (dependencies?: Dependency[]) => {
|
||||
const get = injector.get.bind(injector);
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Plugin, PluginType } from '@univerjs/core';
|
||||
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
import { SHEET_NUMFMT_PLUGIN } from './base/const/PLUGIN_NAME';
|
||||
@@ -31,13 +31,14 @@ import { INumfmtController } from './controllers/type';
|
||||
import { UserHabitController } from './controllers/user-habit.controller';
|
||||
|
||||
export class UniverSheetsNumfmtPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = SHEET_NUMFMT_PLUGIN;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: unknown,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super(SHEET_NUMFMT_PLUGIN);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(): void {
|
||||
|
||||
@@ -23,8 +23,8 @@ import {
|
||||
LocaleType,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import { BorderStyleManagerService, SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
@@ -81,13 +81,14 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData, Workbook } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import { SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -48,13 +48,14 @@ export function createTestBed(workbookConfig?: IWorkbookData, dependencies?: Dep
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import { SelectionManagerService, SheetInterceptorService, SheetPermissionService } from '@univerjs/sheets';
|
||||
import { DesktopMenuService, DesktopShortcutService, IMenuService, IShortcutService } from '@univerjs/ui';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -50,12 +50,13 @@ export function createMenuTestBed() {
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override pluginName = 'test-plugin';
|
||||
protected override _injector: Injector;
|
||||
|
||||
static override type = PluginType.Sheet;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(_config: unknown, @Inject(Injector) _injector: Injector) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
get = this._injector.get.bind(this._injector);
|
||||
@@ -68,10 +69,6 @@ export function createMenuTestBed() {
|
||||
injector.add([SheetPermissionService]);
|
||||
injector.add([SheetInterceptorService]);
|
||||
}
|
||||
|
||||
override onDestroy(): void {
|
||||
get = null;
|
||||
}
|
||||
}
|
||||
|
||||
univer.registerPlugin(TestPlugin);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';
|
||||
import { SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';
|
||||
import {
|
||||
@@ -520,13 +520,14 @@ export function clipboardTestBed(workbookConfig?: IWorkbookData, dependencies?:
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
IUniverInstanceService,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -109,14 +109,14 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
|
||||
super();
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import type { Workbook } from '@univerjs/core';
|
||||
import { IUniverInstanceService, LocaleService, Plugin, PluginType, UniverInstanceType } from '@univerjs/core';
|
||||
import { IUniverInstanceService, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
import { SHEET_UI_PLUGIN_NAME } from './basics';
|
||||
import { ActiveWorksheetController } from './controllers/active-worksheet/active-worksheet.controller';
|
||||
import { AutoFillController } from './controllers/auto-fill.controller';
|
||||
import { AutoHeightController } from './controllers/auto-height.controller';
|
||||
@@ -71,7 +70,8 @@ import { CellCustomRenderController } from './controllers/cell-custom-render.con
|
||||
import { SheetCanvasPopManagerService } from './services/canvas-pop-manager.service';
|
||||
|
||||
export class UniverSheetsUIPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'SHEET_UI_PLUGIN_NAME';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
config: undefined,
|
||||
@@ -79,7 +79,7 @@ export class UniverSheetsUIPlugin extends Plugin {
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService,
|
||||
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
|
||||
) {
|
||||
super(SHEET_UI_PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._localeService.load({
|
||||
zhCN,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -25,14 +25,16 @@ import { zhCN } from './locale';
|
||||
|
||||
export interface IUniverSheetsZenEditorPluginConfig {}
|
||||
export class UniverSheetsZenEditorPlugin extends Plugin {
|
||||
static override type = PluginType.Doc;
|
||||
static override pluginName = 'zen-editor';
|
||||
static override type = UniverInstanceType.DOC;
|
||||
|
||||
constructor(
|
||||
config: IUniverSheetsZenEditorPluginConfig,
|
||||
_config: IUniverSheetsZenEditorPluginConfig,
|
||||
@Inject(Injector) override readonly _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
) {
|
||||
super('zen-editor');
|
||||
super();
|
||||
|
||||
this._initialize();
|
||||
this._initializeDependencies(this._injector);
|
||||
}
|
||||
@@ -52,8 +54,4 @@ export class UniverSheetsZenEditorPlugin extends Plugin {
|
||||
|
||||
dependencies.forEach((dependency) => injector.add(dependency));
|
||||
}
|
||||
|
||||
override onRendered(): void {}
|
||||
|
||||
override onDestroy(): void {}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ import {
|
||||
LocaleType,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Tools,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -81,13 +81,14 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
IUniverInstanceService,
|
||||
LogLevel,
|
||||
Plugin,
|
||||
PluginType,
|
||||
Univer,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
@@ -109,13 +109,14 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
|
||||
const injector = univer.__getInjector();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
|
||||
this._injector = _injector;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -52,13 +52,14 @@ export function createTestBase(workbookConfig?: IWorkbookData, dependencies?: De
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -66,13 +66,14 @@ export function createTestBase(workbookConfig?: IWorkbookData, dependencies?: De
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -66,13 +66,14 @@ export function createTestBase(workbookConfig?: IWorkbookData, dependencies?: De
|
||||
* This plugin hooks into Sheet's DI system to expose API to test scripts
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import type { ICommand, IRange, IWorkbookData, Nullable } from '@univerjs/core';
|
||||
import { ICommandService, ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ICommandService, ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -61,13 +61,14 @@ export function createRefRangeTestBed() {
|
||||
const get = injector.get.bind(injector);
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-plugin');
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IWorkbookData } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
|
||||
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -49,13 +49,14 @@ export function createCoreTestBed(workbookConfig?: IWorkbookData, dependencies?:
|
||||
const get = injector.get.bind(injector);
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = 'test-plugin';
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
_config: undefined,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super('test-spy-plugin');
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ICommandService, LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { ICommandService, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -32,7 +32,7 @@ import { SelectionManagerService } from './services/selection-manager.service';
|
||||
import { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
|
||||
import { DefinedNameDataController } from './controllers/defined-name-data.controller';
|
||||
|
||||
const PLUGIN_NAME = 'sheet';
|
||||
const PLUGIN_NAME = 'sheets';
|
||||
|
||||
export interface IUniverSheetsConfig {
|
||||
notExecuteFormula?: boolean;
|
||||
@@ -42,7 +42,8 @@ export interface IUniverSheetsConfig {
|
||||
* The main sheet base, construct the sheet container and layout, mount the rendering engine
|
||||
*/
|
||||
export class UniverSheetsPlugin extends Plugin {
|
||||
static override type = PluginType.Sheet;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.SHEET;
|
||||
|
||||
constructor(
|
||||
private _config: IUniverSheetsConfig,
|
||||
@@ -50,7 +51,7 @@ export class UniverSheetsPlugin extends Plugin {
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._initializeDependencies(_injector);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { SlideDataModel } from '@univerjs/core';
|
||||
import { IUniverInstanceService, LocaleService, Plugin, PluginType, UniverInstanceType } from '@univerjs/core';
|
||||
import { IUniverInstanceService, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -25,7 +25,8 @@ import { zhCN } from './locale';
|
||||
export const SLIDE_UI_PLUGIN_NAME = 'slides-ui';
|
||||
|
||||
export class UniverSlidesUIPlugin extends Plugin {
|
||||
static override type = PluginType.Slide;
|
||||
static override pluginName = SLIDE_UI_PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.SLIDE;
|
||||
|
||||
constructor(
|
||||
_config: unknown,
|
||||
@@ -33,7 +34,7 @@ export class UniverSlidesUIPlugin extends Plugin {
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService,
|
||||
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
|
||||
) {
|
||||
super(SLIDE_UI_PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { IUniverInstanceService, LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { IUniverInstanceService, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Engine } from '@univerjs/engine-render';
|
||||
import { IRenderingEngine } from '@univerjs/engine-render';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
@@ -30,7 +30,8 @@ const DEFAULT_SLIDE_PLUGIN_DATA = {};
|
||||
const PLUGIN_NAME = 'slides';
|
||||
|
||||
export class UniverSlidesPlugin extends Plugin {
|
||||
static override type = PluginType.Slide;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.SLIDE;
|
||||
|
||||
private _config: IUniverSlidesConfig;
|
||||
|
||||
@@ -44,7 +45,7 @@ export class UniverSlidesPlugin extends Plugin {
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService,
|
||||
@Inject(Injector) override readonly _injector: Injector
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._config = Object.assign(DEFAULT_SLIDE_PLUGIN_DATA, config);
|
||||
this._initializeDependencies(this._injector);
|
||||
@@ -69,10 +70,6 @@ export class UniverSlidesPlugin extends Plugin {
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
override onDestroy(): void {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
getCanvasEngine() {
|
||||
return this._canvasEngine;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IContextService } from '@univerjs/core';
|
||||
import { IConfigService, ILocalStorageService, LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { IConfigService, ILocalStorageService, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -68,7 +68,8 @@ export const DISABLE_AUTO_FOCUS_KEY = 'DISABLE_AUTO_FOCUS';
|
||||
* UI plugin provides basic interaction with users. Including workbench (menus, UI parts, notifications etc.), copy paste, shortcut.
|
||||
*/
|
||||
export class UniverUIPlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
private _config: Partial<IUniverUIConfig> = {},
|
||||
@@ -76,11 +77,9 @@ export class UniverUIPlugin extends Plugin {
|
||||
@Inject(Injector) protected readonly _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
|
||||
this._localeService.load({
|
||||
zhCN,
|
||||
});
|
||||
this._localeService.load({ zhCN });
|
||||
|
||||
if (this._config.disableAutoFocus) {
|
||||
this._contextService.setContextValue(DISABLE_AUTO_FOCUS_KEY, true);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LocaleService, Plugin, PluginType } from '@univerjs/core';
|
||||
import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
||||
import type { Dependency } from '@wendellhu/redi';
|
||||
import { Inject, Injector } from '@wendellhu/redi';
|
||||
|
||||
@@ -30,14 +30,15 @@ const PLUGIN_NAME = 'uniscript';
|
||||
export interface IUniscriptConfig extends IScriptEditorServiceConfig {}
|
||||
|
||||
export class UniverUniscriptPlugin extends Plugin {
|
||||
static override type = PluginType.Univer;
|
||||
static override pluginName = PLUGIN_NAME;
|
||||
static override type = UniverInstanceType.UNIVER;
|
||||
|
||||
constructor(
|
||||
private readonly _config: IUniscriptConfig,
|
||||
@Inject(Injector) protected override _injector: Injector,
|
||||
@Inject(LocaleService) private readonly _localeService: LocaleService
|
||||
) {
|
||||
super(PLUGIN_NAME);
|
||||
super();
|
||||
}
|
||||
|
||||
override onStarting(injector: Injector): void {
|
||||
|
||||
Reference in New Issue
Block a user