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(docs): transform in bullet list (#3830)
Ran Luo7451d2d491ad
diff --git a/packages/core/src/docs/data-model/preset-list-type.ts b/packages/core/src/docs/data-model/preset-list-type.tsindex ea00878123..aaf6393b2e 100644--- a/packages/core/src/docs/data-model/preset-list-type.ts+++ b/packages/core/src/docs/data-model/preset-list-type.ts@@ -14,10 +14,10 @@* limitations under the License.*/+import type { IListData, INestingLevel, ITextStyle } from '../../types/interfaces/i-document-data';import { Tools } from '../../shared';import { BooleanNumber } from '../../types/enum';import { BulletAlignment, GlyphType } from '../../types/interfaces/i-document-data';-import type { IListData, INestingLevel, ITextStyle } from '../../types/interfaces/i-document-data';export enum QuickListType {ORDER_LIST_QUICK_1 = '1.',diff --git a/packages/core/src/docs/data-model/text-x/__tests__/apply.spec.ts b/packages/core/src/docs/data-model/text-x/__tests__/apply.spec.tsindex 0d23e0b3d6..d87c0073f5 100644--- a/packages/core/src/docs/data-model/text-x/__tests__/apply.spec.ts+++ b/packages/core/src/docs/data-model/text-x/__tests__/apply.spec.ts@@ -19,6 +19,7 @@ import type { TextXAction } from '../action-types';import { describe, expect, it } from 'vitest';import { UpdateDocsAttributeType } from '../../../../shared';import { BooleanNumber, HorizontalAlign } from '../../../../types/enum';+import { PresetListType } from '../../preset-list-type';import { TextXActionType } from '../action-types';import { TextX } from '../text-x';@@ -255,13 +256,6 @@ describe('apply method', () => {const resultC = TextX.apply(doc3, composedAction1);const resultD = TextX.apply(doc4, composedAction2);- // console.log(JSON.stringify(resultA, null, 2));- // console.log(JSON.stringify(resultB, null, 2));-- // console.log('composedAction1', JSON.stringify(composedAction1, null, 2));-- // console.log(JSON.stringify(resultC, null, 2));-expect(resultA).toEqual(resultB);expect(resultC).toEqual(resultD);expect(resultA).toEqual(resultC);@@ -402,4 +396,86 @@ describe('apply method', () => {expect(resultA).toEqual(resultC);expect(composedAction1).toEqual(composedAction2);});++ it('should get the same result when set different list style with REPLACE cover type at 2 clients', () => {+ const actionsA: TextXAction[] = [+ {+ t: TextXActionType.RETAIN,+ len: 1,+ segmentId: '',+ }, {+ t: TextXActionType.RETAIN,+ len: 1,+ segmentId: '',+ coverType: UpdateDocsAttributeType.REPLACE,+ body: {+ dataStream: '',+ paragraphs: [{+ startIndex: 0,+ bullet: {+ listId: 'J7FZTm',+ listType: PresetListType.CHECK_LIST,+ nestingLevel: 0,+ textStyle: {+ fs: 20,+ },+ },+ }],+ },+ },+ ];++ const actionsB: TextXAction[] = [+ {+ t: TextXActionType.RETAIN,+ len: 1,+ segmentId: '',+ }, {+ t: TextXActionType.RETAIN,+ len: 1,+ segmentId: '',+ coverType: UpdateDocsAttributeType.REPLACE,+ body: {+ dataStream: '',+ paragraphs: [{+ startIndex: 0,+ bullet: {+ listId: 'uODEbf',+ listType: PresetListType.BULLET_LIST,+ nestingLevel: 0,+ textStyle: {+ fs: 20,+ },+ },+ }],+ },+ },+ ];++ const doc1 = getDefaultDocWithParagraph();+ const doc2 = getDefaultDocWithParagraph();+ const doc3 = getDefaultDocWithParagraph();+ const doc4 = getDefaultDocWithParagraph();++ const resultA = TextX.apply(TextX.apply(doc1, actionsA), TextX.transform(actionsB, actionsA, 'left'));+ const resultB = TextX.apply(TextX.apply(doc2, actionsB), TextX.transform(actionsA, actionsB, 'right'));++ const composedAction1 = TextX.compose(actionsA, TextX.transform(actionsB, actionsA, 'left'));+ const composedAction2 = TextX.compose(actionsB, TextX.transform(actionsA, actionsB, 'right'));++ const resultC = TextX.apply(doc3, composedAction1);+ const resultD = TextX.apply(doc4, composedAction2);++ // console.log(JSON.stringify(resultA, null, 2));+ // console.log(JSON.stringify(resultB, null, 2));++ // console.log('composedAction1', JSON.stringify(composedAction1, null, 2));++ // console.log(JSON.stringify(resultC, null, 2));++ expect(resultA).toEqual(resultB);+ expect(resultC).toEqual(resultD);+ expect(resultA).toEqual(resultC);+ expect(composedAction1).toEqual(composedAction2);+ });});diff --git a/packages/core/src/docs/data-model/text-x/transform-utils.ts b/packages/core/src/docs/data-model/text-x/transform-utils.tsindex 915d90c102..239e632ec6 100644--- a/packages/core/src/docs/data-model/text-x/transform-utils.ts+++ b/packages/core/src/docs/data-model/text-x/transform-utils.ts@@ -189,10 +189,18 @@ function transformParagraph(}if (targetParagraph.bullet) {- if (originParagraph.bullet == null || transformType === TextXTransformType.COVER) {+ if (originParagraph.bullet == null) {paragraph.bullet = {...targetParagraph.bullet,};+ } else {+ if (coverType === UpdateDocsAttributeType.REPLACE) {+ paragraph.bullet = transformType === TextXTransformType.COVER_ONLY_NOT_EXISTED+ ? { ...originParagraph.bullet }+ : { ...targetParagraph.bullet };+ } else {+ throw new Error('Bullet is only supported in replace mode.');+ }}}