UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

73 lines 2.45 kB
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics'; import { findParentNode } from '@atlaskit/editor-prosemirror/utils'; export var getMediaResizeAnalyticsEvent = function getMediaResizeAnalyticsEvent(type, attributes) { if (!attributes) { return; } var width = attributes.width, widthType = attributes.widthType, layout = attributes.layout, snapType = attributes.snapType, parentNode = attributes.parentNode, inputMethod = attributes.inputMethod; var actionSubject = type === 'embed' ? ACTION_SUBJECT.EMBEDS : ACTION_SUBJECT.MEDIA_SINGLE; return { action: ACTION.EDITED, actionSubject: actionSubject, actionSubjectId: ACTION_SUBJECT_ID.RESIZED, attributes: { width: width, layout: layout, widthType: widthType, snapType: snapType, parentNode: parentNode, inputMethod: inputMethod }, eventType: EVENT_TYPE.UI }; }; export var getMediaInputResizeAnalyticsEvent = function getMediaInputResizeAnalyticsEvent(type, attributes) { if (!attributes) { return; } var width = attributes.width, layout = attributes.layout, validation = attributes.validation, parentNode = attributes.parentNode, inputMethod = attributes.inputMethod; var actionSubject = type === 'embed' ? ACTION_SUBJECT.EMBEDS : ACTION_SUBJECT.MEDIA_SINGLE; return { action: ACTION.EDITED, actionSubject: actionSubject, actionSubjectId: ACTION_SUBJECT_ID.RESIZED, attributes: { width: width, layout: layout, validation: validation, parentNode: parentNode, inputMethod: inputMethod }, eventType: EVENT_TYPE.UI }; }; export var getChangeMediaAnalytics = function getChangeMediaAnalytics(previousType, newType, changeFromLocation) { return { action: ACTION.CHANGED_TYPE, actionSubject: ACTION_SUBJECT.MEDIA, eventType: EVENT_TYPE.TRACK, attributes: { newType: newType, previousType: previousType, changeFromLocation: changeFromLocation } }; }; export function findChangeFromLocation(selection) { var _selection$$from$doc$ = selection.$from.doc.type, schema = _selection$$from$doc$.schema, name = _selection$$from$doc$.name; var parentNodeInfo = findParentNode(function (node) { return node.type !== schema.nodes.paragraph; })(selection); return parentNodeInfo ? parentNodeInfo.node.type.name : name; }