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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(formula): add custom data to value objects (#4658)
jcalem2e59a6c7824e
diff --git a/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.ts b/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.tsindex 0b9523ed4d..2d05b15514 100644--- a/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.ts+++ b/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.ts@@ -14,18 +14,18 @@* limitations under the License.*/-import { describe, expect, it } from 'vitest';-import { cellToRange, CellValueType } from '@univerjs/core';-import { convertTonNumber, isSingleValueObject, objectValueToCellValue } from '../value-object';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../value-object/primitive-object';-import { ErrorValueObject } from '../../value-object/base-value-object';++import { describe, expect, it } from 'vitest';import { ErrorType } from '../../../basics/error-type';-import { ArrayValueObject } from '../../value-object/array-value-object';import { CellReferenceObject } from '../../reference-object/cell-reference-object';-import { RowReferenceObject } from '../../reference-object/row-reference-object';import { ColumnReferenceObject } from '../../reference-object/column-reference-object';import { RangeReferenceObject } from '../../reference-object/range-reference-object';+import { RowReferenceObject } from '../../reference-object/row-reference-object';+import { ArrayValueObject } from '../../value-object/array-value-object';+import { ErrorValueObject } from '../../value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../value-object/primitive-object';+import { convertTonNumber, isSingleValueObject, objectValueToCellValue } from '../value-object';describe('Test object cover', () => {it('Function convertTonNumber', () => {@@ -65,5 +65,6 @@ describe('Test object cover', () => {expect(objectValueToCellValue(NullValueObject.create())).toStrictEqual({ v: null });expect(objectValueToCellValue(null)).toStrictEqual({ v: null });expect(objectValueToCellValue(ErrorValueObject.create(ErrorType.VALUE))).toStrictEqual({ v: ErrorType.VALUE, t: CellValueType.STRING });+ expect(objectValueToCellValue(StringValueObject.create('0').withCustomData({ test: 'abc' }))).toStrictEqual({ v: '0', t: CellValueType.STRING, custom: { test: 'abc' } });});});diff --git a/packages/engine-formula/src/engine/utils/value-object.ts b/packages/engine-formula/src/engine/utils/value-object.tsindex 843432cd8b..d187cbc044 100644--- a/packages/engine-formula/src/engine/utils/value-object.ts+++ b/packages/engine-formula/src/engine/utils/value-object.ts@@ -71,6 +71,7 @@ export function isSingleValueObject(valueObject: FunctionVariantType) {export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>): ICellData | undefined {const pattern = objectValue?.getPattern();let cellWithStyle: ICellData = {};+ let cellWithCustomData: ICellData = {};if (pattern) {cellWithStyle = {@@ -82,6 +83,12 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):};}+ if (objectValue?.getCustomData()) {+ cellWithCustomData = {+ custom: objectValue.getCustomData(),+ };+ }+if (objectValue == null) {return {v: null,@@ -93,6 +100,7 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):v: (objectValue as ErrorValueObject).getErrorType() as string,t: CellValueType.STRING,...cellWithStyle,+ ...cellWithCustomData,};}if (objectValue.isValueObject()) {@@ -103,6 +111,7 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):v,t: CellValueType.NUMBER,...cellWithStyle,+ ...cellWithCustomData,};}if (vo.isBoolean()) {@@ -110,6 +119,7 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):v: v ? 1 : 0,t: CellValueType.BOOLEAN,...cellWithStyle,+ ...cellWithCustomData,};}// String "00"@@ -119,6 +129,7 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):v,t: CellValueType.STRING,...cellWithStyle,+ ...cellWithCustomData,};}@@ -126,6 +137,7 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):return {v: null,...cellWithStyle,+ ...cellWithCustomData,};}@@ -133,6 +145,7 @@ export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>):v,t: CellValueType.STRING,...cellWithStyle,+ ...cellWithCustomData,};}}diff --git a/packages/engine-formula/src/engine/value-object/base-value-object.ts b/packages/engine-formula/src/engine/value-object/base-value-object.tsindex 3525c12618..2284db6c6d 100644--- a/packages/engine-formula/src/engine/value-object/base-value-object.ts+++ b/packages/engine-formula/src/engine/value-object/base-value-object.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Nullable } from '@univerjs/core';+import type { CustomData, Nullable } from '@univerjs/core';import { FormulaAstLRU } from '../../basics/cache-lru';import { ConcatenateType } from '../../basics/common';import { ErrorType } from '../../basics/error-type';@@ -33,6 +33,8 @@ export interface IArrayValueObject {column: number;}export class BaseValueObject extends ObjectClassType {+ private _customData: CustomData;+constructor(private _rawValue: string | number | boolean) {super();}@@ -72,6 +74,15 @@ export class BaseValueObject extends ObjectClassType {/** abstract */}+ withCustomData(data: CustomData) {+ this._customData = data;+ return this;+ }++ getCustomData() {+ return this._customData;+ }+isCube() {return false;}