UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

75 lines (73 loc) 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.analyticsEventKey = exports.SEVERITY = void 0; exports.findInsertLocation = findInsertLocation; exports.getBreakpointKey = exports.getAnalyticsEventSeverity = exports.getAnalyticsEditorAppearance = exports.getAnalyticsAppearance = void 0; var _FabricEditorAnalyticsContext = require("@atlaskit/analytics-namespaced-context/FabricEditorAnalyticsContext"); var _state = require("@atlaskit/editor-prosemirror/state"); var _utils = require("@atlaskit/editor-prosemirror/utils"); var _cellSelection = require("@atlaskit/editor-tables/cell-selection"); var getAnalyticsAppearance = exports.getAnalyticsAppearance = function getAnalyticsAppearance(appearance) { switch (appearance) { case 'full-page': return _FabricEditorAnalyticsContext.EDITOR_APPEARANCE_CONTEXT.FIXED_WIDTH; case 'full-width': return _FabricEditorAnalyticsContext.EDITOR_APPEARANCE_CONTEXT.FULL_WIDTH; case 'comment': return _FabricEditorAnalyticsContext.EDITOR_APPEARANCE_CONTEXT.COMMENT; case 'chromeless': return _FabricEditorAnalyticsContext.EDITOR_APPEARANCE_CONTEXT.CHROMELESS; case 'mobile': return _FabricEditorAnalyticsContext.EDITOR_APPEARANCE_CONTEXT.MOBILE; case 'max': return _FabricEditorAnalyticsContext.EDITOR_APPEARANCE_CONTEXT.MAX; } }; var getAnalyticsEditorAppearance = exports.getAnalyticsEditorAppearance = function getAnalyticsEditorAppearance(editorAppearance) { return editorAppearance ? "editor_".concat(getAnalyticsAppearance(editorAppearance)) : '_unknown'; }; var getAnalyticsEventSeverity = exports.getAnalyticsEventSeverity = function getAnalyticsEventSeverity(duration, normalThreshold, degradedThreshold) { if (duration > normalThreshold && duration <= degradedThreshold) { return SEVERITY.DEGRADED; } if (duration > degradedThreshold) { return SEVERITY.BLOCKING; } return SEVERITY.NORMAL; }; function findInsertLocation(selection) { var _selection$$from$doc$ = selection.$from.doc.type, schema = _selection$$from$doc$.schema, name = _selection$$from$doc$.name; if (selection instanceof _state.NodeSelection) { return selection.node.type.name; } if (selection instanceof _cellSelection.CellSelection) { return schema.nodes.table.name; } // Text selection var parentNodeInfo = (0, _utils.findParentNode)(function (node) { return node.type !== schema.nodes.paragraph; })(selection); return parentNodeInfo ? parentNodeInfo.node.type.name : name; } var SEVERITY = exports.SEVERITY = /*#__PURE__*/function (SEVERITY) { SEVERITY["NORMAL"] = "normal"; SEVERITY["DEGRADED"] = "degraded"; SEVERITY["BLOCKING"] = "blocking"; return SEVERITY; }({}); var analyticsEventKey = exports.analyticsEventKey = 'EDITOR_ANALYTICS_EVENT'; var EDITOR_BREAKPOINT_WIDTH = { S: 760, M: 1600, L: Infinity }; var TABLE_BREAKPOINT_KEYS = Object.keys(EDITOR_BREAKPOINT_WIDTH); var getBreakpointKey = exports.getBreakpointKey = function getBreakpointKey(width) { return TABLE_BREAKPOINT_KEYS.find(function (key) { return width <= EDITOR_BREAKPOINT_WIDTH[key]; }) || 'L'; };