How to use the roosterjs-editor-core.cacheGetEventData function in roosterjs-editor-core

To help you get started, we’ve selected a few roosterjs-editor-core 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-plugins / lib / ContentEdit / features / insertLineBeforeStructuredNodeFeature.ts View on Github external
function cacheGetStructuredElement(event: PluginKeyboardEvent, editor: Editor) {
    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 / ContentEdit / features / shortcutFeatures.ts View on Github external
function cacheGetCommand(event: PluginKeyboardEvent) {
    return cacheGetEventData(event, 'DEFAULT_SHORT_COMMAND', () => {
        let e = event.rawEvent;
        let key =
            // Need to check ALT key to be false since in some language (e.g. Polski) uses AltGr to input some special charactors
            // In that case, ctrlKey and altKey are both true in Edge, but we should not trigger any shortcut function here
            event.eventType == PluginEventType.KeyDown && !e.altKey
                ? e.which |
                  (e.metaKey && Keys.Meta) |
                  (e.shiftKey && Keys.Shift) |
                  (e.ctrlKey && Keys.Ctrl)
                : 0;
        return key && commands.filter(cmd => (Browser.isMac ? cmd.macKey : cmd.winKey) == key)[0];
    });
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / autoLinkFeatures.ts View on Github external
function cacheGetLinkData(event: PluginEvent, editor: Editor): LinkData {
    return event.eventType == PluginEventType.KeyDown ||
        (event.eventType == PluginEventType.ContentChanged && event.source == ChangeSource.Paste)
        ? cacheGetEventData(event, 'LINK_DATA', () => {
              // First try to match link from the whole paste string from the plain text in clipboard.
              // This helps when we paste a link next to some existing character, and the text we got
              // from clipboard will only contain what we pasted, any existing characters will not
              // be included.
              let clipboardData =
                  event.eventType == PluginEventType.ContentChanged &&
                  event.source == ChangeSource.Paste &&
                  (event.data as ClipboardData);
              let link = matchLink((clipboardData.text || '').trim());
              let searcher = cacheGetContentSearcher(event, editor);

              // In case the matched link is already inside a <a> tag, we do a range search.
              // getRangeFromText will return null if the given text is already in a LinkInlineElement
              if (link &amp;&amp; searcher.getRangeFromText(link.originalUrl, false /*exactMatch*/)) {
                  return link;
              }
</a>
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / cacheGetHeaderLevel.ts View on Github external
export default function cacheGetHeaderLevel(editor: Editor, event?: PluginEvent): number {
    return cacheGetEventData(event, EVENTDATACACHE_HEADER_LEVEL, () =&gt; {
        for (let i = 1; i &lt;= 6; i++) {
            if (queryNodesWithSelection(editor, 'H' + i).length &gt; 0) {
                return i;
            }
        }
        return 0;
    });
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / tableFeatures.ts View on Github external
function cacheGetTableCell(event: PluginEvent, editor: Editor): HTMLTableCellElement {
    return cacheGetEventData(event, 'TABLECELL_FOR_TABLE_FEATURES', () => {
        let pos = editor.getFocusedPosition();
        let firstTd = editor.getElementAtCursor('TD,TH,LI', pos.node);
        return getTagOfNode(firstTd) == 'LI' ? null : (firstTd as HTMLTableCellElement);
    });
}
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / deprecated / getNodeAtCursor.ts View on Github external
export function cacheGetNodeAtCursor(
    editor: Editor,
    event: PluginEvent,
    expectedTags?: string | string[]
): HTMLElement {
    let selector = expectedTags instanceof Array ? expectedTags.join(',') : expectedTags;
    return cacheGetEventData(event, 'GET_NODE_AT_CURSOR_' + selector, () =>
        getNodeAtCursor(editor, expectedTags)
    );
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / quoteFeatures.ts View on Github external
function cacheGetQuoteChild(event: PluginKeyboardEvent, editor: Editor): Node {
    return cacheGetEventData(event, 'QUOTE_CHILD', () => {
        let quote = editor.getElementAtCursor(STRUCTURED_TAGS);
        if (quote && getTagOfNode(quote) == QUOTE_TAG) {
            let pos = editor.getFocusedPosition();
            let block = pos && editor.getBlockElementAtNode(pos.normalize().node);
            if (block) {
                let node =
                    block.getStartNode() == quote
                        ? block.getStartNode()
                        : block.collapseToSingleElement();
                return isNodeEmpty(node) ? node : null;
            }
        }

        return null;
    });
}
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / deprecated / CursorData.ts View on Github external
export function cacheGetCursorEventData(event: PluginEvent, editor: Editor): CursorData {
    return cacheGetEventData(
        event,
        EVENTDATACACHE_CURSORDATA,
        () =&gt; new CursorData(editor)
    );
}