How to use the roosterjs-editor-dom.findClosestElementAncestor 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-react / packages / roosterjs-react-editor / lib / components / LeanRooster.tsx View on Github external
private _getAnchorForClickOpenHyperlink(ev: React.MouseEvent, element: HTMLElement): HTMLAnchorElement {
        const { clickOpenHyperlinkViewMode, readonly } = this.props;
        const isPrimaryButton = ev.button === 0;
        if (!isPrimaryButton || !clickOpenHyperlinkViewMode || readonly || this.mode !== LeanRoosterModes.View) {
            return null;
        }

        // Hyperlink plugin will handle CTRL+Click when editor is created and FireFox will handle for contenteditable
        const ctrlOpen = Browser.isMac ? ev.metaKey : ev.ctrlKey;
        if ((this._editor && ctrlOpen) || (Browser.isFirefox && ctrlOpen)) {
            return null;
        }

        const anchor = findClosestElementAncestor(element, this._contentDiv, "a[href]");
        if (anchor) {
            return anchor as HTMLAnchorElement;
        }

        return null;
    }
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / corePlugins / TypeInContainerPlugin.ts View on Github external
private onKeyPress(event: PluginKeyboardEvent) {
        // If normalization was not possible before the keypress,
        // check again after the keyboard event has been processed by browser native behaviour.
        //
        // This handles the case where the keyboard event that first inserts content happens when
        // there is already content under the selection (e.g. Ctrl+a -> type new content).
        //
        // Only scheudle when the range is not collapsed to catch this edge case.
        let range = this.editor.getSelectionRange();

        if (!range || this.editor.contains(findClosestElementAncestor(range.startContainer))) {
            return;
        }

        if (range.collapsed) {
            this.tryNormalizeTyping(event, range);
        } else if (!range.collapsed) {
            this.editor.runAsync(() => {
                this.tryNormalizeTyping(event);
            });
        }
    }
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / toggleHeader.ts View on Github external
editor.getDocument().execCommand(DocumentCommand.FormatBlock, false, '<div>');
                wrapped = true;
            }

            let div = editor.getDocument().createElement('div');
            while (header.firstChild) {
                div.appendChild(header.firstChild);
            }
            editor.replaceNode(header, div);
        });

        if (level &gt; 0) {
            let traverser = editor.getSelectionTraverser();
            let inlineElement = traverser ? traverser.currentInlineElement : null;
            while (inlineElement) {
                let element = findClosestElementAncestor(inlineElement.getContainerNode());
                if (element) {
                    element.style.fontSize = '';
                }
                inlineElement = traverser.getNextInlineElement();
            }
            editor.getDocument().execCommand(DocumentCommand.FormatBlock, false, ``);
        }
    }, ChangeSource.Format);
}
</div>