UNPKG

@atlaskit/editor-common

Version:

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

62 lines (61 loc) 2.26 kB
import { EDITOR_APPEARANCE_CONTEXT } from '@atlaskit/analytics-namespaced-context/FabricEditorAnalyticsContext'; import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; import { findParentNode } from '@atlaskit/editor-prosemirror/utils'; import { CellSelection } from '@atlaskit/editor-tables/cell-selection'; export const getAnalyticsAppearance = appearance => { switch (appearance) { case 'full-page': return EDITOR_APPEARANCE_CONTEXT.FIXED_WIDTH; case 'full-width': return EDITOR_APPEARANCE_CONTEXT.FULL_WIDTH; case 'comment': return EDITOR_APPEARANCE_CONTEXT.COMMENT; case 'chromeless': return EDITOR_APPEARANCE_CONTEXT.CHROMELESS; case 'mobile': return EDITOR_APPEARANCE_CONTEXT.MOBILE; case 'max': return EDITOR_APPEARANCE_CONTEXT.MAX; } }; export const getAnalyticsEditorAppearance = editorAppearance => editorAppearance ? `editor_${getAnalyticsAppearance(editorAppearance)}` : '_unknown'; export const getAnalyticsEventSeverity = (duration, normalThreshold, degradedThreshold) => { if (duration > normalThreshold && duration <= degradedThreshold) { return SEVERITY.DEGRADED; } if (duration > degradedThreshold) { return SEVERITY.BLOCKING; } return SEVERITY.NORMAL; }; export function findInsertLocation(selection) { const { schema, name } = selection.$from.doc.type; if (selection instanceof NodeSelection) { return selection.node.type.name; } if (selection instanceof CellSelection) { return schema.nodes.table.name; } // Text selection const parentNodeInfo = findParentNode(node => node.type !== schema.nodes.paragraph)(selection); return parentNodeInfo ? parentNodeInfo.node.type.name : name; } export let SEVERITY = /*#__PURE__*/function (SEVERITY) { SEVERITY["NORMAL"] = "normal"; SEVERITY["DEGRADED"] = "degraded"; SEVERITY["BLOCKING"] = "blocking"; return SEVERITY; }({}); export const analyticsEventKey = 'EDITOR_ANALYTICS_EVENT'; const EDITOR_BREAKPOINT_WIDTH = { S: 760, M: 1600, L: Infinity }; const TABLE_BREAKPOINT_KEYS = Object.keys(EDITOR_BREAKPOINT_WIDTH); export const getBreakpointKey = width => { return TABLE_BREAKPOINT_KEYS.find(key => width <= EDITOR_BREAKPOINT_WIDTH[key]) || 'L'; };