@atlaskit/editor-plugin-table 14.2.7 → 14.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +24 -65
  3. package/dist/cjs/nodeviews/table.js +14 -128
  4. package/dist/cjs/pm-plugins/utils/analytics.js +33 -1
  5. package/dist/cjs/tablePlugin.js +50 -13
  6. package/dist/cjs/ui/DragHandle/index.js +21 -8
  7. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +1 -18
  8. package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -2
  9. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +1 -18
  10. package/dist/cjs/ui/TableFloatingControls/index.js +3 -45
  11. package/dist/es2019/nodeviews/TableComponent.js +18 -62
  12. package/dist/es2019/nodeviews/table.js +14 -129
  13. package/dist/es2019/pm-plugins/utils/analytics.js +32 -0
  14. package/dist/es2019/tablePlugin.js +39 -1
  15. package/dist/es2019/ui/DragHandle/index.js +15 -5
  16. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -19
  17. package/dist/es2019/ui/TableFloatingColumnControls/index.js +1 -2
  18. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +2 -19
  19. package/dist/es2019/ui/TableFloatingControls/index.js +5 -47
  20. package/dist/esm/nodeviews/TableComponent.js +24 -65
  21. package/dist/esm/nodeviews/table.js +14 -128
  22. package/dist/esm/pm-plugins/utils/analytics.js +32 -0
  23. package/dist/esm/tablePlugin.js +50 -13
  24. package/dist/esm/ui/DragHandle/index.js +20 -7
  25. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -19
  26. package/dist/esm/ui/TableFloatingColumnControls/index.js +1 -2
  27. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +2 -19
  28. package/dist/esm/ui/TableFloatingControls/index.js +5 -47
  29. package/dist/types/pm-plugins/utils/analytics.d.ts +2 -0
  30. package/dist/types/ui/DragHandle/index.d.ts +1 -4
  31. package/dist/types-ts4.5/pm-plugins/utils/analytics.d.ts +2 -0
  32. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +1 -4
  33. package/package.json +10 -22
@@ -4,7 +4,6 @@ import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'reac
4
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
5
  import { CellSelection } from '@atlaskit/editor-tables';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
- import { fg } from '@atlaskit/platform-feature-flags';
8
7
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
9
8
  import { clearHoverSelection } from '../../../pm-plugins/commands';
10
9
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
@@ -13,7 +12,7 @@ import { getRowHeights, getRowsParams } from '../../../pm-plugins/utils/row-cont
13
12
  import { getSelectedRowIndexes } from '../../../pm-plugins/utils/selection';
14
13
  import { TableCssClassName as ClassName } from '../../../types';
15
14
  import { dropTargetExtendedWidth } from '../../consts';
16
- import { DragHandle, DragHandleWithSharedState } from '../../DragHandle';
15
+ import { DragHandle } from '../../DragHandle';
17
16
  import RowDropTarget from '../RowDropTarget';
