How to use the roosterjs-editor-dom.getTagOfNode function in roosterjs-editor-dom

To help you get started, we’ve selected a few roosterjs-editor-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / clearBlockFormat.ts View on Github external
return false;
    }

    // 1. Recursively clear format of all its child nodes
    let allChildrenAreBlock = ([].slice.call(node.childNodes) as Node[])
        .map(n => clearNodeFormat(n, tagsToUnwrap, tagsToStopUnwrap, attributesToPreserve))
        .reduce((previousValue, value) => previousValue && value, true);

    if (!canCollapse(tagsToStopUnwrap, node)) {
        return false;
    }

    let returnBlockElement = isBlockElement(node);

    // 2. If we should unwrap this tag, put it into an array and unwrap it later
    if (tagsToUnwrap.indexOf(getTagOfNode(node)) >= 0 || allChildrenAreBlock) {
        if (returnBlockElement && !allChildrenAreBlock) {
            wrap(node);
        }
        unwrap(node);
    } else {
        // 3. Otherwise, remove all attributes
        clearAttribute(node as HTMLElement, attributesToPreserve);
    }

    return returnBlockElement;
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / insertLineBeforeStructuredNodeFeature.ts View on Github external
editor.addUndoSnapshot(() => {
            element.parentNode.insertBefore(div, element);
            // Select the new line when we are in table. This is the same behavior with Word
            if (getTagOfNode(element) == 'TABLE') {
                editor.select(new Position(div, PositionType.Begin).normalize());
            }
        });
        event.rawEvent.preventDefault();
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / insertLineBeforeStructuredNodeFeature.ts View on Github external
return cacheGetEventData(event, 'FIRST_STRUCTURE', () => {
        // Provide a chance to keep browser default behavior by pressing SHIFT
        let element = event.rawEvent.shiftKey ? null : editor.getElementAtCursor(CHILD_SELECTOR);

        if (element) {
            let range = editor.getSelectionRange();
            if (
                range &&
                range.collapsed &&
                isPositionAtBeginningOf(Position.getStart(range), element) &&
                !editor.getBodyTraverser(element).getPreviousBlockElement()
            ) {
                return editor.getElementAtCursor(CHILD_PARENT_TAG_MAP[getTagOfNode(element)]);
            }
        }

        return null;
    });
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / Paste / officeOnlineConverter / convertPastedContentFromWordOnline.ts View on Github external
function getContainerListType(listItemContainer: Element): 'OL' | 'UL' | null {
    const tag = getTagOfNode(listItemContainer.firstChild);
    return tag == UNORDERED_LIST_TAG_NAME || tag == ORDERED_LIST_TAG_NAME ? tag : null;
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / listFeatures.ts View on Github external
function cacheGetListElement(event: PluginKeyboardEvent, editor: Editor) {
    let li = cacheGetElementAtCursor(editor, event, 'LI,TABLE');
    let listElement = li && getTagOfNode(li) == 'LI' && editor.getElementAtCursor('UL,OL', li);
    return listElement ? [listElement, li] : null;
}
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / clearBlockFormat.ts View on Github external
function canCollapse(tagsToStopUnwrap: string[], node: Node) {
    return tagsToStopUnwrap.indexOf(getTagOfNode(node)) < 0;
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / Paste / officeOnlineConverter / convertPastedContentFromWordOnline.ts View on Github external
collapsedListItemSections.forEach((section) => {
        if (getTagOfNode(section.firstChild) == 'DIV') {
            unwrap(section)
        }
    })
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / listFeatures.ts View on Github external
function toggleListAndPreventDefault(event: PluginKeyboardEvent, editor: Editor) {
    let listInfo = cacheGetListElement(event, editor);
    if (listInfo) {
        let listElement = listInfo[0];
        let tag = getTagOfNode(listElement);
        if (tag == 'UL') {
            toggleBullet(editor);
        } else if (tag == 'OL') {
            toggleNumbering(editor);
        }
        editor.focus();
        event.rawEvent.preventDefault();
    }
}
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / toggleCodeBlock.ts View on Github external
function unwrapFunction(node: HTMLElement): Node {
    if (!node) {
        return null;
    }

    let firstChild = node.childNodes[0];
    if (node.childNodes.length == 1 && getTagOfNode(firstChild) == CODE_NODE_TAG) {
        unwrap(firstChild);
    }

    return unwrap(node);
}
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / getFormatState.ts View on Github external
export function getElementBasedFormatState(
    editor: Editor,
    event?: PluginEvent
): ElementBasedFormatState {
    let listTag = getTagOfNode(cacheGetElementAtCursor(editor, event, 'OL,UL'));
    let headerTag = getTagOfNode(cacheGetElementAtCursor(editor, event, 'H1,H2,H3,H4,H5,H6'));

    return {
        isBullet: listTag == 'UL',
        isNumbering: listTag == 'OL',
        headerLevel: (headerTag && parseInt(headerTag[1])) || 0,

        canUnlink: !!editor.queryElements('a[href]', QueryScope.OnSelection)[0],
        canAddImageAltText: !!editor.queryElements('img', QueryScope.OnSelection)[0],
        isBlockQuote: !!editor.queryElements('blockquote', QueryScope.OnSelection)[0],
    };
}