UNPKG

@atlaskit/renderer

Version:
84 lines (81 loc) 3.02 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import { TABLE_ACTION, ACTION_SUBJECT, EVENT_TYPE, MODE } from '@atlaskit/editor-common/analytics'; import { getBreakpointKey } from '@atlaskit/editor-common/utils/analytics'; export var getWidthInfoPayload = function getWidthInfoPayload(renderer) { var tablesInfo = []; var tableWrappers = renderer.querySelectorAll('.pm-table-wrapper'); // only send the event if there are tables on the page if (tableWrappers.length === 0) { return undefined; } tableWrappers.forEach(function (tableWrapper) { var table = tableWrapper.querySelector(':scope > table'); if (table) { var isNestedTable = Boolean(table.closest('td, th')); tablesInfo.push({ tableWidth: table.scrollWidth, hasScrollbar: tableWrapper.clientWidth < table.scrollWidth, isNestedTable: isNestedTable }); } }); var maxTableWidth = Math.max.apply(Math, _toConsumableArray(tablesInfo.map(function (table) { return table.tableWidth; }))); var editorWidth = renderer.scrollWidth; return { action: TABLE_ACTION.TABLE_WIDTH_INFO, actionSubject: ACTION_SUBJECT.TABLE, attributes: { editorWidth: editorWidth, editorWidthBreakpoint: getBreakpointKey(editorWidth), tableWidthInfo: tablesInfo, maxTableWidthBreakpoint: getBreakpointKey(maxTableWidth), hasTableWiderThanEditor: maxTableWidth > editorWidth, hasTableWithScrollbar: tablesInfo.some(function (table) { return table.hasScrollbar; }), mode: MODE.RENDERER }, eventType: EVENT_TYPE.OPERATIONAL }; }; export var getHeightInfoPayload = function getHeightInfoPayload(renderer) { var tablesInfo = []; var tableWrappers = renderer.querySelectorAll('.pm-table-wrapper'); // only send the event if there are tables on the page if (tableWrappers.length === 0) { return undefined; } tableWrappers.forEach(function (tableWrapper) { var table = tableWrapper.querySelector(':scope > table'); if (table) { var isNestedTable = Boolean(table.closest('td, th')); tablesInfo.push({ tableHeight: table.scrollHeight, isNestedTable: isNestedTable }); } }); var maxTableHeight = Math.max.apply(Math, _toConsumableArray(tablesInfo.map(function (table) { return table.tableHeight; }))); /** NOTE: Renderer is not scrollable, so this height represents the height of the content */ var rendererClientHeight = renderer.clientHeight; var viewportHeight = window.innerHeight; if (!viewportHeight) { return undefined; } return { action: TABLE_ACTION.TABLE_RENDERER_HEIGHT_INFO, actionSubject: ACTION_SUBJECT.TABLE, attributes: { viewportHeight: viewportHeight, rendererHeight: rendererClientHeight, maxTableHeight: maxTableHeight, maxTableToViewportHeightRatio: maxTableHeight / viewportHeight, tableHeightInfo: tablesInfo }, eventType: EVENT_TYPE.OPERATIONAL }; };