UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

34 lines 1.45 kB
import { createTable } from '@atlaskit/editor-tables/utils'; import { TABLE_MAX_WIDTH } from '../table-resizing/utils/consts'; const NESTED_TABLE_DEFAULT_ROWS = 2; const NESTED_TABLE_DEFAULT_COLS = 2; export const createTableWithWidth = ({ isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, isCommentEditor, isChromelessEditor, isTableResizingEnabled, isNestedTable, createTableProps }) => schema => { const attrsOverrides = {}; if (isNestedTable) { attrsOverrides.rowsCount = createTableProps !== null && createTableProps !== void 0 && createTableProps.rowsCount ? createTableProps === null || createTableProps === void 0 ? void 0 : createTableProps.rowsCount : NESTED_TABLE_DEFAULT_ROWS; attrsOverrides.colsCount = createTableProps !== null && createTableProps !== void 0 && createTableProps.colsCount ? createTableProps === null || createTableProps === void 0 ? void 0 : createTableProps.colsCount : NESTED_TABLE_DEFAULT_COLS; } if (isTableScalingEnabled && isFullWidthModeEnabled && !isCommentEditor) { attrsOverrides.tableWidth = TABLE_MAX_WIDTH; } if (isTableAlignmentEnabled && (isFullWidthModeEnabled || isCommentEditor)) { attrsOverrides.layout = 'align-start'; } if (isCommentEditor && isTableResizingEnabled || isChromelessEditor) { attrsOverrides.tableWidth = 'inherit'; } return createTable({ schema, ...createTableProps, ...attrsOverrides }); };