UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

100 lines 4.69 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { Component } from 'react'; import classnames from 'classnames'; import { isSSR } from '@atlaskit/editor-common/core-utils'; import { isRowSelected } from '@atlaskit/editor-tables/utils'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; import { getRowHeights } from '../../../pm-plugins/utils/row-controls'; import { TableCssClassName as ClassName } from '../../../types'; import { tableBorderColor } from '../../consts'; // Ignored via go/ees005 // eslint-disable-next-line @repo/internal/react/no-class-components, @typescript-eslint/no-explicit-any export default class NumberColumn extends Component { constructor(...args) { super(...args); _defineProperty(this, "getCellStyles", (index, rowHeight) => { const { stickyTop, hasHeaderRow } = this.props; if (stickyTop && hasHeaderRow && index === 0) { const topOffset = 0; return { height: rowHeight, top: `${topOffset}px` }; } return { height: rowHeight }; }); _defineProperty(this, "getClassNames", (index, isButtonDisabled = false) => { const { hoveredRows, editorView, isInDanger, isResizing, tableActive } = this.props; const isActive = isRowSelected(index)(editorView.state.selection) || (hoveredRows || []).indexOf(index) !== -1 && !isResizing; return classnames(ClassName.NUMBERED_COLUMN_BUTTON, { [ClassName.NUMBERED_COLUMN_BUTTON_DISABLED]: isButtonDisabled, [ClassName.HOVERED_CELL_IN_DANGER]: tableActive && isActive && isInDanger, [ClassName.HOVERED_CELL_ACTIVE]: tableActive && isActive }); }); } render() { const { tableRef, hasHeaderRow, isDragAndDropEnabled, tableActive, updateCellHoverLocation } = this.props; const rowHeights = getRowHeights(tableRef); if (isSSR()) { return /*#__PURE__*/React.createElement("div", { // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 className: ClassName.NUMBERED_COLUMN, style: { // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview marginTop: hasHeaderRow && this.props.stickyTop !== undefined ? rowHeights[0] : undefined, borderLeft: isDragAndDropEnabled && tableActive && !expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) ? // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766 `1px solid ${tableBorderColor}` : undefined, // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop visibility: 'hidden' // Ensure the column is not visible during SSR }, contentEditable: false }); } return /*#__PURE__*/React.createElement("div", { // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 className: ClassName.NUMBERED_COLUMN, style: { // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview marginTop: hasHeaderRow && this.props.stickyTop !== undefined ? rowHeights[0] : undefined, borderLeft: isDragAndDropEnabled && tableActive && !expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) ? // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766 `1px solid ${tableBorderColor}` : undefined, // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop visibility: 'visible' }, contentEditable: false }, rowHeights.map((rowHeight, index) => /*#__PURE__*/React.createElement("div", { // Ignored via go/ees005 // eslint-disable-next-line react/no-array-index-key key: `wrapper-${index}` // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 , className: this.getClassNames(index, true), "data-index": index // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766 , style: this.getCellStyles(index, rowHeight), onFocus: expValEquals('platform_editor_table_a11y_eslint_fix', 'isEnabled', true) ? () => updateCellHoverLocation(index) : undefined, onMouseOver: () => updateCellHoverLocation(index) }, hasHeaderRow ? index > 0 ? index : null : index + 1))); } }