@atlaskit/renderer
Version:
Renderer component
91 lines (87 loc) • 3.43 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getWidthInfoPayload = exports.getHeightInfoPayload = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _analytics = require("@atlaskit/editor-common/analytics");
var _analytics2 = require("@atlaskit/editor-common/utils/analytics");
var getWidthInfoPayload = exports.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, (0, _toConsumableArray2.default)(tablesInfo.map(function (table) {
return table.tableWidth;
})));
var editorWidth = renderer.scrollWidth;
return {
action: _analytics.TABLE_ACTION.TABLE_WIDTH_INFO,
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
attributes: {
editorWidth: editorWidth,
editorWidthBreakpoint: (0, _analytics2.getBreakpointKey)(editorWidth),
tableWidthInfo: tablesInfo,
maxTableWidthBreakpoint: (0, _analytics2.getBreakpointKey)(maxTableWidth),
hasTableWiderThanEditor: maxTableWidth > editorWidth,
hasTableWithScrollbar: tablesInfo.some(function (table) {
return table.hasScrollbar;
}),
mode: _analytics.MODE.RENDERER
},
eventType: _analytics.EVENT_TYPE.OPERATIONAL
};
};
var getHeightInfoPayload = exports.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, (0, _toConsumableArray2.default)(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: _analytics.TABLE_ACTION.TABLE_RENDERER_HEIGHT_INFO,
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
attributes: {
viewportHeight: viewportHeight,
rendererHeight: rendererClientHeight,
maxTableHeight: maxTableHeight,
maxTableToViewportHeightRatio: maxTableHeight / viewportHeight,
tableHeightInfo: tablesInfo
},
eventType: _analytics.EVENT_TYPE.OPERATIONAL
};
};