@atlaskit/editor-plugin-find-replace
Version:
find replace plugin for @atlaskit/editor-core
74 lines • 2.55 kB
JavaScript
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
import { activate, cancelSearch, find, findNext, findPrevious, replace, replaceAll } from './commands';
export const activateWithAnalytics = editorAnalyticsAPI => ({
triggerMethod
}) => withAnalytics(editorAnalyticsAPI, state => ({
eventType: EVENT_TYPE.UI,
action: ACTION.ACTIVATED,
actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG,
attributes: {
inputMethod: state.selection instanceof TextSelection && !state.selection.empty ? INPUT_METHOD.PREFILL : INPUT_METHOD.KEYBOARD,
triggerMethod
}
}))(activate());
export const findWithAnalytics = editorAnalyticsAPI => ({
editorView,
containerElement,
keyword
}) => withAnalytics(editorAnalyticsAPI, {
eventType: EVENT_TYPE.TRACK,
action: ACTION.FIND_PERFORMED,
actionSubject: ACTION_SUBJECT.TEXT
})(find(editorView, containerElement, keyword));
export const findNextWithAnalytics = (editorAnalyticsAPI, editorView) => ({
triggerMethod
}) => {
return withAnalytics(editorAnalyticsAPI, {
eventType: EVENT_TYPE.TRACK,
action: ACTION.FIND_NEXT_PERFORMED,
actionSubject: ACTION_SUBJECT.TEXT,
attributes: {
triggerMethod
}
})(findNext(editorView));
};
export const findPrevWithAnalytics = (editorAnalyticsAPI, editorView) => ({
triggerMethod
}) => withAnalytics(editorAnalyticsAPI, {
eventType: EVENT_TYPE.TRACK,
action: ACTION.FIND_PREV_PERFORMED,
actionSubject: ACTION_SUBJECT.TEXT,
attributes: {
triggerMethod
}
})(findPrevious(editorView));
export const replaceWithAnalytics = editorAnalyticsAPI => ({
triggerMethod,
replaceText
}) => withAnalytics(editorAnalyticsAPI, {
eventType: EVENT_TYPE.TRACK,
action: ACTION.REPLACED_ONE,
actionSubject: ACTION_SUBJECT.TEXT,
attributes: {
triggerMethod
}
})(replace(replaceText));
export const replaceAllWithAnalytics = editorAnalyticsAPI => ({
replaceText
}) => withAnalytics(editorAnalyticsAPI, {
eventType: EVENT_TYPE.TRACK,
action: ACTION.REPLACED_ALL,
actionSubject: ACTION_SUBJECT.TEXT
})(replaceAll(replaceText));
export const cancelSearchWithAnalytics = editorAnalyticsAPI => ({
triggerMethod
}) => withAnalytics(editorAnalyticsAPI, {
eventType: EVENT_TYPE.UI,
action: ACTION.DEACTIVATED,
actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG,
attributes: {
triggerMethod
}
})(cancelSearch());