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
fix(sheet): cell custom supports updating from mutation (#2058)
Dushusirbec1944bd4d8
diff --git a/packages/core/src/types/interfaces/i-cell-data.ts b/packages/core/src/types/interfaces/i-cell-data.tsindex f1937d8223..34f987890c 100644--- a/packages/core/src/types/interfaces/i-cell-data.ts+++ b/packages/core/src/types/interfaces/i-cell-data.ts@@ -60,7 +60,7 @@ export interface ICellData {/*** User stored custom fields*/- custom?: { [key: string]: any };+ custom?: Nullable<Record<string, any>>;}export interface ICellMarksStyle {diff --git a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.tsindex b440b38df5..8e73c21966 100644--- a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts@@ -170,6 +170,51 @@ describe('Test set range values commands', () => {expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();});+ it('will set range values when there is a selected range, includes custom property', async () => {+ function getParams() {+ const params: ISetRangeValuesCommandParams = {+ value: {+ v: 'a1',+ custom: {+ id: 1,+ },+ },+ };++ return params;+ }++ function getResultParams() {+ const params: ISetRangeValuesCommandParams = {+ value: {+ v: 'a1',+ t: CellValueType.STRING,+ custom: {+ id: 1,+ },+ },+ };++ return params;+ }++ expect(await commandService.executeCommand(SetRangeValuesCommand.id, getParams())).toBeTruthy();+ expect(getValue()).toStrictEqual(getResultParams().value);+ // undo+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();+ expect(getValue()).toStrictEqual({+ v: 'A1',+ t: CellValueType.STRING,+ });++ // redo+ expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();+ expect(getValue()).toStrictEqual(getResultParams().value);++ // reset+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();+ });+it('will tile all values when there is a selected range', async () => {function getParams() {const params: ISetRangeValuesCommandParams = {diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.tsindex 45572d1a4d..7d3de1328e 100644--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts@@ -138,6 +138,10 @@ function setNull(value: Nullable<ICellData>) {value.s = null;}+ if (value.custom === undefined) {+ value.custom = null;+ }+return value;}@@ -239,6 +243,10 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, bo}}+ if (newVal.custom !== undefined) {+ oldVal.custom = newVal.custom;+ }+cellMatrix.setValue(row, col, Tools.removeNull(oldVal));}});@@ -349,7 +357,7 @@ export function transformNormalKey(if (!newStyle || !Object.keys(newStyle).length) {return oldStyle;}- const backupStyle: { [key: string]: any } = oldStyle || {};+ const backupStyle: Record<string, any> = oldStyle || {};for (const k in newStyle) {if (k === 'bd') {@@ -402,7 +410,7 @@ export function mergeStyle(// don't operateif (newStyle === undefined) return oldStyle;- const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};+ const backupStyle: Record<string, any> = Tools.deepClone(oldStyle) || {};if (!backupStyle) return;for (const k in newStyle) {if (isRichText && ['bd', 'tr', 'td', 'ht', 'vt', 'tb', 'pd'].includes(k)) {