Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 1x 1x 372x 148x 296x 148x 148x 140x 148x 204x 204x 204x 204x 114x 114x 77x 37x 28x 114x 114x | import { isElementOfType } from '../../domUtils/isElementOfType';
import type { FormatHandler } from '../FormatHandler';
import type { ListThreadFormat } from 'roosterjs-content-model-types';
/**
* @internal
*/
export const listLevelThreadFormatHandler: FormatHandler<ListThreadFormat> = {
parse: (format, element, context) => {
if (isElementOfType(element, 'ol')) {
const { listFormat } = context;
const { threadItemCounts, levels } = listFormat;
const depth = levels.length;
if (
element.start == 1 ||
typeof threadItemCounts[depth] !== 'number' ||
element.start != threadItemCounts[depth] + 1
) {
format.startNumberOverride = element.start;
}
threadItemCounts[depth] = element.start - 1;
}
},
apply: (format, element, context) => {
const {
listFormat: { threadItemCounts, nodeStack },
} = context;
// The first one is always the parent of list, and minus another one to convert length to index
// This format applier needs to be executed after new list level is pushed into node stack
const depth = nodeStack.length - 2;
if (depth >= 0 && isElementOfType(element, 'ol')) {
const startNumber = format.startNumberOverride;
if (typeof startNumber === 'number') {
threadItemCounts[depth] = startNumber - 1;
} else if (typeof threadItemCounts[depth] != 'number') {
threadItemCounts[depth] = 0;
}
threadItemCounts.splice(depth + 1);
element.start = threadItemCounts[depth] + 1;
}
},
};
|