From 59294d2b103ea5774f61d70a635ec364b48b6b8b Mon Sep 17 00:00:00 2001 From: Dushusir <1414556676@qq.com> Date: Wed, 11 Dec 2024 21:15:11 +0800 Subject: [PATCH 1/4] fix(formula): formula props --- examples/package.json | 1 + packages/preset-sheets-core/src/umd.ts | 12 +++++++++--- packages/preset-sheets-core/src/worker.ts | 11 +++++++++-- packages/preset-sheets-node-core/src/umd.ts | 12 ++++++++---- packages/preset-sheets-node-core/src/worker.ts | 12 ++++++++++-- pnpm-lock.yaml | 3 +++ 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/examples/package.json b/examples/package.json index 3f645ab..4d82487 100644 --- a/examples/package.json +++ b/examples/package.json @@ -11,6 +11,7 @@ "dependencies": { "@univerjs/core": "0.5.1", "@univerjs/design": "0.5.1", + "@univerjs/engine-formula": "0.5.1", "@univerjs/presets": "workspace:*", "@univerjs/sheets-zen-editor": "0.5.1", "clsx": "^2.1.1", diff --git a/packages/preset-sheets-core/src/umd.ts b/packages/preset-sheets-core/src/umd.ts index 589b891..db8a6e9 100644 --- a/packages/preset-sheets-core/src/umd.ts +++ b/packages/preset-sheets-core/src/umd.ts @@ -1,4 +1,6 @@ +import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc'; +import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula'; import type { IUniverSheetsUIConfig } from '@univerjs/sheets-ui'; import type { IUniverUIConfig } from '@univerjs/ui'; import type { IPreset } from './types'; @@ -33,7 +35,9 @@ import '@univerjs/sheets-numfmt-ui/lib/index.css'; export interface IUniverSheetsCorePresetConfig extends Pick, - Pick { + Pick, + Pick, + Pick { workerURL: IUniverRPCMainThreadConfig['workerURL']; } @@ -51,6 +55,8 @@ 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..84a80d6 100644 --- a/packages/preset-sheets-core/src/worker.ts +++ b/packages/preset-sheets-core/src/worker.ts @@ -1,14 +1,21 @@ +import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; import type { IPreset } 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 extends + Pick {} + +export function UniverSheetsCoreWorkerPreset(config: Partial = {}): IPreset { + const { + function: functionUser, + } = config; return { plugins: [ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }], - UniverFormulaEnginePlugin, + [UniverFormulaEnginePlugin, { function: functionUser }], UniverRPCWorkerThreadPlugin, UniverRemoteSheetsFormulaPlugin, ], diff --git a/packages/preset-sheets-node-core/src/umd.ts b/packages/preset-sheets-node-core/src/umd.ts index 60445d5..49354e6 100644 --- a/packages/preset-sheets-node-core/src/umd.ts +++ b/packages/preset-sheets-node-core/src/umd.ts @@ -1,3 +1,5 @@ +import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; +import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula'; import type { IPreset } from './types'; import { UniverDocsPlugin } from '@univerjs/docs'; import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'; @@ -18,12 +20,14 @@ import '@univerjs/sheets-data-validation/facade'; import '@univerjs/engine-formula/facade'; import '@univerjs/sheets-filter/facade'; -export interface IUniverSheetsNodeCorePresetConfig { +export interface IUniverSheetsNodeCorePresetConfig extends + Pick, + Pick { workerSrc?: string; } export function UniverSheetsNodeCorePreset(config: Partial): IPreset { - const { workerSrc } = config; + const { workerSrc, function: functionUser, description } = config; const useWorker = !!workerSrc; @@ -32,13 +36,13 @@ export function UniverSheetsNodeCorePreset(config: Partial {} + +export function UniverSheetsNodeCoreWorkerPreset(config: Partial = {}): IPreset { + const { + function: functionUser, + } = config; + return { plugins: [ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }], - UniverFormulaEnginePlugin, + [UniverFormulaEnginePlugin, { function: functionUser }], UniverRPCNodeWorkerPlugin, UniverRemoteSheetsFormulaPlugin, ], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f958253..55e61f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,6 +72,9 @@ importers: '@univerjs/design': specifier: 0.5.1 version: 0.5.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@univerjs/engine-formula': + specifier: 0.5.1 + version: 0.5.1(@grpc/grpc-js@1.9.14)(react@18.3.1)(rxjs@7.8.1) '@univerjs/presets': specifier: workspace:* version: link:../packages/presets From 533aee941dd13c50953c3f47ec1f617631b65850 Mon Sep 17 00:00:00 2001 From: Dushusir <1414556676@qq.com> Date: Thu, 12 Dec 2024 14:31:56 +0800 Subject: [PATCH 2/4] fix(formula): set formula config for presets --- examples/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/package.json b/examples/package.json index 4d82487..3f645ab 100644 --- a/examples/package.json +++ b/examples/package.json @@ -11,7 +11,6 @@ "dependencies": { "@univerjs/core": "0.5.1", "@univerjs/design": "0.5.1", - "@univerjs/engine-formula": "0.5.1", "@univerjs/presets": "workspace:*", "@univerjs/sheets-zen-editor": "0.5.1", "clsx": "^2.1.1", From 51d9a07b30606a60a18fc8d5b82e9368d5d767d3 Mon Sep 17 00:00:00 2001 From: Dushusir <1414556676@qq.com> Date: Thu, 12 Dec 2024 14:33:35 +0800 Subject: [PATCH 3/4] fix(formula): set formula config for presets --- packages/preset-sheets-core/src/types.ts | 11 +++++++++ packages/preset-sheets-core/src/umd.ts | 23 +++++++++++-------- packages/preset-sheets-core/src/worker.ts | 12 +++++----- packages/preset-sheets-node-core/src/types.ts | 11 +++++++++ packages/preset-sheets-node-core/src/umd.ts | 15 +++++------- .../preset-sheets-node-core/src/worker.ts | 12 +++++----- pnpm-lock.yaml | 3 --- 7 files changed, 53 insertions(+), 34 deletions(-) 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 db8a6e9..e23ac4d 100644 --- a/packages/preset-sheets-core/src/umd.ts +++ b/packages/preset-sheets-core/src/umd.ts @@ -1,9 +1,7 @@ -import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc'; -import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula'; 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,10 +33,16 @@ import '@univerjs/sheets-numfmt-ui/lib/index.css'; export interface IUniverSheetsCorePresetConfig extends Pick, - Pick, - Pick, - Pick { + Pick { + /** + * The formula configuration. + */ + formula?: IUniverFormulaConfig; + + /** + * The URL of the worker script. + */ workerURL: IUniverRPCMainThreadConfig['workerURL']; } @@ -55,8 +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 84a80d6..a7bc943 100644 --- a/packages/preset-sheets-core/src/worker.ts +++ b/packages/preset-sheets-core/src/worker.ts @@ -1,21 +1,21 @@ -import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; -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 interface IUniverSheetsCoreWorkerPresetConfig extends - Pick {} +export interface IUniverSheetsCoreWorkerPresetConfig { + formula?: IUniverFormulaWorkerConfig; +} export function UniverSheetsCoreWorkerPreset(config: Partial = {}): IPreset { const { - function: functionUser, + formula, } = config; return { plugins: [ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }], - [UniverFormulaEnginePlugin, { function: functionUser }], + [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 49354e6..c8f7b46 100644 --- a/packages/preset-sheets-node-core/src/umd.ts +++ b/packages/preset-sheets-node-core/src/umd.ts @@ -1,6 +1,4 @@ -import type { IUniverEngineFormulaConfig } from '@univerjs/engine-formula'; -import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula'; -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'; @@ -20,14 +18,13 @@ import '@univerjs/sheets-data-validation/facade'; import '@univerjs/engine-formula/facade'; import '@univerjs/sheets-filter/facade'; -export interface IUniverSheetsNodeCorePresetConfig extends - Pick, - Pick { +export interface IUniverSheetsNodeCorePresetConfig { + formula?: IUniverFormulaConfig; workerSrc?: string; } export function UniverSheetsNodeCorePreset(config: Partial): IPreset { - const { workerSrc, function: functionUser, description } = config; + const { workerSrc, formula } = config; const useWorker = !!workerSrc; @@ -36,13 +33,13 @@ export function UniverSheetsNodeCorePreset(config: Partial {} +export interface IUniverSheetsNodeCoreWorkerPresetConfig { + formula?: IUniverFormulaWorkerConfig; +} export function UniverSheetsNodeCoreWorkerPreset(config: Partial = {}): IPreset { const { - function: functionUser, + formula, } = config; return { plugins: [ [UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }], - [UniverFormulaEnginePlugin, { function: functionUser }], + [UniverFormulaEnginePlugin, { function: formula?.function }], UniverRPCNodeWorkerPlugin, UniverRemoteSheetsFormulaPlugin, ], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 55e61f5..f958253 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,9 +72,6 @@ importers: '@univerjs/design': specifier: 0.5.1 version: 0.5.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@univerjs/engine-formula': - specifier: 0.5.1 - version: 0.5.1(@grpc/grpc-js@1.9.14)(react@18.3.1)(rxjs@7.8.1) '@univerjs/presets': specifier: workspace:* version: link:../packages/presets From 5b1acda07ac7241008440cb76d1f9381b72bae78 Mon Sep 17 00:00:00 2001 From: Dushusir <1414556676@qq.com> Date: Thu, 12 Dec 2024 14:35:20 +0800 Subject: [PATCH 4/4] chore(formula): add comment for interface --- packages/preset-sheets-core/src/worker.ts | 3 +++ packages/preset-sheets-node-core/src/umd.ts | 7 +++++++ packages/preset-sheets-node-core/src/worker.ts | 3 +++ 3 files changed, 13 insertions(+) diff --git a/packages/preset-sheets-core/src/worker.ts b/packages/preset-sheets-core/src/worker.ts index a7bc943..28e1a54 100644 --- a/packages/preset-sheets-core/src/worker.ts +++ b/packages/preset-sheets-core/src/worker.ts @@ -5,6 +5,9 @@ import { UniverSheetsPlugin } from '@univerjs/sheets'; import { UniverRemoteSheetsFormulaPlugin } from '@univerjs/sheets-formula'; export interface IUniverSheetsCoreWorkerPresetConfig { + /** + * The formula worker config. + */ formula?: IUniverFormulaWorkerConfig; } diff --git a/packages/preset-sheets-node-core/src/umd.ts b/packages/preset-sheets-node-core/src/umd.ts index c8f7b46..8fe37cf 100644 --- a/packages/preset-sheets-node-core/src/umd.ts +++ b/packages/preset-sheets-node-core/src/umd.ts @@ -19,7 +19,14 @@ 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; } diff --git a/packages/preset-sheets-node-core/src/worker.ts b/packages/preset-sheets-node-core/src/worker.ts index 0f14ba1..70e95c4 100644 --- a/packages/preset-sheets-node-core/src/worker.ts +++ b/packages/preset-sheets-node-core/src/worker.ts @@ -10,6 +10,9 @@ export * from '@univerjs/sheets'; export * from '@univerjs/sheets-formula'; export interface IUniverSheetsNodeCoreWorkerPresetConfig { + /** + * The formula worker config. + */ formula?: IUniverFormulaWorkerConfig; }