UNPKG

@atlaskit/editor-plugin-find-replace

Version:

find replace plugin for @atlaskit/editor-core

108 lines (106 loc) • 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceWithAnalytics = exports.replaceAllWithAnalytics = exports.findWithAnalytics = exports.findPrevWithAnalytics = exports.findNextWithAnalytics = exports.cancelSearchWithAnalytics = exports.activateWithAnalytics = void 0; var _enums = require("@atlaskit/editor-common/analytics/types/enums"); var _withAnalytics = require("@atlaskit/editor-common/withAnalytics"); var _state = require("@atlaskit/editor-prosemirror/state"); var _commands = require("./commands"); /** * Hosts that do not install `editorViewMode` are always editing, so the attribute * falls back to `edit` when the api is absent. */ var activateWithAnalytics = exports.activateWithAnalytics = function activateWithAnalytics(editorAnalyticsAPI, editorViewModeAPI) { return function (_ref) { var triggerMethod = _ref.triggerMethod; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, function (state) { var _editorViewModeAPI$sh, _editorViewModeAPI$sh2; return { eventType: _enums.EVENT_TYPE.UI, action: _enums.ACTION.ACTIVATED, actionSubject: _enums.ACTION_SUBJECT.FIND_REPLACE_DIALOG, attributes: { inputMethod: state.selection instanceof _state.TextSelection && !state.selection.empty ? _enums.INPUT_METHOD.PREFILL : _enums.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' } }; })((0, _commands.activate)()); }; }; var findWithAnalytics = exports.findWithAnalytics = function findWithAnalytics(editorAnalyticsAPI) { return function (_ref2) { var editorView = _ref2.editorView, containerElement = _ref2.containerElement, keyword = _ref2.keyword; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, { eventType: _enums.EVENT_TYPE.TRACK, action: _enums.ACTION.FIND_PERFORMED, actionSubject: _enums.ACTION_SUBJECT.TEXT })((0, _commands.find)(editorView, containerElement, keyword)); }; }; var findNextWithAnalytics = exports.findNextWithAnalytics = function findNextWithAnalytics(editorAnalyticsAPI, editorView) { return function (_ref3) { var triggerMethod = _ref3.triggerMethod; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, { eventType: _enums.EVENT_TYPE.TRACK, action: _enums.ACTION.FIND_NEXT_PERFORMED, actionSubject: _enums.ACTION_SUBJECT.TEXT, attributes: { triggerMethod: triggerMethod } })((0, _commands.findNext)(editorView)); }; }; var findPrevWithAnalytics = exports.findPrevWithAnalytics = function findPrevWithAnalytics(editorAnalyticsAPI, editorView) { return function (_ref4) { var triggerMethod = _ref4.triggerMethod; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, { eventType: _enums.EVENT_TYPE.TRACK, action: _enums.ACTION.FIND_PREV_PERFORMED, actionSubject: _enums.ACTION_SUBJECT.TEXT, attributes: { triggerMethod: triggerMethod } })((0, _commands.findPrevious)(editorView)); }; }; var replaceWithAnalytics = exports.replaceWithAnalytics = function replaceWithAnalytics(editorAnalyticsAPI) { return function (_ref5) { var triggerMethod = _ref5.triggerMethod, replaceText = _ref5.replaceText; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, { eventType: _enums.EVENT_TYPE.TRACK, action: _enums.ACTION.REPLACED_ONE, actionSubject: _enums.ACTION_SUBJECT.TEXT, attributes: { triggerMethod: triggerMethod } })((0, _commands.replace)(replaceText)); }; }; var replaceAllWithAnalytics = exports.replaceAllWithAnalytics = function replaceAllWithAnalytics(editorAnalyticsAPI) { return function (_ref6) { var replaceText = _ref6.replaceText; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, { eventType: _enums.EVENT_TYPE.TRACK, action: _enums.ACTION.REPLACED_ALL, actionSubject: _enums.ACTION_SUBJECT.TEXT })((0, _commands.replaceAll)(replaceText)); }; }; var cancelSearchWithAnalytics = exports.cancelSearchWithAnalytics = function cancelSearchWithAnalytics(editorAnalyticsAPI) { return function (_ref7) { var triggerMethod = _ref7.triggerMethod; return (0, _withAnalytics.withAnalytics)(editorAnalyticsAPI, { eventType: _enums.EVENT_TYPE.UI, action: _enums.ACTION.DEACTIVATED, actionSubject: _enums.ACTION_SUBJECT.FIND_REPLACE_DIALOG, attributes: { triggerMethod: triggerMethod } })((0, _commands.cancelSearch)()); }; };