Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
}
? 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 && searcher.getRangeFromText(link.originalUrl, false /*exactMatch*/)) {
return link;
}
let word = searcher && searcher.getWordBefore();
if (word && word.length > MINIMUM_LENGTH) {
// Check for trailing punctuation
let trailingPunctuations = word.match(TRAILING_PUNCTUATION_REGEX);
let trailingPunctuation = (trailingPunctuations || [])[0] || '';
</a>
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();
};
public onPluginEvent(event: PluginEvent): void {
if (event && event.eventType === PluginEventType.ContentChanged) {
console.log(`Content changed from ${(event as any).source}`);
}
}
}
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);
}
}
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;
}
onPluginEvent(event: PluginEvent) {
if (
event.eventType == PluginEventType.KeyUp ||
event.eventType == PluginEventType.MouseUp ||
event.eventType == PluginEventType.ContentChanged
) {
this.updateFormatState();
}
}
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;
}
}
onPluginEvent(e: PluginEvent) {
if (
e.eventType == PluginEventType.KeyPress ||
e.eventType == PluginEventType.ContentChanged
) {
if (this.checkGetBlocks.current.checked) {
this.update();
} else {
this.setBlocks([]);
}
}
}
public onPluginEvent(event: PluginEvent): void {
if (event && event.eventType === PluginEventType.ContentChanged) {
this.onChangeEvent();
}
}