mirror of
https://github.com/dream-num/univer.git
synced 2026-08-28 23:01:30 +08:00
feat(sheets): add biz info on other formula (#6296)
This commit is contained in:
@@ -43,7 +43,7 @@ import {
|
||||
import { replaceSelectionFactory } from '@univerjs/docs';
|
||||
import { RichText } from '@univerjs/engine-render';
|
||||
import { DataSyncPrimaryController } from '@univerjs/rpc';
|
||||
import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { OtherFormulaBizType, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { CanvasView } from '@univerjs/slides-ui';
|
||||
import { DumbUniFormulaService, IUniFormulaService } from '@univerjs/uni-formula';
|
||||
import { take } from 'rxjs';
|
||||
@@ -237,7 +237,7 @@ export class UniFormulaService extends DumbUniFormulaService implements IUniForm
|
||||
const pseudoId = getPseudoUnitKey(unitId);
|
||||
this._checkSyncingUnit(pseudoId);
|
||||
|
||||
const id = this._registerOtherFormulaSrv.registerFormulaWithRange(pseudoId, PSEUDO_SUBUNIT, f);
|
||||
const id = this._registerOtherFormulaSrv.registerFormulaWithRange(pseudoId, PSEUDO_SUBUNIT, f, undefined, undefined, OtherFormulaBizType.DOC, rangeId);
|
||||
this._docFormulas.set(key, { unitId, rangeId, f, formulaId: id, v, t });
|
||||
this._formulaIdToKey.set(id, key);
|
||||
|
||||
@@ -267,7 +267,7 @@ export class UniFormulaService extends DumbUniFormulaService implements IUniForm
|
||||
const pseudoId = getPseudoUnitKey(unitId);
|
||||
this._checkSyncingUnit(pseudoId);
|
||||
|
||||
const id = this._registerOtherFormulaSrv.registerFormulaWithRange(pseudoId, PSEUDO_SUBUNIT, f);
|
||||
const id = this._registerOtherFormulaSrv.registerFormulaWithRange(pseudoId, PSEUDO_SUBUNIT, f, undefined, undefined, OtherFormulaBizType.SLIDE, `${pageId}_${elementId}_${rangeId}`);
|
||||
this._slideFormulas.set(key, { unitId, pageId, elementId, rangeId, f, formulaId: id, v, t });
|
||||
this._formulaIdToKey.set(id, key);
|
||||
|
||||
@@ -318,11 +318,11 @@ export class UniFormulaService extends DumbUniFormulaService implements IUniForm
|
||||
// are registered formulas but not added to the formula system.
|
||||
this._docFormulas.forEach((value, key) => {
|
||||
if (!value.formulaId) {
|
||||
const { unitId, f } = value;
|
||||
const { unitId, f, rangeId } = value;
|
||||
const pseudoId = getPseudoUnitKey(unitId);
|
||||
this._checkSyncingUnit(pseudoId);
|
||||
|
||||
const id = this._registerOtherFormulaSrv.registerFormulaWithRange(pseudoId, PSEUDO_SUBUNIT, f);
|
||||
const id = this._registerOtherFormulaSrv.registerFormulaWithRange(pseudoId, PSEUDO_SUBUNIT, f, undefined, undefined, OtherFormulaBizType.DOC, rangeId);
|
||||
value.formulaId = id;
|
||||
this._formulaIdToKey.set(id, key);
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ import { ISuperTableService } from '../../services/super-table.service';
|
||||
import { LexerNode } from '../analysis/lexer-node';
|
||||
import { TableReferenceObject } from '../reference-object/table-reference-object';
|
||||
import { prefixHandler } from '../utils/prefix-handler';
|
||||
import { splitTableStructuredRef } from '../utils/reference';
|
||||
import { getReferenceObjectFromCache, ReferenceObjectType } from '../utils/value-object';
|
||||
import { ErrorValueObject } from '../value-object/base-value-object';
|
||||
import { BaseAstNode } from './base-ast-node';
|
||||
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
|
||||
import { NODE_ORDER_MAP, NodeType } from './node-type';
|
||||
import { splitTableStructuredRef } from '../utils/reference';
|
||||
|
||||
export class ReferenceNode extends BaseAstNode {
|
||||
private _refOffsetX = 0;
|
||||
|
||||
@@ -84,6 +84,9 @@ export class UniverSheetsConditionalFormattingPlugin extends Plugin {
|
||||
|
||||
override onStarting(): void {
|
||||
this._injector.get(ConditionalFormattingService);
|
||||
touchDependencies(this._injector, [[ConditionalFormattingService], [ConditionalFormattingViewModel]]);
|
||||
touchDependencies(this._injector, [
|
||||
[ConditionalFormattingService],
|
||||
[ConditionalFormattingViewModel],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
+31
-4
@@ -16,12 +16,12 @@
|
||||
|
||||
import type { ICellData, IRange, Nullable } from '@univerjs/core';
|
||||
import type { IOtherFormulaResult } from '@univerjs/sheets-formula';
|
||||
import type { IConditionalFormattingRuleConfig } from '../models/type';
|
||||
import type { IConditionalFormattingRuleConfig, IConditionFormattingRule } from '../models/type';
|
||||
import { BooleanNumber, CellValueType, Disposable, Inject, ObjectMatrix, RefAlias } from '@univerjs/core';
|
||||
import { FormulaResultStatus, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { FormulaResultStatus, OtherFormulaBizType, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
import { CFRuleType, CFValueType } from '../base/const';
|
||||
import { CFRuleType, CFSubRuleType, CFValueType } from '../base/const';
|
||||
import { ConditionalFormattingRuleModel } from '../models/conditional-formatting-rule-model';
|
||||
|
||||
// eslint-disable-next-line ts/consistent-type-definitions
|
||||
@@ -75,9 +75,36 @@ export class ConditionalFormattingFormulaService extends Disposable {
|
||||
this._removeFormulaByCfId(unitId, subUnitId, rule.cfId);
|
||||
}
|
||||
}
|
||||
if (option.type === 'add') {
|
||||
this._registerRuleFormulas(unitId, subUnitId, rule);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register formulas for a specific rule based on its type
|
||||
*/
|
||||
private _registerRuleFormulas(unitId: string, subUnitId: string, rule: IConditionFormattingRule): void {
|
||||
switch (rule.rule.type) {
|
||||
case CFRuleType.highlightCell: {
|
||||
// For highlight cell with formula subtype
|
||||
if (rule.rule.subType === CFSubRuleType.formula) {
|
||||
const formulaText = rule.rule.value;
|
||||
if (formulaText) {
|
||||
this.registerFormulaWithRange(
|
||||
unitId,
|
||||
subUnitId,
|
||||
rule.cfId,
|
||||
formulaText,
|
||||
rule.ranges
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _initFormulaResultChange() {
|
||||
// Subscribe to formula calculation results
|
||||
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((results: Record<string, Record<string, IOtherFormulaResult[]>>) => {
|
||||
@@ -126,7 +153,7 @@ export class ConditionalFormattingFormulaService extends Disposable {
|
||||
if (formulaMap.getValue(cfFormulaId, ['id'])) {
|
||||
return;
|
||||
}
|
||||
const formulaId = this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaText, ranges);
|
||||
const formulaId = this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaText, ranges, undefined, OtherFormulaBizType.CONDITIONAL_FORMATTING, cfId);
|
||||
formulaMap.addValue({
|
||||
formulaText,
|
||||
unitId,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import type { IRange, ISheetDataValidationRule } from '@univerjs/core';
|
||||
import { Disposable, Inject, isFormulaString, IUniverInstanceService, Rectangle, UniverInstanceType } from '@univerjs/core';
|
||||
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
|
||||
import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { OtherFormulaBizType, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { getFormulaCellData, shouldOffsetFormulaByRange } from '../utils/formula';
|
||||
import { DataValidationCacheService } from './dv-cache.service';
|
||||
|
||||
@@ -111,7 +111,7 @@ export class DataValidationCustomFormulaService extends Disposable {
|
||||
};
|
||||
|
||||
private _registerFormula(unitId: string, subUnitId: string, ruleId: string, formulaString: string, ranges: IRange[]) {
|
||||
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaString, ranges, { ruleId });
|
||||
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaString, ranges, { ruleId }, OtherFormulaBizType.DATA_VALIDATION_CUSTOM, ruleId);
|
||||
};
|
||||
|
||||
private _handleDirtyRanges(unitId: string, subUnitId: string, ranges: IRange[]) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import type { ISheetDataValidationRule, Nullable } from '@univerjs/core';
|
||||
import type { IFormulaInfo, IOtherFormulaResult } from '@univerjs/sheets-formula';
|
||||
import { DataValidationType, Disposable, Inject, isFormulaString, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
|
||||
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
|
||||
import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { OtherFormulaBizType, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
|
||||
import { shouldOffsetFormulaByRange } from '../utils/formula';
|
||||
import { DataValidationCacheService } from './dv-cache.service';
|
||||
import { DataValidationListCacheService } from './dv-list-cache.service';
|
||||
@@ -89,7 +89,7 @@ export class DataValidationFormulaService extends Disposable {
|
||||
|
||||
private _registerSingleFormula(unitId: string, subUnitId: string, formula: string, ruleId: string) {
|
||||
const ranges = [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }];
|
||||
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formula, ranges, { ruleId });
|
||||
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formula, ranges, { ruleId }, OtherFormulaBizType.DATA_VALIDATION, ruleId);
|
||||
}
|
||||
|
||||
addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
|
||||
|
||||
@@ -33,6 +33,6 @@ export type { IRegisterAsyncFunction, IRegisterFunction, ISingleFunctionRegister
|
||||
export type { IRegisterFunctionParams, IUnregisterFunctionParams } from './services/register-function.service';
|
||||
export { RegisterFunctionService } from './services/register-function.service';
|
||||
export { IRegisterFunctionService } from './services/register-function.service';
|
||||
export { RegisterOtherFormulaService } from './services/register-other-formula.service';
|
||||
export { OtherFormulaBizType, RegisterOtherFormulaService } from './services/register-other-formula.service';
|
||||
export { IRemoteRegisterFunctionService, RemoteRegisterFunctionService } from './services/remote/remote-register-function.service';
|
||||
export { calculateFormula } from './util/calculate';
|
||||
|
||||
@@ -24,6 +24,15 @@ import { BehaviorSubject, bufferWhen, filter, Subject } from 'rxjs';
|
||||
import { OtherFormulaMarkDirty } from '../commands/mutations/formula.mutation';
|
||||
import { FormulaResultStatus } from './formula-common';
|
||||
|
||||
export enum OtherFormulaBizType {
|
||||
DEFAULT = 'default',
|
||||
DATA_VALIDATION = 'dv',
|
||||
DATA_VALIDATION_CUSTOM = 'dv-custom',
|
||||
CONDITIONAL_FORMATTING = 'cf',
|
||||
DOC = 'doc',
|
||||
SLIDE = 'slide',
|
||||
}
|
||||
|
||||
export class RegisterOtherFormulaService extends Disposable {
|
||||
private _formulaCacheMap: Map<string, Map<string, Map<string, IOtherFormulaResult>>> = new Map();
|
||||
|
||||
@@ -72,8 +81,8 @@ export class RegisterOtherFormulaService extends Disposable {
|
||||
return subUnitMap;
|
||||
}
|
||||
|
||||
private _createFormulaId(unitId: string, subUnitId: string) {
|
||||
return `formula.${unitId}_${subUnitId}_${generateRandomId(8)}`;
|
||||
private _createFormulaId(unitId: string, subUnitId: string, bizType: OtherFormulaBizType, bizId: string) {
|
||||
return `formula.${unitId}_${subUnitId}_${bizType}_${bizId}_${generateRandomId(8)}`;
|
||||
}
|
||||
|
||||
private _initFormulaRegister() {
|
||||
@@ -182,8 +191,8 @@ export class RegisterOtherFormulaService extends Disposable {
|
||||
}));
|
||||
}
|
||||
|
||||
registerFormulaWithRange(unitId: string, subUnitId: string, formulaText: string, ranges: IRange[] = [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }], extra?: Record<string, any>) {
|
||||
const formulaId = this._createFormulaId(unitId, subUnitId);
|
||||
registerFormulaWithRange(unitId: string, subUnitId: string, formulaText: string, ranges: IRange[] = [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }], extra?: Record<string, any>, bizType: OtherFormulaBizType = OtherFormulaBizType.DEFAULT, bizId: string = '') {
|
||||
const formulaId = this._createFormulaId(unitId, subUnitId, bizType, bizId);
|
||||
const cacheMap = this._ensureCacheMap(unitId, subUnitId);
|
||||
|
||||
cacheMap.set(formulaId, {
|
||||
|
||||
Reference in New Issue
Block a user