diff --git a/packages/preset-sheets-core/src/types.ts b/packages/preset-sheets-core/src/types.ts index 76033e4..d3a959d 100644 --- a/packages/preset-sheets-core/src/types.ts +++ b/packages/preset-sheets-core/src/types.ts @@ -1,4 +1,6 @@ import type { IUniverConfig, Plugin, PluginCtor } from '@univerjs/core'; +import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; +import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula'; /** * A collection of plugins and their default configs. @@ -11,3 +13,12 @@ export interface IPreset { export interface IPresetOptions { lazy?: boolean; } + +export interface IUniverFormulaConfig extends + Pick, + Pick { +} + +export interface IUniverFormulaWorkerConfig extends + Pick { +} diff --git a/packages/preset-sheets-core/src/umd.ts b/packages/preset-sheets-core/src/umd.ts index 589b891..e23ac4d 100644 --- a/packages/preset-sheets-core/src/umd.ts +++ b/packages/preset-sheets-core/src/umd.ts @@ -1,7 +1,7 @@ import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc'; import type { IUniverSheetsUIConfig } from '@univerjs/sheets-ui'; import type { IUniverUIConfig } from '@univerjs/ui'; -import type { IPreset } from './types'; +import type { IPreset, IUniverFormulaConfig } from './types'; import { UniverDocsPlugin } from '@univerjs/docs'; import { UniverDocsUIPlugin } from '@univerjs/docs-ui'; import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'; @@ -35,6 +35,14 @@ export interface IUniverSheetsCorePresetConfig extends Pick, Pick { + /** + * The formula configuration. + */ + formula?: IUniverFormulaConfig; + + /** + * The URL of the worker script. + */ workerURL: IUniverRPCMainThreadConfig['workerURL']; } @@ -51,6 +59,7 @@ export function UniverSheetsCorePreset(config: Partial !!v) as IPreset['plugins'], }; diff --git a/packages/preset-sheets-core/src/worker.ts b/packages/preset-sheets-core/src/worker.ts index 6ce28c8..28e1a54 100644 --- a/packages/preset-sheets-core/src/worker.ts +++ b/packages/preset-sheets-core/src/worker.ts @@ -1,14 +1,24 @@ -import type { IPreset } from './types'; +import type { IPreset, IUniverFormulaWorkerConfig } from './types'; import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'; import { UniverRPCWorkerThreadPlugin } from '@univerjs/rpc'; import { UniverSheetsPlugin } from '@univerjs/sheets'; import { UniverRemoteSheetsFormulaPlugin } from '@univerjs/sheets-formula'; -export function UniverSheetsCoreWorkerPreset(): IPreset { +export interface IUniverSheetsCoreWorkerPresetConfig { + /** + * The formula worker config. + */ + formula?: IUniverFormulaWorkerConfig; +} + +export function UniverSheetsCoreWorkerPreset(config: Partial = {}): IPreset { + const { + formula, + } = config; return { plugins: [ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }], - UniverFormulaEnginePlugin, + [UniverFormulaEnginePlugin, { function: formula?.function }], UniverRPCWorkerThreadPlugin, UniverRemoteSheetsFormulaPlugin, ], diff --git a/packages/preset-sheets-node-core/src/types.ts b/packages/preset-sheets-node-core/src/types.ts index 76033e4..d3a959d 100644 --- a/packages/preset-sheets-node-core/src/types.ts +++ b/packages/preset-sheets-node-core/src/types.ts @@ -1,4 +1,6 @@ import type { IUniverConfig, Plugin, PluginCtor } from '@univerjs/core'; +import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; +import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula'; /** * A collection of plugins and their default configs. @@ -11,3 +13,12 @@ export interface IPreset { export interface IPresetOptions { lazy?: boolean; } + +export interface IUniverFormulaConfig extends + Pick, + Pick { +} + +export interface IUniverFormulaWorkerConfig extends + Pick { +} diff --git a/packages/preset-sheets-node-core/src/umd.ts b/packages/preset-sheets-node-core/src/umd.ts index 60445d5..8fe37cf 100644 --- a/packages/preset-sheets-node-core/src/umd.ts +++ b/packages/preset-sheets-node-core/src/umd.ts @@ -1,4 +1,4 @@ -import type { IPreset } from './types'; +import type { IPreset, IUniverFormulaConfig } from './types'; import { UniverDocsPlugin } from '@univerjs/docs'; import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'; import { UniverRPCNodeMainPlugin } from '@univerjs/rpc-node'; @@ -19,11 +19,19 @@ import '@univerjs/engine-formula/facade'; import '@univerjs/sheets-filter/facade'; export interface IUniverSheetsNodeCorePresetConfig { + /** + * The formula configuration. + */ + formula?: IUniverFormulaConfig; + + /** + * The URL of the worker script. + */ workerSrc?: string; } export function UniverSheetsNodeCorePreset(config: Partial): IPreset { - const { workerSrc } = config; + const { workerSrc, formula } = config; const useWorker = !!workerSrc; @@ -32,13 +40,13 @@ export function UniverSheetsNodeCorePreset(config: Partial = {}): IPreset { + const { + formula, + } = config; + return { plugins: [ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }], - UniverFormulaEnginePlugin, + [UniverFormulaEnginePlugin, { function: formula?.function }], UniverRPCNodeWorkerPlugin, UniverRemoteSheetsFormulaPlugin, ],