import React, { CSSProperties } from 'react'; import classnames from 'classnames'; import { Node as PmNode } from 'prosemirror-model'; import { isTableSelected } from '@atlaskit/editor-tables/utils'; import { EditorView } from 'prosemirror-view'; import rafSchedule from 'raf-schd'; import { browser, calcTableWidth, tableMarginSides, } from '@atlaskit/editor-common'; import { akEditorMobileBreakoutPoint, akEditorTableToolbarSize as tableToolbarSize, } from '@atlaskit/editor-shared-styles'; import { isValidPosition } from '../../../utils'; import { getParentNodeWidth } from '../../../utils/node-width'; import { parsePx } from '../../../utils/dom'; import { WidthPluginState } from '../../width'; import { autoSizeTable } from '../commands'; import { getPluginState } from '../pm-plugins/plugin-factory'; import { findStickyHeaderForTable, RowStickyState, pluginKey as stickyHeadersPluginKey, StickyPluginState, } from '../pm-plugins/sticky-headers'; import { scaleTable } from '../pm-plugins/table-resizing'; import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, } from '../pm-plugins/table-resizing/utils'; import { updateControls } from '../pm-plugins/table-resizing/utils/dom'; import { TableCssClassName as ClassName, ColumnResizingPluginState, ShadowEvent, } from '../types'; import type { TableColumnOrdering } from '@atlaskit/adf-schema/steps'; import TableFloatingControls from '../ui/TableFloatingControls'; import { containsHeaderRow, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, } from '../utils'; import { TableOptions } from './types'; import { updateOverflowShadows } from './update-overflow-shadows'; import { EventDispatcher } from '../../../event-dispatcher'; import { ForwardRef } from '../../../nodeviews/types'; import { getFeatureFlags } from '../../feature-flags-context'; import memoizeOne from 'memoize-one'; import { OverflowShadowsObserver } from './OverflowShadowsObserver'; const isIE11 = browser.ie_version === 11; const NOOP = () => undefined; export interface ComponentProps { view: EditorView; getNode: () => PmNode; allowColumnResizing?: boolean; eventDispatcher: EventDispatcher; getPos: () => number; options?: TableOptions; contentDOM: ForwardRef; containerWidth: WidthPluginState; allowControls: boolean; isHeaderRowEnabled: boolean; isHeaderColumnEnabled: boolean; tableActive: boolean; ordering: TableColumnOrdering; tableResizingPluginState?: ColumnResizingPluginState; } interface TableState { scroll: number; tableContainerWidth: string; parentWidth?: number; isLoading: boolean; stickyHeader?: RowStickyState; [ShadowEvent.SHOW_BEFORE_SHADOW]: boolean; [ShadowEvent.SHOW_AFTER_SHADOW]: boolean; } // in Chrome, if none of the parent elements // have content, then it will auto-scroll the container // which interferes with us applying padding to the // sticky header to make up for us taking it out of // the layout flow. // // this is only an issue when scrolling down the // page without row controls active, and doesn't // occur in other browsers afaik const FloatingPlaceholder = () => (