UNPKG

@atlaskit/editor-plugin-block-controls

Version:

Block controls plugin for @atlaskit/editor-core

60 lines (58 loc) 2.72 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { fg } from '@atlaskit/platform-feature-flags'; export var attachMoveNodeAnalytics = function attachMoveNodeAnalytics(tr, inputMethod, fromDepth, fromNodeType, toDepth, toNodeType, isSameParent, api, fromNodeTypes, hasSelectedMultipleNodes) { var _api$analytics; return api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 ? void 0 : _api$analytics.attachAnalyticsEvent({ eventType: EVENT_TYPE.TRACK, action: ACTION.MOVED, actionSubject: ACTION_SUBJECT.ELEMENT, actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE, attributes: { nodeDepth: fromDepth, nodeType: fromNodeType, nodeTypes: fromNodeTypes, hasSelectedMultipleNodes: hasSelectedMultipleNodes, destinationNodeDepth: toDepth, destinationNodeType: toNodeType, isSameParent: isSameParent, inputMethod: inputMethod } })(tr); }; export var fireInsertLayoutAnalytics = function fireInsertLayoutAnalytics(tr, api, nodeTypes, hasSelectedMultipleNodes, columnCount) { var _api$analytics2; api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.attachAnalyticsEvent({ action: ACTION.INSERTED, actionSubject: ACTION_SUBJECT.DOCUMENT, actionSubjectId: ACTION_SUBJECT_ID.LAYOUT, attributes: { inputMethod: INPUT_METHOD.DRAG_AND_DROP, nodeTypes: nodeTypes, hasSelectedMultipleNodes: hasSelectedMultipleNodes, columnCount: columnCount }, eventType: EVENT_TYPE.TRACK })(tr); }; /** * Given a range, return distinctive types of node and whether there are multiple nodes in the range */ export var getMultiSelectAnalyticsAttributes = function getMultiSelectAnalyticsAttributes(tr, anchor, head) { var nodeTypes = []; var from = Math.min(anchor, head); var to = Math.max(anchor, head); tr.doc.nodesBetween(from, to, function (node, pos) { if (pos < from) { // ignore parent node return true; } nodeTypes.push(node.type.name); // only care about the top level (relatively in the range) nodes return false; }); return { nodeTypes: fg('platform_editor_track_node_types') ? _toConsumableArray(new Set(nodeTypes)).sort().join(',') : undefined, hasSelectedMultipleNodes: nodeTypes.length > 1 }; };