UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

36 lines (35 loc) 2.21 kB
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics'; import { findTable } from '@atlaskit/editor-tables/utils'; import { applyTableMeasurement } from '../../transforms/content-mode'; import { measureTableWithAutoLayout } from './measure-table-with-auto-layout'; /** * Used to measure a selected table width with it's content being laid out natively by the browser */ export var applyMeasuredWidthToSelectedTable = function applyMeasuredWidthToSelectedTable(view, api) { var _api$width, _api$analytics, _api$width$sharedStat, _api$width2; var tableObject = findTable(view.state.selection); if (!tableObject) { return; } var node = tableObject.node, pos = tableObject.pos; var tableState = api === null || api === void 0 ? void 0 : api.table.sharedState.currentState(); if (!(tableState !== null && tableState !== void 0 && tableState.tableRef)) { return; } var editorContainerWidth = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 || (_api$width = _api$width.sharedState.currentState()) === null || _api$width === void 0 ? void 0 : _api$width.width; var measurement = measureTableWithAutoLayout(tableState.tableRef, editorContainerWidth); var tr = applyTableMeasurement(view.state.tr, node, measurement, pos); api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({ action: TABLE_ACTION.FIT_TO_CONTENT_ON_DEMAND, actionSubject: ACTION_SUBJECT.TABLE, actionSubjectId: null, eventType: EVENT_TYPE.TRACK, attributes: { editorContainerWidth: (_api$width$sharedStat = api === null || api === void 0 || (_api$width2 = api.width) === null || _api$width2 === void 0 || (_api$width2 = _api$width2.sharedState.currentState()) === null || _api$width2 === void 0 ? void 0 : _api$width2.width) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : 0, tableWidth: measurement.tableWidth, totalColumnCount: measurement.colWidths.length } })(tr); view.dispatch(tr); };