Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(formula): formula props #26

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/preset-sheets-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -11,3 +13,12 @@ export interface IPreset {
export interface IPresetOptions {
lazy?: boolean;
}

export interface IUniverFormulaConfig extends
Pick<IUniverEngineFormulaConfig, 'function'>,
Pick<IUniverSheetsFormulaBaseConfig, 'description'> {
}

export interface IUniverFormulaWorkerConfig extends
Pick<IUniverEngineFormulaConfig, 'function'> {
}
15 changes: 12 additions & 3 deletions packages/preset-sheets-core/src/umd.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -35,6 +35,14 @@ export interface IUniverSheetsCorePresetConfig extends
Pick<IUniverUIConfig, 'container' | 'header' | 'footer' | 'toolbar' | 'menu' | 'contextMenu' | 'disableAutoFocus'>,
Pick<IUniverSheetsUIConfig, 'formulaBar'> {

/**
* The formula configuration.
*/
formula?: IUniverFormulaConfig;

/**
* The URL of the worker script.
*/
workerURL: IUniverRPCMainThreadConfig['workerURL'];
}

Expand All @@ -51,6 +59,7 @@ export function UniverSheetsCorePreset(config: Partial<IUniverSheetsCorePresetCo
menu,
contextMenu,
disableAutoFocus,
formula,
} = config;

const useWorker = !!workerSrc;
Expand All @@ -73,14 +82,14 @@ export function UniverSheetsCorePreset(config: Partial<IUniverSheetsCorePresetCo
useWorker
? [UniverRPCMainThreadPlugin, { workerURL: workerSrc }]
: null,
[UniverFormulaEnginePlugin, { notExecuteFormula: useWorker }],
[UniverFormulaEnginePlugin, { notExecuteFormula: useWorker, function: formula?.function }],

[UniverSheetsPlugin, { notExecuteFormula: useWorker, onlyRegisterFormulaRelatedMutations: false }],
UniverSheetsUIPlugin,
UniverSheetsNumfmtPlugin,
UniverSheetsNumfmtUIPlugin,

UniverSheetsFormulaPlugin,
[UniverSheetsFormulaPlugin, { notExecuteFormula: useWorker, description: formula?.description }],
UniverSheetsFormulaUIPlugin,
].filter(v => !!v) as IPreset['plugins'],
};
Expand Down
16 changes: 13 additions & 3 deletions packages/preset-sheets-core/src/worker.ts
Original file line number Diff line number Diff line change
@@ -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<IUniverSheetsCoreWorkerPresetConfig> = {}): IPreset {
const {
formula,
} = config;
return {
plugins: [
[UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }],
UniverFormulaEnginePlugin,
[UniverFormulaEnginePlugin, { function: formula?.function }],
UniverRPCWorkerThreadPlugin,
UniverRemoteSheetsFormulaPlugin,
],
Expand Down
11 changes: 11 additions & 0 deletions packages/preset-sheets-node-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -11,3 +13,12 @@ export interface IPreset {
export interface IPresetOptions {
lazy?: boolean;
}

export interface IUniverFormulaConfig extends
Pick<IUniverEngineFormulaConfig, 'function'>,
Pick<IUniverSheetsFormulaBaseConfig, 'description'> {
}

export interface IUniverFormulaWorkerConfig extends
Pick<IUniverEngineFormulaConfig, 'function'> {
}
16 changes: 12 additions & 4 deletions packages/preset-sheets-node-core/src/umd.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<IUniverSheetsNodeCorePresetConfig>): IPreset {
const { workerSrc } = config;
const { workerSrc, formula } = config;

const useWorker = !!workerSrc;

Expand All @@ -32,13 +40,13 @@ export function UniverSheetsNodeCorePreset(config: Partial<IUniverSheetsNodeCore
useWorker
? [UniverRPCNodeMainPlugin, { workerSrc }]
: null,
[UniverFormulaEnginePlugin, { notExecuteFormula: useWorker }],
[UniverFormulaEnginePlugin, { notExecuteFormula: useWorker, function: formula?.function }],

UniverThreadCommentPlugin,
UniverDocsPlugin,

UniverSheetsPlugin,
[UniverSheetsFormulaPlugin, { notExecuteFormula: useWorker }],
[UniverSheetsFormulaPlugin, { notExecuteFormula: useWorker, description: formula?.description }],
UniverSheetsDataValidationPlugin,
UniverSheetsFilterPlugin,
UniverSheetsHyperLinkPlugin,
Expand Down
17 changes: 14 additions & 3 deletions packages/preset-sheets-node-core/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IPreset } from './types';
import type { IPreset, IUniverFormulaWorkerConfig } from './types';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRPCNodeWorkerPlugin } from '@univerjs/rpc-node';
import { UniverSheetsPlugin } from '@univerjs/sheets';
Expand All @@ -9,11 +9,22 @@ export * from '@univerjs/rpc-node';
export * from '@univerjs/sheets';
export * from '@univerjs/sheets-formula';

export function UniverSheetsNodeCoreWorkerPreset(): IPreset {
export interface IUniverSheetsNodeCoreWorkerPresetConfig {
/**
* The formula worker config.
*/
formula?: IUniverFormulaWorkerConfig;
}

export function UniverSheetsNodeCoreWorkerPreset(config: Partial<IUniverSheetsNodeCoreWorkerPresetConfig> = {}): IPreset {
const {
formula,
} = config;

return {
plugins: [
[UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true }],
UniverFormulaEnginePlugin,
[UniverFormulaEnginePlugin, { function: formula?.function }],
UniverRPCNodeWorkerPlugin,
UniverRemoteSheetsFormulaPlugin,
],
Expand Down
Loading