18
17
  const getSelectedRows = selection => {
19
18
  if (selection instanceof CellSelection && selection.isRowSelection()) {
@@ -155,23 +154,7 @@ export const DragControls = ({
155
154
  pointerEvents: 'none'
156
155
  },
157
156
  "data-testid": `table-floating-row-${isHover ? rowIndex : selectedRowIndexes[0]}-drag-handle`
158
- }, fg('platform_editor_table_use_shared_state_hook_fg') ? /*#__PURE__*/React.createElement(DragHandleWithSharedState, {
159
- isDragMenuTarget: !isHover,
160
- direction: "row",
161
- tableLocalId: currentNodeLocalId,
162
- indexes: indexes,
163
- forceDefaultHandle: !isHover,
164
- previewWidth: tableWidth,
165
- previewHeight: previewHeight,
166
- appearance: appearance,
167
- hoveredCell: hoveredCell,
168
- onClick: handleClick,
169
- onMouseOver: handleMouseOver,
170
- onMouseOut: handleMouseOut,
171
- toggleDragMenu: toggleDragMenuHandler,
172
- editorView: editorView,
173
- api: api
174
- }) : /*#__PURE__*/React.createElement(DragHandle, {
157
+ }, /*#__PURE__*/React.createElement(DragHandle, {
175
158
  isDragMenuTarget: !isHover,
176
159
  direction: "row",
177
160
  tableLocalId: currentNodeLocalId,
@@ -5,12 +5,10 @@ import { fg } from '@atlaskit/platform-feature-flags';
5
5
  import { hoverCell, hoverRows, selectRow, selectRows } from '../../pm-plugins/commands';
6
6
  import { isTableNested } from '../../pm-plugins/utils/nodes';
7
7
  import { TableCssClassName as ClassName } from '../../types';
8
- import { CornerControls } from './CornerControls/ClassicCornerControls';
9
- import { DragCornerControls, DragCornerControlsWithSelection } from './CornerControls/DragCornerControls';
8
+ import { DragCornerControlsWithSelection } from './CornerControls/DragCornerControls';
10
9
  import { FloatingControlsWithSelection } from './FloatingControlsWithSelection';
11
10
  import NumberColumn from './NumberColumn';
12
- import { RowControls } from './RowControls/ClassicControls';
13
- import { DragControls, DragControlsWithSelection } from './RowControls/DragControls';
11
+ import { DragControlsWithSelection } from './RowControls/DragControls';
14
12
  // Row controls
15
13
  export const TableFloatingControls = ({
16
14
  editorView,
@@ -109,7 +107,7 @@ export const TableFloatingControls = ({
109
107
  updateCellHoverLocation: updateCellHoverLocation,
110
108
  stickyTop: stickyTop,
111
109
  isDragAndDropEnabled: isDragAndDropEnabled
112
- }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, fg('platform_editor_table_use_shared_state_hook_fg') ? /*#__PURE__*/React.createElement(React.Fragment, null, shouldShowCornerControls && /*#__PURE__*/React.createElement(DragCornerControlsWithSelection, {
110
+ }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, shouldShowCornerControls && /*#__PURE__*/React.createElement(DragCornerControlsWithSelection, {
113
111
  editorView: editorView,
114
112
  tableRef: tableRef,
115
113
  isInDanger: isInDanger,
@@ -133,29 +131,7 @@ export const TableFloatingControls = ({
133
131
  selectRows: _selectRows,
134
132
  updateCellHoverLocation: updateCellHoverLocation,
135
133
  api: api
136
- })) : /*#__PURE__*/React.createElement(React.Fragment, null, shouldShowCornerControls && /*#__PURE__*/React.createElement(DragCornerControls, {
137
- editorView: editorView,
138
- tableRef: tableRef,
139
- isInDanger: isInDanger,
140
- isResizing: isResizing
141
- }), /*#__PURE__*/React.createElement(DragControls, {
142
- tableRef: tableRef,
143
- tableNode: tableNode,
144
- hoveredCell: hoveredCell,
145
- isTableHovered: isTableHovered,
146
- editorView: editorView,
147
- tableActive: tableActive,
148
- isInDanger: isInDanger,
149
- isResizing: isResizing
150
- // Ignored via go/ees005
151
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
152
- ,
153
- tableWidth: tableWrapperWidth,
154
- hoverRows: _hoverRows,
155
- selectRow: _selectRow,
156
- selectRows: _selectRows,
157
- updateCellHoverLocation: updateCellHoverLocation
158
- }))) : fg('platform_editor_table_use_shared_state_hook_fg') ? /*#__PURE__*/React.createElement(FloatingControlsWithSelection, {
134
+ })) : /*#__PURE__*/React.createElement(FloatingControlsWithSelection, {
159
135
  editorView: editorView,
160
136
  tableRef: tableRef,
161
137
  isInDanger: isInDanger,
@@ -168,25 +144,7 @@ export const TableFloatingControls = ({
168
144
  hoverRows: _hoverRows,
169
145
  selectRow: _selectRow,
170
146
  api: api
171
- }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
172
- editorView: editorView,
173
- tableRef: tableRef,
174
- isInDanger: isInDanger,
175
- isResizing: isResizing,
176
- isHeaderRowEnabled: isHeaderRowEnabled,
177
- isHeaderColumnEnabled: isHeaderColumnEnabled,
178
- hoveredRows: hoveredRows,
179
- stickyTop: tableActive ? stickyTop : undefined
180
- }), /*#__PURE__*/React.createElement(RowControls, {
181
- editorView: editorView,
182
- tableRef: tableRef,
183
- hoverRows: _hoverRows,
184
- hoveredRows: hoveredRows,
185
- isInDanger: isInDanger,
186
- isResizing: isResizing,
187
- selectRow: _selectRow,
188
- stickyTop: tableActive ? stickyTop : undefined
189
- })))))
147
+ }))))
190
148
  );
