@atlaskit/editor-plugin-card
Version:
Card plugin for @atlaskit/editor-core
69 lines • 2.06 kB
JavaScript
import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
/**
* If the metadata is for a history event,
* returns undo/redo instead of instead of what fn(metadata) would have otherwise
* returned
*/
const withHistoryMethod = fn => {
return metadata => {
const {
isUndo,
isRedo
} = metadata;
if (isUndo) {
return 'undo';
}
if (isRedo) {
return 'redo';
}
return fn(metadata);
};
};
export const getMethod = withHistoryMethod(({
inputMethod,
sourceEvent
}) => {
var _inputMethod, _payload, _payload$attributes;
inputMethod = (_inputMethod = inputMethod) !== null && _inputMethod !== void 0 ? _inputMethod : sourceEvent === null || sourceEvent === void 0 ? void 0 : (_payload = sourceEvent.payload) === null || _payload === void 0 ? void 0 : (_payload$attributes = _payload.attributes) === null || _payload$attributes === void 0 ? void 0 : _payload$attributes.inputMethod;
switch (inputMethod) {
case INPUT_METHOD.CLIPBOARD:
return 'editor_paste';
case INPUT_METHOD.FLOATING_TB:
return 'editor_floatingToolbar';
case INPUT_METHOD.AUTO_DETECT:
case INPUT_METHOD.FORMATTING:
return 'editor_type';
case INPUT_METHOD.TYPEAHEAD:
return 'linkpicker_searchResult';
case INPUT_METHOD.MANUAL:
return 'linkpicker_manual';
case INPUT_METHOD.DATASOURCE:
return 'datasource_config';
default:
return 'unknown';
}
});
export const getUpdateType = withHistoryMethod(({
action
}) => {
switch (action) {
case ACTION.CHANGED_TYPE:
return 'display_update';
case ACTION.UPDATED:
return 'link_update';
default:
return 'unknown';
}
});
export const getDeleteType = withHistoryMethod(({
action
}) => {
if (action === ACTION.UNLINK) {
return 'unlink';
}
return 'delete';
});
export const getSourceEventFromMetadata = metadata => {
return metadata.sourceEvent instanceof UIAnalyticsEvent ? metadata.sourceEvent : null;
};