Skip to content

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.

6.5 KB
Raw Blame
/**
 * Copyright 2023-present DreamNum Co., Ltd.
 *
 * 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 { IExecutionOptions, IMutation, IUnitRange, Nullable } from '@univerjs/core';
import type {
    IFormulaData,
    IFormulaExecuteResultMap,
    IFormulaStringMap,
    IRuntimeOtherUnitDataType,
    IRuntimeUnitDataPrimitiveType,
} from '../../basics/common';
import type {
    IFormulaDependencyTreeFullJson,
    IFormulaDependencyTreeJson,
    IFormulaDependentsAndInRangeResults,
} from '../../engine/dependency/dependency-tree';
import type { IFormulaDirtyData } from '../../services/current-data.service';
import type { FormulaExecutedStateType, ICircularReference, IExecutionInProgressParams } from '../../services/runtime.service';
import { CommandType } from '@univerjs/core';

export interface ISetFormulaCalculationStartMutation extends IFormulaDirtyData {
    options: Nullable<IExecutionOptions>;
}

export interface ISetFormulaStringBatchCalculationMutation {
    formulas: IFormulaStringMap;
}

export interface ISetFormulaStringBatchCalculationResultMutation {
    result: IFormulaExecuteResultMap;
}

export interface ISetFormulaStringBatchCalculationResultMutation {
    result: IFormulaExecuteResultMap;
}

export interface ISetFormulaDependencyCalculationMutation {
    unitId: string;
    sheetId: string;
    row: number;
    column: number;
}

export interface ISetFormulaDependencyCalculationResultMutation {
    result: IFormulaDependencyTreeJson[];
}

export interface ISetCellFormulaDependencyCalculationResultMutation {
    result: IFormulaDependencyTreeFullJson | undefined;
}

export interface ISetQueryFormulaDependencyMutation {
    unitRanges: IUnitRange[];
    isInRange?: boolean;
}

export interface ISetQueryFormulaDependencyResultMutation {
    result: IFormulaDependencyTreeJson[];
}

export interface ISetQueryFormulaDependencyAllMutation {
    unitRanges: IUnitRange[];
}

export interface ISetQueryFormulaDependencyAllResultMutation {
    result: IFormulaDependentsAndInRangeResults;
}

/**
 * TODO: @DR-Univer
 * Trigger the calculation of the formula and stop the formula
 */
export const SetFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation> = {
    id: 'formula.mutation.set-formula-calculation-start',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetTriggerFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation> = {
    id: 'formula.mutation.set-trigger-formula-calculation-start',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetFormulaStringBatchCalculationMutation: IMutation<ISetFormulaStringBatchCalculationMutation> = {
    id: 'formula.mutation.set-formula-string-batch-calculation',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetFormulaStringBatchCalculationResultMutation: IMutation<ISetFormulaStringBatchCalculationResultMutation> = {
    id: 'formula.mutation.set-formula-string-batch-calculation-result',
    type: CommandType.MUTATION,
    handler: () => true,
};

export interface ISetFormulaCalculationStopMutation { }

export const SetFormulaCalculationStopMutation: IMutation<ISetFormulaCalculationStopMutation> = {
    id: 'formula.mutation.set-formula-calculation-stop',
    type: CommandType.MUTATION,
    handler: () => true,
};

// TODO: this name lacks Params
export interface ISetFormulaCalculationNotificationMutation {
    circularReferences?: ICircularReference[];
    functionsExecutedState?: FormulaExecutedStateType;
    stageInfo?: IExecutionInProgressParams;
}

export const SetFormulaCalculationNotificationMutation: IMutation<ISetFormulaCalculationNotificationMutation> = {
    id: 'formula.mutation.set-formula-calculation-notification',
    type: CommandType.MUTATION,
    handler: () => true,
};

export interface ISetFormulaCalculationResultMutation {
    unitData: IRuntimeUnitDataPrimitiveType;
    sourceFormulaData?: IFormulaData;
    unitOtherData: IRuntimeOtherUnitDataType;
}

export const SetFormulaCalculationResultMutation: IMutation<ISetFormulaCalculationResultMutation> = {
    id: 'formula.mutation.set-formula-calculation-result',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetFormulaDependencyCalculationMutation: IMutation<{}> = {
    id: 'formula.mutation.set-formula-dependency-calculation',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetFormulaDependencyCalculationResultMutation: IMutation<ISetFormulaDependencyCalculationResultMutation> = {
    id: 'formula.mutation.set-formula-dependency-calculation-result',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetCellFormulaDependencyCalculationMutation: IMutation<ISetFormulaDependencyCalculationMutation> = {
    id: 'formula.mutation.set-cell-formula-dependency-calculation',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetCellFormulaDependencyCalculationResultMutation: IMutation<ISetCellFormulaDependencyCalculationResultMutation> = {
    id: 'formula.mutation.set-cell-formula-dependency-calculation-result',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetQueryFormulaDependencyMutation: IMutation<ISetQueryFormulaDependencyMutation> = {
    id: 'formula.mutation.set-query-formula-dependency',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetQueryFormulaDependencyResultMutation: IMutation<ISetQueryFormulaDependencyResultMutation> = {
    id: 'formula.mutation.set-query-formula-dependency-result',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetQueryFormulaDependencyAllMutation: IMutation<ISetQueryFormulaDependencyAllMutation> = {
    id: 'formula.mutation.set-query-formula-dependency-all',
    type: CommandType.MUTATION,
    handler: () => true,
};

export const SetQueryFormulaDependencyAllResultMutation: IMutation<ISetQueryFormulaDependencyAllResultMutation> = {
    id: 'formula.mutation.set-query-formula-dependency-all-result',
    type: CommandType.MUTATION,
    handler: () => true,
};