191
149
  };
192
150
  export default TableFloatingControls;
@@ -33,7 +33,6 @@ import UFOLoadHold from '@atlaskit/react-ufo/load-hold';
33
33
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
34
34
  import { autoSizeTable, clearHoverSelection } from '../pm-plugins/commands';
35
35
  import { autoScrollerFactory } from '../pm-plugins/drag-and-drop/utils/autoscrollers';
36
- import { getPluginState } from '../pm-plugins/plugin-factory';
37
36
  import { pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers/plugin-key';
38
37
  import { findStickyHeaderForTable } from '../pm-plugins/sticky-headers/util';
39
38
  import { META_KEYS } from '../pm-plugins/table-analytics';
@@ -523,14 +522,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
523
522
  this.wrapper.addEventListener('scroll', this.handleScrollDebounced, {
524
523
  passive: true
525
524
  });
526
- if (fg('disable-sticky-scrollbar-for-nested-tables')) {
527
- if (this.table && !this.isNestedInTable) {
528
- this.stickyScrollbar = new TableStickyScrollbar(this.wrapper, this.props.view);
529
- }
530
- } else {
531
- if (this.table) {
532
- this.stickyScrollbar = new TableStickyScrollbar(this.wrapper, this.props.view);
533
- }
525
+ if (this.table && !this.isNestedInTable) {
526
+ this.stickyScrollbar = new TableStickyScrollbar(this.wrapper, this.props.view);
534
527
  }
535
528
  if (isDragAndDropEnabled) {
536
529
  this.dragAndDropCleanupFn = combine.apply(void 0, _toConsumableArray(autoScrollerFactory({
@@ -803,13 +796,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
803
796
  options = _this$props1.options,
804
797
  isTableScalingEnabled = _this$props1.isTableScalingEnabled,
805
798
  getPos = _this$props1.getPos,
806
- getEditorFeatureFlags = _this$props1.getEditorFeatureFlags;
807
- var isInDanger = this.props.isInDanger;
799
+ getEditorFeatureFlags = _this$props1.getEditorFeatureFlags,
800
+ isInDanger = _this$props1.isInDanger;
808
801
  var table = findTable(view.state.selection);
809
- if (!fg('platform_editor_table_use_shared_state_hook_fg')) {
810
- var pluginState = getPluginState(view.state);
811
- isInDanger = pluginState.isInDanger;
812
- }
813
802
  var shouldScale = false;
814
803
  var shouldHandleColgroupUpdates = false;
815
804
  var _getEditorFeatureFlag5 = getEditorFeatureFlags(),
@@ -831,14 +820,21 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
831
820
  if (shouldHandleColgroupUpdates) {
832
821
  this.handleColgroupUpdates();
833
822
  }
834
- if (isInDanger && !table) {
835
- clearHoverSelection()(view.state, view.dispatch);
823
+
824
+ // table is always defined so this never runs
825
+ if (!expValEquals('platform_editor_table_drag_handle_hover', 'isEnabled', true)) {
826
+ if (isInDanger && !table) {
827
+ clearHoverSelection()(view.state, view.dispatch);
828
+ }
836
829
  }
837
830
  if ((_this$props$options1 = this.props.options) !== null && _this$props$options1 !== void 0 && _this$props$options1.isCommentEditor && allowTableResizing && !(options !== null && options !== void 0 && options.isTableScalingEnabled)) {
838
831
  this.removeInlineTableWidth();
839
832
  }
840
833
  if ((_this$wrapper = this.wrapper) !== null && _this$wrapper !== void 0 && _this$wrapper.parentElement && this.table && !this.overflowShadowsObserver) {
841
- if (this.props.isDragAndDropEnabled) {
834
+ // isDragAndDropEnabled will be false when the editorViewMode is 'live' and so the fix below is never triggered
835
+ // but the shadow observer must run async so its initial state is correct.
836
+ // note: when cleaning up platform_editor_table_drag_handle_hover entirely remove this nested if check incl. this.props.isDragAndDropEnabled
837
+ if (this.props.isDragAndDropEnabled || expValEquals('platform_editor_table_drag_handle_hover', 'isEnabled', true)) {
842
838
  // requestAnimationFrame is used here to fix a race condition issue
843
839
  // that happens when a table is nested in expand and expand's width is
844
840
  // changed via breakout button
@@ -944,25 +940,16 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
944
940
  isTableScalingEnabled = _this$props10.isTableScalingEnabled,
945
941
  allowTableResizing = _this$props10.allowTableResizing,
946
942
  allowTableAlignment = _this$props10.allowTableAlignment,
947
- selection = _this$props10.selection;
948
- var _this$props11 = this.props,
949
- isInDanger = _this$props11.isInDanger,
950
- hoveredRows = _this$props11.hoveredRows,
951
- hoveredCell = _this$props11.hoveredCell,
952
- isTableHovered = _this$props11.isTableHovered,
953
- isWholeTableInDanger = _this$props11.isWholeTableInDanger;
943
+ selection = _this$props10.selection,
944
+ isInDanger = _this$props10.isInDanger,
945
+ hoveredRows = _this$props10.hoveredRows,
946
+ hoveredCell = _this$props10.hoveredCell,
947
+ isTableHovered = _this$props10.isTableHovered,
948
+ isWholeTableInDanger = _this$props10.isWholeTableInDanger;
954
949
  var _this$state3 = this.state,
955
950
  showBeforeShadow = _this$state3.showBeforeShadow,
956
951
  showAfterShadow = _this$state3.showAfterShadow;
957
952
  var node = getNode();
958
- if (!fg('platform_editor_table_use_shared_state_hook_fg')) {
959
- var pluginState = getPluginState(view.state);
960
- isInDanger = pluginState.isInDanger;
961
- hoveredRows = pluginState.hoveredRows;
962
- hoveredCell = pluginState.hoveredCell;
963
- isTableHovered = pluginState.isTableHovered;
964
- isWholeTableInDanger = pluginState.isWholeTableInDanger;
965
- }
966
953
  var tableRef = this.table || undefined;
967
954
  var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
968
955
  var hasHeaderRow = containsHeaderRow(node);
@@ -1076,11 +1063,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
1076
1063
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1077
1064
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
1078
1065
  "data-testid": "sticky-sentinel-top"
1079
- }), fg('disable-sticky-scrollbar-for-nested-tables') ? !this.isNestedInTable && /*#__PURE__*/React.createElement("div", {
1080
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1081
- className: ClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_TOP,
1082
- "data-testid": "sticky-scrollbar-sentinel-top"
1083
- }) : /*#__PURE__*/React.createElement("div", {
1066
+ }), !this.isNestedInTable && /*#__PURE__*/React.createElement("div", {
1084
1067
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1085
1068
  className: ClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_TOP,
1086
1069
  "data-testid": "sticky-scrollbar-sentinel-top"
@@ -1126,7 +1109,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
1126
1109
  }
1127
1110
  }
1128
1111
  }
1129
- }, allowControls && colControls), fg('disable-sticky-scrollbar-for-nested-tables') ? !this.isNestedInTable ? /*#__PURE__*/React.createElement("div", {
1112
+ }, allowControls && colControls), !this.isNestedInTable ? /*#__PURE__*/React.createElement("div", {
1130
1113
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1131
1114
  className: ClassName.TABLE_STICKY_SCROLLBAR_CONTAINER,
1132
1115
  "data-vc-nvs": "true",
@@ -1153,27 +1136,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
1153
1136
  height: '100%'
1154
1137
  },
1155
1138
  "data-vc-nvs": "true"
1156
- }) : /*#__PURE__*/React.createElement("div", {
1157
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1158
- className: ClassName.TABLE_STICKY_SCROLLBAR_CONTAINER,
1159
- style: {
1160
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
1161
- height: "var(--ds-space-250, 20px)",
1162
- // MAX_BROWSER_SCROLLBAR_HEIGHT
1163
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
1164
- display: 'none',
1165
- // prevent unwanted scroll during table resize without removing scrollbar container from the dom
1166
- width: isResizing ? "var(--ds-space-0, 0px)" : '100%'
1167
- },
1168
- "data-vc-nvs": "true"
1169
- }, /*#__PURE__*/React.createElement("div", {
1170
- style: {
1171
- width: tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth,
1172
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
1173
- height: '100%'
1174
- },
1175
- "data-vc-nvs": "true"
1176
- })), /*#__PURE__*/React.createElement("div", {
1139
+ }), /*#__PURE__*/React.createElement("div", {
1177
1140
  contentEditable: false
1178
1141
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
1179
1142
  ,
@@ -1200,11 +1163,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
1200
1163
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1201
1164
  className: ClassName.TABLE_STICKY_SENTINEL_BOTTOM,
1202
1165
  "data-testid": "sticky-sentinel-bottom"
1203
- }), fg('disable-sticky-scrollbar-for-nested-tables') ? !this.isNestedInTable && /*#__PURE__*/React.createElement("div", {
1204
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1205
- className: ClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_BOTTOM,
1206
- "data-testid": "sticky-scrollbar-sentinel-bottom"
1207
- }) : /*#__PURE__*/React.createElement("div", {
1166
+ }), !this.isNestedInTable && /*#__PURE__*/React.createElement("div", {
1208
1167
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1209
1168
  className: ClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_BOTTOM,
1210
1169
  "data-testid": "sticky-scrollbar-sentinel-bottom"
@@ -12,20 +12,15 @@ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prot
12
12
  import React from 'react';
13
13
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
14
14
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
15
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
16
15
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
17
16
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
18
17
  import { TableMap } from '@atlaskit/editor-tables/table-map';
19
18
  import { fg } from '@atlaskit/platform-feature-flags';
20
19
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
21
20
  import { pluginConfig as getPluginConfig } from '../pm-plugins/create-plugin-config';
22
- import { pluginKey as tableDragAndDropPluginKey } from '../pm-plugins/drag-and-drop/plugin-key';
23
21
  import { getPluginState } from '../pm-plugins/plugin-factory';
24
- import { pluginKey } from '../pm-plugins/plugin-key';
25
- import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizing/plugin-key';
26
22
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
27
23
  import { isTableNested } from '../pm-plugins/utils/nodes';
28
- import TableComponent from './TableComponent';
29
24
  import { TableComponentWithSharedState } from './TableComponentWithSharedState';
30
25
  import { tableNodeSpecWithFixedToDOM } from './toDOM';
31
26
  var tableAttributes = function tableAttributes(node) {
@@ -211,129 +206,20 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
211
206
  }, {
212
207
  key: "render",
213
208
  value: function render(props, forwardRef) {
214
- var _props$pluginInjectio,
215
- _this4 = this;
216
- if (fg('platform_editor_table_use_shared_state_hook_fg')) {
217
- return /*#__PURE__*/React.createElement(TableComponentWithSharedState, {
218
- forwardRef: forwardRef,
219
- getNode: this.getNode,
220
- view: props.view,
221
- options: props.options,
222
- eventDispatcher: props.eventDispatcher,
223
- api: props.pluginInjectionApi,
224
- allowColumnResizing: props.allowColumnResizing,
225
- allowTableAlignment: props.allowTableAlignment,
226
- allowTableResizing: props.allowTableResizing,
227
- allowControls: props.allowControls,
228
- getPos: props.getPos,
229
- getEditorFeatureFlags: props.getEditorFeatureFlags,
230
- dispatchAnalyticsEvent: props.dispatchAnalyticsEvent
231
- });
232
- }
233
- // Please, do not copy or use this kind of code below
234
- // @ts-ignore
235
- var fakePluginKey = {
236
- key: 'widthPlugin$',
237
- getState: function getState(state) {
238
- // Ignored via go/ees005
239
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
- return state['widthPlugin$'];
241
- }
242
- };
243
-
244
- // Please, do not copy or use this kind of code below
245
- // @ts-ignore
246
- var fakeMediaPluginKey = {
247
- key: 'mediaPlugin$',
248
- getState: function getState(state) {
249
- // Ignored via go/ees005
250
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
- return state['mediaPlugin$'];
252
- }
253
- };
254
- return /*#__PURE__*/React.createElement(WithPluginState, {
255
- plugins: {
256
- pluginState: pluginKey,
257
- tableResizingPluginState: tableResizingPluginKey,
258
- tableWidthPluginState: tableWidthPluginKey,
259
- widthPlugin: fakePluginKey,
260
- mediaState: fakeMediaPluginKey,
261
- tableDragAndDropState: tableDragAndDropPluginKey,
262
- limitedModePlugin: (_props$pluginInjectio = props.pluginInjectionApi) === null || _props$pluginInjectio === void 0 || (_props$pluginInjectio = _props$pluginInjectio.limitedMode) === null || _props$pluginInjectio === void 0 || (_props$pluginInjectio = _props$pluginInjectio.sharedState.currentState()) === null || _props$pluginInjectio === void 0 ? void 0 : _props$pluginInjectio.limitedModePluginKey
263
- },
264
- editorView: props.view,
265
- render: function render(pluginStates) {
266
- var _props$options, _pluginStates$limited, _pluginStates$limited2;
267
- var tableResizingPluginState = pluginStates.tableResizingPluginState,
268
- tableWidthPluginState = pluginStates.tableWidthPluginState,
269
- pluginState = pluginStates.pluginState,
270
- mediaState = pluginStates.mediaState;
271
- var containerWidth = props.getEditorContainerWidth();
272
- var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
273
- var isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
274
-
275
- /**
276
- * ED-19810
277
- * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
278
- * directly to confluence since this bug is now in production.
279
- */
280
- var tablePos;
281
- try {
282
- tablePos = props.getPos ? props.getPos() : undefined;
283
- } catch (e) {
284
- tablePos = undefined;
285
- }
286
-
287
- // Ignored via go/ees005
288
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
289
- var tableActive = tablePos === pluginState.tablePos && !isTableResizing;
290
- return /*#__PURE__*/React.createElement(TableComponent, {
291
- view: props.view,
292
- allowColumnResizing: props.allowColumnResizing,
293
- eventDispatcher: props.eventDispatcher,
294
- getPos: props.getPos,
295
- isMediaFullscreen: mediaState === null || mediaState === void 0 ? void 0 : mediaState.isFullscreen,
296
- options: props.options
297
- // Ignored via go/ees005
298
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
299
- // Ignored via go/ees005
300
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
301
- ,
302
- allowControls: pluginState.pluginConfig.allowControls
303
- // Ignored via go/ees005
304
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
305
- ,
306
- isHeaderRowEnabled: pluginState.isHeaderRowEnabled
307
- // Ignored via go/ees005
308
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
309
- ,
310
- isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled
311
- // Ignored via go/ees005
312
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
313
- ,
314
- isDragAndDropEnabled: pluginState.isDragAndDropEnabled,
315
- isTableScalingEnabled: (_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.isTableScalingEnabled // this.options?.isTableScalingEnabled same as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
316
- ,
317
- allowTableAlignment: props.allowTableAlignment,
318
- allowTableResizing: props.allowTableResizing,
319
- tableActive: tableActive
320
- // Ignored via go/ees005
321
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
322
- ,
323
- ordering: pluginState.ordering,
324
- isResizing: isResizing,
325
- getNode: _this4.getNode
326
- // Ignored via go/ees005
327
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
328
- ,
329
- containerWidth: containerWidth,
330
- contentDOM: forwardRef,
331
- getEditorFeatureFlags: props.getEditorFeatureFlags,
332
- dispatchAnalyticsEvent: props.dispatchAnalyticsEvent,
333
- pluginInjectionApi: props.pluginInjectionApi,
334
- limitedMode: (_pluginStates$limited = (_pluginStates$limited2 = pluginStates.limitedModePlugin) === null || _pluginStates$limited2 === void 0 ? void 0 : _pluginStates$limited2.documentSizeBreachesThreshold) !== null && _pluginStates$limited !== void 0 ? _pluginStates$limited : false
335
- });
336
- }
209
+ return /*#__PURE__*/React.createElement(TableComponentWithSharedState, {
210
+ forwardRef: forwardRef,
211
+ getNode: this.getNode,
212
+ view: props.view,
213
+ options: props.options,
214
+ eventDispatcher: props.eventDispatcher,
215
+ api: props.pluginInjectionApi,
216
+ allowColumnResizing: props.allowColumnResizing,
217
+ allowTableAlignment: props.allowTableAlignment,
218
+ allowTableResizing: props.allowTableResizing,
219
+ allowControls: props.allowControls,
220
+ getPos: props.getPos,
221
+ getEditorFeatureFlags: props.getEditorFeatureFlags,
222
+ dispatchAnalyticsEvent: props.dispatchAnalyticsEvent
337
223
  });
338
224
  }
339
225
  }, {
@@ -198,4 +198,36 @@ export var useMeasureFramerate = function useMeasureFramerate() {
198
198
  endMeasure: endMeasure,
199
199
  countFrames: countFrames
200
200
  };
201
+ };
202
+ var tableContainerNodes = new Set(['layoutSection', 'layoutColumn', 'expand', 'nestedExpand', 'extension', 'bodiedExtension', 'multiBodiedExtension', 'extensionFrame', 'table', 'tableCell', 'tableHeader', 'tableRow']);
203
+ export var getWidthInfoPayload = function getWidthInfoPayload(editorView, editorWidth) {
204
+ var tablesInfo = [];
205
+ editorView.state.doc.nodesBetween(0, editorView.state.doc.content.size, function (node, pos, parent) {
206
+ if (!tableContainerNodes.has(node.type.name)) {
207
+ return false;
208
+ }
209
+ if (node.type.name === 'table') {
210
+ var _domAtPos$node;
211
+ var domAtPos = editorView.domAtPos(pos + 1);
212
+ var table = (_domAtPos$node = domAtPos.node) === null || _domAtPos$node === void 0 ? void 0 : _domAtPos$node.parentElement;
213
+ var isNestedTable = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'tableCell' || (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'tableHeader';
214
+ if (table instanceof HTMLTableElement) {
215
+ tablesInfo.push({
216
+ tableWidth: table.scrollWidth,
217
+ isNestedTable: isNestedTable,
218
+ hasScrollbar: table.parentElement ? (table === null || table === void 0 ? void 0 : table.parentElement.clientWidth) < table.scrollWidth : false
219
+ });
220
+ }
221
+ }
222
+ });
223
+ return {
224
+ action: TABLE_ACTION.TABLE_WIDTH_INFO,
225
+ actionSubject: ACTION_SUBJECT.TABLE,
226
+ attributes: {
227
+ editorWidth: editorWidth,
228
+ tableWidthInfo: tablesInfo,
229
+ mode: 'editor'
230
+ },
231
+ eventType: EVENT_TYPE.OPERATIONAL
232
+ };
201
233
  };
@@ -15,6 +15,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
15
15
  import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
16
16
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
17
17
  import { fg } from '@atlaskit/platform-feature-flags';
18
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
18
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
19
20
  import { tableNodeSpecWithFixedToDOM } from './nodeviews/toDOM';
20
21
  import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
@@ -38,6 +39,7 @@ import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap'
38
39
  import { createPlugin as createSizeSelectorPlugin, pluginKey as sizeSelectorPluginKey } from './pm-plugins/table-size-selector';
39
40
  import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
40
41
  import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
42
+ import { getWidthInfoPayload } from './pm-plugins/utils/analytics';
41
43
  import { createTableWithWidth } from './pm-plugins/utils/create';
42
44
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
43
45
  import { ContentComponent } from './ui/ContentComponent';
@@ -46,6 +48,9 @@ var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
46
48
  return {};
47
49
  };
48
50
 
51
+ // we want to calculate all the table widths (which causes reflows) after the editor has finished loading to mitigate performance impact
52
+ var TABLE_WIDTH_INFO_TIMEOUT = 10000;
53
+
49
54
  /**
50
55
  * Table plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
51
56
  * from `@atlaskit/editor-core`.
@@ -401,13 +406,45 @@ var tablePlugin = function tablePlugin(_ref) {
401
406
  }
402
407
  }, {
403
408
  name: 'tableGetEditorViewReferencePlugin',
404
- plugin: function plugin() {
409
+ plugin: function plugin(_ref17) {
410
+ var dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
405
411
  return new SafePlugin({
406
412
  view: function view(editorView) {
407
413
  editorViewRef.current = editorView;
414
+ var setTimeoutID;
415
+ var rafID;
416
+ var ricID;
417
+ if (expValEquals('platform_editor_editor_width_analytics', 'isEnabled', true)) {
418
+ // send statistics about the widths of the tables on the page for alerting
419
+ // only send this event once, after the editorView is first initialised
420
+ setTimeoutID = setTimeout(function () {
421
+ var requestIdleCallbackFn = function requestIdleCallbackFn() {
422
+ var _api$width$sharedStat2;
423
+ var editorWidth = api === null || api === void 0 || (_api$width$sharedStat2 = api.width.sharedState.currentState()) === null || _api$width$sharedStat2 === void 0 ? void 0 : _api$width$sharedStat2.width;
424
+ if (editorWidth && editorViewRef.current) {
425
+ dispatchAnalyticsEvent(getWidthInfoPayload(editorViewRef.current, editorWidth));
426
+ }
427
+ };
428
+ if (window && typeof window.requestIdleCallback === 'function') {
429
+ ricID = window.requestIdleCallback(requestIdleCallbackFn);
430
+ } else if (window && typeof window.requestAnimationFrame === 'function') {
431
+ // requestIdleCallback is not supported in safari, fallback to requestAnimationFrame
432
+ rafID = window.requestAnimationFrame(requestIdleCallbackFn);
433
+ }
434
+ }, TABLE_WIDTH_INFO_TIMEOUT);
435
+ }
408
436
  return {
409
437
  destroy: function destroy() {
410
438
  editorViewRef.current = null;
439
+ if (setTimeoutID) {
440
+ clearTimeout(setTimeoutID);
441
+ }
442
+ if (rafID) {
443
+ window.cancelAnimationFrame(rafID);
444
+ }
445
+ if (ricID) {
446
+ window.cancelIdleCallback(ricID);
447
+ }
411
448
  }
412
449
  };
413
450
  }
@@ -415,8 +452,8 @@ var tablePlugin = function tablePlugin(_ref) {
415
452
  }
416
453
  }, {
417
454
  name: 'tableSizeSelectorPlugin',
418
- plugin: function plugin(_ref17) {
419
- var dispatch = _ref17.dispatch;
455
+ plugin: function plugin(_ref18) {
456
+ var dispatch = _ref18.dispatch;
420
457
  return isTableSelectorEnabled ? createSizeSelectorPlugin(dispatch) : undefined;
421
458
  }
422
459
  }];
@@ -433,12 +470,12 @@ var tablePlugin = function tablePlugin(_ref) {
433
470
  }
434
471
  return plugins;
435
472
  },
436
- contentComponent: function contentComponent(_ref18) {
437
- var editorView = _ref18.editorView,
438
- popupsMountPoint = _ref18.popupsMountPoint,
439
- popupsBoundariesElement = _ref18.popupsBoundariesElement,
440
- popupsScrollableElement = _ref18.popupsScrollableElement,
441
- dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
473
+ contentComponent: function contentComponent(_ref19) {
474
+ var editorView = _ref19.editorView,
475
+ popupsMountPoint = _ref19.popupsMountPoint,
476
+ popupsBoundariesElement = _ref19.popupsBoundariesElement,
477
+ popupsScrollableElement = _ref19.popupsScrollableElement,
478
+ dispatchAnalyticsEvent = _ref19.dispatchAnalyticsEvent;
442
479
  return /*#__PURE__*/React.createElement(ContentComponent, {
443
480
  api: api,
444
481
  editorView: editorView,
@@ -453,8 +490,8 @@ var tablePlugin = function tablePlugin(_ref) {
453
490
  });
454
491
  },
455
492
  pluginsOptions: {
456
- quickInsert: function quickInsert(_ref19) {
457
- var formatMessage = _ref19.formatMessage;
493
+ quickInsert: function quickInsert(_ref20) {
494
+ var formatMessage = _ref20.formatMessage;
458
495
  return [{
459
496
  id: 'table',
460
497
  title: formatMessage(messages.table),
@@ -525,8 +562,8 @@ var tablePlugin = function tablePlugin(_ref) {
525
562
  return editorViewRef.current;
526
563
  }, options, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent)(pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions))
527
564
  },
528
- usePluginHook: function usePluginHook(_ref20) {
529
- var editorView = _ref20.editorView;
565
+ usePluginHook: function usePluginHook(_ref21) {
566
+ var editorView = _ref21.editorView;
530
567
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['editorViewMode'], function (states) {
531
568
  var _states$editorViewMod;
532
569
  return {