UNPKG

@atlaskit/editor-plugin-list

Version:

List plugin for @atlaskit/editor-core

59 lines (57 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createRuleForListType = createRuleForListType; var _analytics = require("@atlaskit/editor-common/analytics"); var _utils = require("@atlaskit/editor-common/utils"); var _wrappingJoinRule = require("./wrapping-join-rule"); var getOrder = function getOrder(matchResult) { return Number(matchResult[1]); }; function createRuleForListType(_ref) { var listType = _ref.listType, expression = _ref.expression, editorAnalyticsApi = _ref.editorAnalyticsApi; var joinScenario = _analytics.JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.NO_JOIN; var isBulletList = listType.name === 'bulletList'; var actionSubjectId = isBulletList ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER; var getAnalyticsPayload = function getAnalyticsPayload(state, matchResult) { var analyticsPayload = { action: _analytics.ACTION.INSERTED, actionSubject: _analytics.ACTION_SUBJECT.LIST, actionSubjectId: actionSubjectId, eventType: _analytics.EVENT_TYPE.TRACK, attributes: { inputMethod: _analytics.INPUT_METHOD.FORMATTING } }; if (listType === state.schema.nodes.orderedList && analyticsPayload.attributes) { analyticsPayload.attributes.listStartNumber = getOrder(matchResult); analyticsPayload.attributes.joinScenario = joinScenario; // we reset the tracked joinScenario after storing it in the event payload joinScenario = _analytics.JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.NO_JOIN; } return analyticsPayload; }; var joinToNeighbourIfSameListType = function joinToNeighbourIfSameListType(_, node, scenario) { var shouldJoin = node.type === listType; if (shouldJoin) { joinScenario = scenario; } return shouldJoin; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any var getAttrs = function getAttrs(matchResult) { return { order: getOrder(matchResult) }; }; var inputRule = (0, _wrappingJoinRule.createWrappingJoinRule)({ match: expression, nodeType: listType, getAttrs: getAttrs, joinPredicate: joinToNeighbourIfSameListType }); return (0, _utils.inputRuleWithAnalytics)(getAnalyticsPayload, editorAnalyticsApi)(inputRule); }