UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

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