How to use the roosterjs-editor-types.PluginEventType.ContentChanged function in roosterjs-editor-types

To help you get started, we’ve selected a few roosterjs-editor-types 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-plugin-picker / lib / PickerPlugin.ts View on Github external
public onPluginEvent(event: PluginEvent) {
        switch (event.eventType) {
            case PluginEventType.ContentChanged:
                if (event.source == ChangeSource.SetContent && this.dataProvider.onContentChanged) {
                    // Stop suggesting since content is fully changed
                    if (this.isSuggesting) {
                        this.setIsSuggesting(false);
                    }

                    // Undos and other major changes to document content fire this type of event.
                    // Inform the data provider of the current picker placed elements in the body.
                    let elementIds: string[] = [];
                    this.editor.queryElements(
                        "[id^='" + this.pickerOptions.elementIdPrefix + "']",
                        element => {
                            if (element.id) {
                                elementIds.push(element.id);
                            }
                        }
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / ContentEdit / features / autoLinkFeatures.ts View on Github external
? 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;
              }

              let word = searcher &amp;&amp; searcher.getWordBefore();
              if (word &amp;&amp; word.length &gt; MINIMUM_LENGTH) {
                  // Check for trailing punctuation
                  let trailingPunctuations = word.match(TRAILING_PUNCTUATION_REGEX);
                  let trailingPunctuation = (trailingPunctuations || [])[0] || '';
</a>
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / PasteManager / PasteManager.ts View on Github external
private onPasteComplete = (clipboardData: ClipboardData) => {
        let pasteHandler = this.pasteHandler || this.defaultPasteHandler;
        if (clipboardData) {
            // if any clipboard data exists, call into pasteHandler
            pasteHandler(clipboardData);
        }

        // add undo snapshot after paste
        // broadcast contentChangedEvent to ensure the snapshot actually gets added
        let contentChangedEvent: PluginEvent = { eventType: PluginEventType.ContentChanged };
        this.editor.triggerEvent(contentChangedEvent, true /* broadcast */);
        this.editor.addUndoSnapshot();
    };
github microsoft / roosterjs-react / sample / script / FocusOutShellSample.tsx View on Github external
public onPluginEvent(event: PluginEvent): void {
        if (event && event.eventType === PluginEventType.ContentChanged) {
            console.log(`Content changed from ${(event as any).source}`);
        }
    }
}
github microsoft / roosterjs / packages / roosterjs-editor-plugins / lib / Watermark / Watermark.ts View on Github external
onPluginEvent(event: PluginEvent) {
        if (
            event.eventType == PluginEventType.Focus ||
            event.eventType == PluginEventType.Blur ||
            event.eventType == PluginEventType.ContentChanged
        ) {
            this.showHideWatermark();
        } else if (event.eventType == PluginEventType.ExtractContent && this.isWatermarkShowing) {
            this.removeWartermarkFromHtml(event as ExtractContentEvent);
        }
    }
github microsoft / roosterjs-react / packages / roosterjs-react-command-bar / lib / plugins / RoosterCommandBarPlugin.ts View on Github external
import { Editor, EditorPlugin, browserData } from 'roosterjs-editor-core';
import { PluginEvent, PluginEventType, PluginDomEvent } from 'roosterjs-editor-types';
import { DefaultShortcut } from 'roosterjs-editor-plugins';
import { KeyCodes } from 'office-ui-fabric-react/lib/Utilities';
import { createLinkWithPrompt } from 'roosterjs-react-common';

import RoosterCommandBar from '../components/RoosterCommandBar';
import RoosterCommandBarPluginInterface from '../schema/RoosterCommandBarPluginInterface';

export default class RoosterCommandBarPlugin implements EditorPlugin, RoosterCommandBarPluginInterface {
    private static readonly EventTypesToHandle: { [eventType: number]: boolean } = {
        [PluginEventType.KeyUp]: true,
        [PluginEventType.MouseDown]: true,
        [PluginEventType.MouseUp]: true,
        [PluginEventType.ContentChanged]: true
    };

    private editor: Editor;
    private commandBars: RoosterCommandBar[] = [];
    private defaultShortcut: DefaultShortcut = new DefaultShortcut();
    private strings: { [key: string]: string };

    constructor(strings?: { [key: string]: string }) {
        this.strings = strings;
    }

    public initialize(editor: Editor): void {
        this.defaultShortcut.initialize(editor);
        this.editor = editor;
    }
github microsoft / roosterjs / publish / samplesite / scripts / controls / sidePane / formatState / FormatStatePlugin.ts View on Github external
onPluginEvent(event: PluginEvent) {
        if (
            event.eventType == PluginEventType.KeyUp ||
            event.eventType == PluginEventType.MouseUp ||
            event.eventType == PluginEventType.ContentChanged
        ) {
            this.updateFormatState();
        }
    }
github microsoft / roosterjs / packages / roosterjs-plugin-react / lib / ReactPlugin.tsx View on Github external
private isTriggeringEvent(event: PluginEvent): boolean {
        if (event.eventType === PluginEventType.EditorReady) {
            return true;
        } else if (
            event.eventType == PluginEventType.ContentChanged &&
            legalChangeSources.has(event.source)
        ) {
            return true;
        }
        return false;
    }
}
github microsoft / roosterjs / publish / samplesite / scripts / controls / sidePane / apiPlayground / blockElements / BlockElementsPane.tsx View on Github external
onPluginEvent(e: PluginEvent) {
        if (
            e.eventType == PluginEventType.KeyPress ||
            e.eventType == PluginEventType.ContentChanged
        ) {
            if (this.checkGetBlocks.current.checked) {
                this.update();
            } else {
                this.setBlocks([]);
            }
        }
    }
github microsoft / roosterjs-react / packages / roosterjs-react-common / lib / plugins / ContentChangedPlugin.ts View on Github external
public onPluginEvent(event: PluginEvent): void {
        if (event && event.eventType === PluginEventType.ContentChanged) {
            this.onChangeEvent();
        }
    }