UNPKG

@atlaskit/editor-plugin-find-replace

Version:

find replace plugin for @atlaskit/editor-core

103 lines (101 loc) • 4.13 kB
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics/types/enums'; import { withAnalytics } from '@atlaskit/editor-common/withAnalytics'; import { TextSelection } from '@atlaskit/editor-prosemirror/state'; import { activate, cancelSearch, find, findNext, findPrevious, replace, replaceAll } from './commands'; /** * Hosts that do not install `editorViewMode` are always editing, so the attribute * falls back to `edit` when the api is absent. */ export var activateWithAnalytics = function activateWithAnalytics(editorAnalyticsAPI, editorViewModeAPI) { return function (_ref) { var triggerMethod = _ref.triggerMethod; return withAnalytics(editorAnalyticsAPI, function (state) { var _editorViewModeAPI$sh, _editorViewModeAPI$sh2; return { 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: triggerMethod, editorViewMode: (_editorViewModeAPI$sh = editorViewModeAPI === null || editorViewModeAPI === void 0 || (_editorViewModeAPI$sh2 = editorViewModeAPI.sharedState.currentState()) === null || _editorViewModeAPI$sh2 === void 0 ? void 0 : _editorViewModeAPI$sh2.mode) !== null && _editorViewModeAPI$sh !== void 0 ? _editorViewModeAPI$sh : 'edit' } }; })(activate()); }; }; export var findWithAnalytics = function findWithAnalytics(editorAnalyticsAPI) { return function (_ref2) { var editorView = _ref2.editorView, containerElement = _ref2.containerElement, keyword = _ref2.keyword; return withAnalytics(editorAnalyticsAPI, { eventType: EVENT_TYPE.TRACK, action: ACTION.FIND_PERFORMED, actionSubject: ACTION_SUBJECT.TEXT })(find(editorView, containerElement, keyword)); }; }; export var findNextWithAnalytics = function findNextWithAnalytics(editorAnalyticsAPI, editorView) { return function (_ref3) { var triggerMethod = _ref3.triggerMethod; return withAnalytics(editorAnalyticsAPI, { eventType: EVENT_TYPE.TRACK, action: ACTION.FIND_NEXT_PERFORMED, actionSubject: ACTION_SUBJECT.TEXT, attributes: { triggerMethod: triggerMethod } })(findNext(editorView)); }; }; export var findPrevWithAnalytics = function findPrevWithAnalytics(editorAnalyticsAPI, editorView) { return function (_ref4) { var triggerMethod = _ref4.triggerMethod; return withAnalytics(editorAnalyticsAPI, { eventType: EVENT_TYPE.TRACK, action: ACTION.FIND_PREV_PERFORMED, actionSubject: ACTION_SUBJECT.TEXT, attributes: { triggerMethod: triggerMethod } })(findPrevious(editorView)); }; }; export var replaceWithAnalytics = function replaceWithAnalytics(editorAnalyticsAPI) { return function (_ref5) { var triggerMethod = _ref5.triggerMethod, replaceText = _ref5.replaceText; return withAnalytics(editorAnalyticsAPI, { eventType: EVENT_TYPE.TRACK, action: ACTION.REPLACED_ONE, actionSubject: ACTION_SUBJECT.TEXT, attributes: { triggerMethod: triggerMethod } })(replace(replaceText)); }; }; export var replaceAllWithAnalytics = function replaceAllWithAnalytics(editorAnalyticsAPI) { return function (_ref6) { var replaceText = _ref6.replaceText; return withAnalytics(editorAnalyticsAPI, { eventType: EVENT_TYPE.TRACK, action: ACTION.REPLACED_ALL, actionSubject: ACTION_SUBJECT.TEXT })(replaceAll(replaceText)); }; }; export var cancelSearchWithAnalytics = function cancelSearchWithAnalytics(editorAnalyticsAPI) { return function (_ref7) { var triggerMethod = _ref7.triggerMethod; return withAnalytics(editorAnalyticsAPI, { eventType: EVENT_TYPE.UI, action: ACTION.DEACTIVATED, actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG, attributes: { triggerMethod: triggerMethod } })(cancelSearch()); }; };