Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): transform in bullet list #3830

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/docs/data-model/preset-list-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});
10 changes: 9 additions & 1 deletion packages/core/src/docs/data-model/text-x/transform-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
}

Expand Down
Loading