Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export const listItemMetadataApplier: MetadataApplier<
> = {
metadataDefinition: ListMetadataDefinition,
applierFunction: (metadata, format, context) => {
const depth = context.listFormat.nodeStack.length - 2; // Minus two for the parent element and convert length to index
const depth = context.listFormat.currentLevel;

if (depth >= 0) {
const listType = context.listFormat.nodeStack[depth + 1].listType ?? 'OL';
const listType = context.listFormat.nodeStack[depth + 1]?.listType ?? 'OL';
const listStyleType = getAutoListStyleType(listType, metadata ?? {}, depth);

if (listStyleType !== undefined) {
Expand All @@ -77,10 +77,10 @@ export const listLevelMetadataApplier: MetadataApplier<
> = {
metadataDefinition: ListMetadataDefinition,
applierFunction: (metadata, format, context) => {
const depth = context.listFormat.nodeStack.length - 2; // Minus two for the parent element and convert length to index
const depth = context.listFormat.currentLevel;

if (depth >= 0) {
const listType = context.listFormat.nodeStack[depth + 1].listType ?? 'OL';
const listType = context.listFormat.nodeStack[depth + 1]?.listType ?? 'OL';
const listStyleType = getAutoListStyleType(listType, metadata ?? {}, depth);

if (listStyleType !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('listItemMetadataApplier', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -61,6 +62,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down Expand Up @@ -100,6 +102,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down Expand Up @@ -138,6 +141,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: '"(2) "',
Expand Down Expand Up @@ -177,6 +181,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down Expand Up @@ -216,6 +221,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down Expand Up @@ -255,6 +261,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: 'test',
Expand Down Expand Up @@ -296,6 +303,7 @@ describe('listItemMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: '"➢ "',
Expand All @@ -318,8 +326,14 @@ describe('listItemMetadataApplier', () => {
listType: 'OL',
refNode: null,
},
{
node: {} as Node,
listType: 'OL',
refNode: null,
},
];
context.listFormat.threadItemCounts = [2, 3, 4];
context.listFormat.currentLevel = 1;

listItemMetadataApplier.applierFunction(
{
Expand Down Expand Up @@ -347,7 +361,13 @@ describe('listItemMetadataApplier', () => {
listType: 'OL',
refNode: null,
},
{
node: {} as Node,
listType: 'OL',
refNode: null,
},
],
currentLevel: 1,
});
expect(format).toEqual({
listStyleType: '"(3) "',
Expand Down Expand Up @@ -547,6 +567,7 @@ describe('listLevelMetadataApplier', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -583,6 +604,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: 'lower-roman',
Expand Down Expand Up @@ -624,6 +646,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: 'lower-roman',
Expand Down Expand Up @@ -664,6 +687,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down Expand Up @@ -701,6 +725,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: 'decimal',
Expand Down Expand Up @@ -742,6 +767,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: 'decimal',
Expand Down Expand Up @@ -783,6 +809,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({
listStyleType: 'test',
Expand Down Expand Up @@ -824,6 +851,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down Expand Up @@ -874,6 +902,7 @@ describe('listLevelMetadataApplier', () => {
refNode: null,
},
],
currentLevel: 0,
});
expect(format).toEqual({});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function createModelToDomFormatContext(): ModelToDomFormatContext {
listFormat: {
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
},
implicitFormat: {},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const handleList: ContentModelBlockHandler<ContentModelListItem> = (
const stackLevel = nodeStack[layer + 1];
const itemLevel = listItem.levels[layer];

context.listFormat.currentLevel = layer;

if (
stackLevel.listType != itemLevel.listType ||
stackLevel.dataset?.editingInfo != itemLevel.dataset.editingInfo ||
Expand Down Expand Up @@ -79,6 +81,8 @@ export const handleList: ContentModelBlockHandler<ContentModelListItem> = (
let isNewlyCreated = false;
const levelRefNode = nodeStack[layer].refNode ?? null;

context.listFormat.currentLevel = layer;

if (context.allowCacheListItem && level.cachedElement) {
newList = level.cachedElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ describe('listItemThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
});
});

Expand All @@ -232,6 +233,7 @@ describe('listItemThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -267,6 +269,7 @@ describe('listItemThreadFormatHandler.parse', () => {
refNode: null,
},
],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -302,6 +305,7 @@ describe('listItemThreadFormatHandler.parse', () => {
refNode: null,
},
],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -339,6 +343,7 @@ describe('listItemThreadFormatHandler.parse', () => {
refNode: null,
},
],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -384,6 +389,7 @@ describe('listItemThreadFormatHandler.parse', () => {
refNode: null,
},
],
currentLevel: 0,
});
});

Expand Down Expand Up @@ -414,6 +420,7 @@ describe('listItemThreadFormatHandler.parse', () => {
refNode: null,
},
],
currentLevel: 0,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
});
});

Expand All @@ -205,6 +206,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [0],
nodeStack: [parent1, parent2],
currentLevel: 0,
});
});

Expand All @@ -221,6 +223,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [0],
nodeStack: [parent1, parent2],
currentLevel: 0,
});
});

Expand All @@ -238,6 +241,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [1, 2],
nodeStack: [parent1, parent2, parent3],
currentLevel: 0,
});
});

Expand All @@ -257,6 +261,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [1, 3],
nodeStack: [parent1, parent2, parent3],
currentLevel: 0,
});
});

Expand All @@ -273,6 +278,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [1],
nodeStack: [parent],
currentLevel: 0,
});
});

Expand All @@ -290,6 +296,7 @@ describe('listLevelThreadFormatHandler.parse', () => {
expect(context.listFormat).toEqual({
threadItemCounts: [1],
nodeStack: [parent],
currentLevel: 0,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('createModelToDomContext', () => {
listFormat: {
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
},
implicitFormat: {},
modelHandlers: defaultContentModelHandlers,
Expand Down Expand Up @@ -54,6 +55,7 @@ describe('createModelToDomContext', () => {
listFormat: {
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
},
implicitFormat: {},
modelHandlers: defaultContentModelHandlers,
Expand Down Expand Up @@ -122,6 +124,7 @@ describe('createModelToDomContext', () => {
listFormat: {
threadItemCounts: [],
nodeStack: [],
currentLevel: 0,
},
implicitFormat: {},
modelHandlers: {
Expand Down
Loading
Loading