RichText/Archived/Rooster/Rooster.gcomp/Support/node_modules/roosterjs/dist/rooster-amd.js
/**
 * Handles the pass 1: Discovery
 * During discovery, we'll parse the metadata out of the elements and store it in the list items dictionary.
 * We'll detect cases where the list items for a particular ordered list are not next to each other. Word does these
 * for numbered headers, and we don't want to convert those, because the numbering would be completely wrong.
 */
Handles the pass 1: Discovery
During discovery, we'll parse the metadata out of the elements and store it in the list items dictionary.
We'll detect cases where the list items for a particular ordered list are not next to each other. Word does these
for numbered headers, and we don't want to convert those, because the numbering would be completely wrong.
Handles the pass 1 : Discovery During discovery we ' ll parse the metadata out of the elements and store it in the list items dictionary . We ' ll detect cases where the list items for a particular ordered list are not next to each other . Word does these for numbered headers and we don ' t want to convert those because the numbering would be completely wrong .
function processNodesDiscovery(wordConverter) {
    var args = wordConverter.wordConverterArgs;
    while (args.currentIndex < args.nodes.length) {
        var node = args.nodes.item(args.currentIndex);
        var itemMetadata = getListItemMetadata(node);
        if (itemMetadata) {
            var levelInfo = args.currentListIdsByLevels[itemMetadata.level - 1] || LevelLists_1.createLevelLists();
            args.currentListIdsByLevels[itemMetadata.level - 1] = levelInfo;
            if (args.lastProcessedItem && getRealPreviousSibling(node) != args.lastProcessedItem) {
                resetCurrentLists(args);
            }
            var listMetadata = levelInfo.listsMetadata[itemMetadata.wordListId];
            if (!listMetadata) {
                var firstFakeBullet = getFakeBulletText(node, LOOKUP_DEPTH);
                listMetadata = {
                    numberOfItems: 0,
                    uniqueListId: wordConverter.nextUniqueId++,
                    firstFakeBullet: firstFakeBullet,
                    ignore: !firstFakeBullet || firstFakeBullet.length == 0,
                    tagName: getFakeBulletTagName(firstFakeBullet),
                };
                levelInfo.listsMetadata[itemMetadata.wordListId] = listMetadata;
                args.lists[listMetadata.uniqueListId.toString()] = listMetadata;
            }
            else if (!listMetadata.ignore && listMetadata.numberOfItems == 1) {
                var secondFakeBullet = getFakeBulletText(node, LOOKUP_DEPTH);
                listMetadata.tagName =
                    listMetadata.firstFakeBullet == secondFakeBullet ? 'UL' : 'OL';
            }
            itemMetadata.uniqueListId = listMetadata.uniqueListId;
            if (listMetadata.ignore ||
                (listMetadata.tagName == 'OL' &&
                    listMetadata.numberOfItems > 0 &&
                    levelInfo.currentUniqueListId != itemMetadata.uniqueListId)) {
                listMetadata.ignore = true;
                args.currentListIdsByLevels[0].currentUniqueListId = -1;
                args.currentListIdsByLevels = args.currentListIdsByLevels.slice(0, 1);
            }
            else {
                if (args.currentListIdsByLevels.length > itemMetadata.level) {
                    args.currentListIdsByLevels = args.currentListIdsByLevels.slice(0, itemMetadata.level);
                }
                levelInfo.currentUniqueListId = itemMetadata.uniqueListId;
                args.listItems.push(itemMetadata);
                listMetadata.numberOfItems++;
            }
            args.lastProcessedItem = node;
        }
        else {
            var last = args.lastProcessedItem;
            if (last &&
                getRealPreviousSibling(node) == last &&
                node.tagName == last.tagName &&
                node.className == last.className) {
                last.appendChild(last.ownerDocument.createElement('br'));
                last.appendChild(last.ownerDocument.createElement('br'));
                while (node.firstChild != null) {
                    last.appendChild(node.firstChild);
                }
                node.parentNode.removeChild(node);
            }
        }
        args.currentIndex++;
    }
    return args.listItems.length > 0;
}
function processNodesDiscovery ( wordConverter ) { var args = wordConverter . wordConverterArgs ; while ( args . currentIndex < args . nodes . length ) { var node = args . nodes . item ( args . currentIndex ) ; var itemMetadata = getListItemMetadata ( node ) ; if ( itemMetadata ) { var levelInfo = args . currentListIdsByLevels [ itemMetadata . level - 1 ] || LevelLists_1 . createLevelLists ( ) ; args . currentListIdsByLevels [ itemMetadata . level - 1 ] = levelInfo ; if ( args . lastProcessedItem && getRealPreviousSibling ( node ) != args . lastProcessedItem ) { resetCurrentLists ( args ) ; } var listMetadata = levelInfo . listsMetadata [ itemMetadata . wordListId ] ; if ( ! listMetadata ) { var firstFakeBullet = getFakeBulletText ( node , LOOKUP_DEPTH ) ; listMetadata = { numberOfItems : 0 , uniqueListId : wordConverter . nextUniqueId ++ , firstFakeBullet : firstFakeBullet , ignore : ! firstFakeBullet || firstFakeBullet . length == 0 , tagName : getFakeBulletTagName ( firstFakeBullet ) , } ; levelInfo . listsMetadata [ itemMetadata . wordListId ] = listMetadata ; args . lists [ listMetadata . uniqueListId . toString ( ) ] = listMetadata ; } else if ( ! listMetadata . ignore && listMetadata . numberOfItems == 1 ) { var secondFakeBullet = getFakeBulletText ( node , LOOKUP_DEPTH ) ; listMetadata . tagName = listMetadata . firstFakeBullet == secondFakeBullet ? 'UL' : 'OL' ; } itemMetadata . uniqueListId = listMetadata . uniqueListId ; if ( listMetadata . ignore || ( listMetadata . tagName == 'OL' && listMetadata . numberOfItems > 0 && levelInfo . currentUniqueListId != itemMetadata . uniqueListId ) ) { listMetadata . ignore = true ; args . currentListIdsByLevels [ 0 ] . currentUniqueListId = - 1 ; args . currentListIdsByLevels = args . currentListIdsByLevels . slice ( 0 , 1 ) ; } else { if ( args . currentListIdsByLevels . length > itemMetadata . level ) { args . currentListIdsByLevels = args . currentListIdsByLevels . slice ( 0 , itemMetadata . level ) ; } levelInfo . currentUniqueListId = itemMetadata . uniqueListId ; args . listItems . push ( itemMetadata ) ; listMetadata . numberOfItems ++ ; } args . lastProcessedItem = node ; } else { var last = args . lastProcessedItem ; if ( last && getRealPreviousSibling ( node ) == last && node . tagName == last . tagName && node . className == last . className ) { last . appendChild ( last . ownerDocument . createElement ( 'br' ) ) ; last . appendChild ( last . ownerDocument . createElement ( 'br' ) ) ; while ( node . firstChild != null ) { last . appendChild ( node . firstChild ) ; } node . parentNode . removeChild ( node ) ; } } args . currentIndex ++ ; } return args . listItems . length > 0 ; }
Handles the pass 1: Discovery
 During discovery, we'll parse the metadata out of the elements and store it in the list items dictionary.
