Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(core): add register multi plugins API (#5604)
Evan Hu3fd10c060ad3
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex 8824a2d886..e732762c7f 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -95,39 +95,38 @@ function createNewInstance() {});const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });- univer.registerPlugin(UniverRPCMainThreadPlugin, { workerURL: worker });- univer.registerPlugin(UniverDocsPlugin);- univer.registerPlugin(UniverRenderEnginePlugin);- univer.registerPlugin(UniverUIPlugin, {- container: 'app',- // ribbonType: 'simple',- });- univer.registerPlugin(UniverWebComponentAdapterPlugin);- univer.registerPlugin(UniverVue3AdapterPlugin);- univer.registerPlugin(UniverDocsUIPlugin);-- univer.registerPlugin(UniverSheetsPlugin, {- notExecuteFormula: true,- autoHeightForMergedCells: true,- });- univer.registerPlugin(UniverSheetsUIPlugin);- univer.registerPlugin(UniverSheetsNumfmtPlugin);- univer.registerPlugin(UniverSheetsZenEditorPlugin);- univer.registerPlugin(UniverFormulaEnginePlugin, { notExecuteFormula: true });- univer.registerPlugin(UniverSheetsFormulaPlugin, { notExecuteFormula: true });- univer.registerPlugin(UniverSheetsDataValidationPlugin);- univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);- univer.registerPlugin(UniverSheetsFilterPlugin);- univer.registerPlugin(UniverSheetsSortPlugin);- univer.registerPlugin(UniverSheetsHyperLinkPlugin);- univer.registerPlugin(UniverSheetsThreadCommentPlugin);-- univer.registerPlugin(UniverSheetsTablePlugin);- univer.registerPlugin(UniverNetworkPlugin);- univer.registerPlugin(UniverSheetsNotePlugin);- univer.registerPlugin(ImportCSVButtonPlugin);- univer.registerPlugin(UniverSheetsCustomShortcutPlugin);+ univer.registerPlugins([+ [UniverRPCMainThreadPlugin, { workerURL: worker }],+ [UniverDocsPlugin],+ [UniverRenderEnginePlugin],+ [UniverUIPlugin, {+ container: 'app',+ }],+ [UniverWebComponentAdapterPlugin],+ [UniverVue3AdapterPlugin],+ [UniverDocsUIPlugin],+ [UniverSheetsPlugin, {+ notExecuteFormula: true,+ autoHeightForMergedCells: true,+ }],+ [UniverSheetsUIPlugin],+ [UniverSheetsNumfmtPlugin],+ [UniverSheetsZenEditorPlugin],+ [UniverFormulaEnginePlugin, { notExecuteFormula: true }],+ [UniverSheetsFormulaPlugin, { notExecuteFormula: true }],+ [UniverSheetsDataValidationPlugin],+ [UniverSheetsConditionalFormattingPlugin],+ [UniverSheetsFilterPlugin],+ [UniverSheetsSortPlugin],+ [UniverSheetsHyperLinkPlugin],+ [UniverSheetsThreadCommentPlugin],+ [UniverSheetsTablePlugin],+ [UniverNetworkPlugin],+ [UniverSheetsNotePlugin],+ [ImportCSVButtonPlugin],+ [UniverSheetsCustomShortcutPlugin],+ ]);// If we are running in e2e platform, we should immediately register the debugger plugin.if (IS_E2E) {@@ -151,14 +150,14 @@ function createNewInstance() {setTimeout(() => {import('./lazy').then((lazy) => {const plugins = lazy.default();- plugins.forEach((p) => univer.registerPlugin(p[0], p[1]));+ univer.registerPlugins(plugins);});}, LOAD_LAZY_PLUGINS_TIMEOUT);setTimeout(() => {import('./very-lazy').then((lazy) => {const plugins = lazy.default();- plugins.forEach((p) => univer.registerPlugin(p[0], p[1]));+ univer.registerPlugins(plugins);});}, LOAD_VERY_LAZY_PLUGINS_TIMEOUT);diff --git a/examples/src/sheets/worker.ts b/examples/src/sheets/worker.tsindex 97cd766704..69c9716bfd 100644--- a/examples/src/sheets/worker.ts+++ b/examples/src/sheets/worker.ts@@ -31,11 +31,13 @@ const univer = new Univer({},});-univer.registerPlugin(UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true });-univer.registerPlugin(UniverFormulaEnginePlugin);-univer.registerPlugin(UniverRPCWorkerThreadPlugin);-univer.registerPlugin(UniverRemoteSheetsFormulaPlugin);-univer.registerPlugin(UniverSheetsFilterPlugin);+univer.registerPlugins([+ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }],+ [UniverFormulaEnginePlugin],+ [UniverRPCWorkerThreadPlugin],+ [UniverRemoteSheetsFormulaPlugin],+ [UniverSheetsFilterPlugin],+]);declare let self: WorkerGlobalScope & typeof globalThis & { univer: Univer };self.univer = univer;diff --git a/packages/core/src/univer.ts b/packages/core/src/univer.tsindex 8d5fdd49bb..d07be4ee50 100644--- a/packages/core/src/univer.ts+++ b/packages/core/src/univer.ts@@ -220,6 +220,34 @@ export class Univer implements IDisposable {registerPlugin<T extends PluginCtor<Plugin>>(plugin: T, config?: ConstructorParameters<T>[0]): void {this._pluginService.registerPlugin(plugin, config);}++ /**+ * Register multiple plugins into univer.+ * @param plugins An array of tuples, where each tuple contains a plugin constructor and its optional configuration.+ */+ registerPlugins<+ T extends readonly (+ | readonly [PluginCtor<Plugin>]+ | readonly [PluginCtor<Plugin>, unknown]+ )[]+ >(+ plugins: {+ readonly [K in keyof T]: T[K] extends readonly [infer P]+ ? P extends PluginCtor<Plugin>+ ? readonly [P]+ : T[K]+ : T[K] extends readonly [infer P, unknown]+ ? P extends PluginCtor<Plugin>+ ? readonly [P, ConstructorParameters<P>[0]?]+ : T[K]+ : T[K];+ }+ ): void {+ plugins.forEach((item) => {+ const [plugin, config] = item;+ this._pluginService.registerPlugin(plugin, config);+ });+ }}function createUniverInjector(parentInjector?: Injector, override?: DependencyOverride): Injector {