Handles the pass 1 : Discovery During discovery we ' ll parse the metadata out of the elements and store it in the list items dictionary .
// Try to get the list metadata for the specified node // We need to drop some list information if this is not an item next to another // This list item is not next to the previous one. This means that there is some content in between them // so we need to reset our list of list ids per level // Get the list metadata for the list that will hold this item // Get the first item fake bullet.. This will be used later to check what is the right type of list // This is a the first item of a list.. We'll create the list metadata using the information // we already have from this first item // If the bullet we got is emtpy or not found, we ignore the list out.. this means // that this is not an item we need to convert of that the format doesn't match what // we are expecting // We'll use the first fake bullet to try to figure out which type of list we create. If this list has a second // item, we'll perform a better comparasion, but for one item lists, this will be check that will determine the list type // This is the second item we've seen for this list.. we'll compare the 2 fake bullet // items we have an decide if we create ordered or unordered lists based on this. // This is the best way we can do this since we cannot read the metadata that Word // puts in the head of the HTML... // Set the unique id to the list // Check if we need to ignore this list... we'll either know already that we need to ignore // it, or we'll know it because the previous list items are not next to this one // We need to ignore this item... and we also need to forget about the lists that // are not at the root level // This is an item we don't need to ignore... If added lists deep under this one before // we'll drop their ids from the list of ids per level.. this is because this list item // breaks the deeper lists. // Add the list item into the list of items to be processed // Here, we know that this is not a list item, but we'll want to check if it is one "no bullet" list items... // these can be created by creating a bullet and hitting delete on it it... The content will continue to be indented, but there will // be no bullet and the list will continue correctly after that. Visually, it looks like the previous item has multiple lines, but // the HTML generated has multiple paragraphs with the same class. We'll merge these when we find them, so the logic doesn't skips // the list conversion thinking that the list items are not together... // Add 2 line breaks and move all the nodes to the last item // Remove the item that we don't need anymore // Move to the next element are return true if more elements need to be processed