@atlaskit/editor-plugin-table 5.3.7 → 5.3.8

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 (63) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +4 -4
  3. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -2
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  5. package/dist/cjs/plugins/table/types.js +1 -1
  6. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +72 -0
  7. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +20 -3
  8. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  9. package/dist/cjs/plugins/table/ui/ui-styles.js +19 -15
  10. package/dist/cjs/plugins/table/utils/decoration.js +3 -24
  11. package/dist/cjs/plugins/table/utils/dom.js +1 -4
  12. package/dist/cjs/plugins/table/utils/index.js +0 -6
  13. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +4 -4
  14. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -2
  15. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  16. package/dist/es2019/plugins/table/types.js +1 -1
  17. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +60 -0
  18. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +20 -3
  19. package/dist/es2019/plugins/table/ui/common-styles.js +2 -5
  20. package/dist/es2019/plugins/table/ui/ui-styles.js +29 -30
  21. package/dist/es2019/plugins/table/utils/decoration.js +3 -24
  22. package/dist/es2019/plugins/table/utils/dom.js +0 -1
  23. package/dist/es2019/plugins/table/utils/index.js +1 -1
  24. package/dist/esm/plugins/table/nodeviews/TableComponent.js +4 -4
  25. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -2
  26. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  27. package/dist/esm/plugins/table/types.js +1 -1
  28. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +63 -0
  29. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +20 -3
  30. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  31. package/dist/esm/plugins/table/ui/ui-styles.js +18 -14
  32. package/dist/esm/plugins/table/utils/decoration.js +3 -24
  33. package/dist/esm/plugins/table/utils/dom.js +0 -3
  34. package/dist/esm/plugins/table/utils/index.js +1 -1
  35. package/dist/types/plugins/table/types.d.ts +1 -1
  36. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +15 -0
  37. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -0
  38. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  39. package/dist/types/plugins/table/utils/decoration.d.ts +2 -2
  40. package/dist/types/plugins/table/utils/dom.d.ts +0 -1
  41. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  42. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -1
  43. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +15 -0
  44. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -0
  45. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  46. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -2
  47. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +0 -1
  48. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  49. package/package.json +1 -1
  50. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +2 -2
  51. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +84 -34
  52. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +5 -2
  53. package/src/plugins/table/nodeviews/TableComponent.tsx +15 -15
  54. package/src/plugins/table/pm-plugins/decorations/plugin.ts +3 -2
  55. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -1
  56. package/src/plugins/table/types.ts +1 -1
  57. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +100 -0
  58. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +30 -8
  59. package/src/plugins/table/ui/common-styles.ts +2 -4
  60. package/src/plugins/table/ui/ui-styles.ts +30 -30
  61. package/src/plugins/table/utils/decoration.ts +3 -45
  62. package/src/plugins/table/utils/dom.ts +0 -4
  63. package/src/plugins/table/utils/index.ts +0 -1
@@ -231,12 +231,6 @@ Object.defineProperty(exports, "isColumnDeleteButtonVisible", {
231
231
  return _columnControls.isColumnDeleteButtonVisible;
232
232
  }
233
233
  });
234
- Object.defineProperty(exports, "isColumnDragControlsDecorations", {
235
- enumerable: true,
236
- get: function get() {
237
- return _dom.isColumnDragControlsDecorations;
238
- }
239
- });
240
234
  Object.defineProperty(exports, "isCornerButton", {
241
235
  enumerable: true,
242
236
  get: function get() {
@@ -494,13 +494,13 @@ class TableComponent extends React.Component {
494
494
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
495
495
  stickyHeader: this.state.stickyHeader
496
496
  }));
497
- const colControls = /*#__PURE__*/React.createElement("div", {
498
- className: ClassName.COLUMN_CONTROLS_WRAPPER
499
- }, /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
497
+ const colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
500
498
  editorView: view,
501
499
  tableRef: tableRef,
502
500
  tableActive: tableActive,
503
501
  hoveredRows: hoveredRows,
502
+ hoveredCell: hoveredCell,
503
+ isResizing: isResizing,
504
504
  ordering: ordering,
505
505
  hasHeaderRow: hasHeaderRow
506
506
  // pass `selection` and `tableHeight` to control re-render
@@ -509,7 +509,7 @@ class TableComponent extends React.Component {
509
509
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
510
510
  stickyHeader: this.state.stickyHeader,
511
511
  getEditorFeatureFlags: this.props.getEditorFeatureFlags
512
- }));
512
+ });
513
513
  const shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
514
514
  const shadowStyle = memoizeOne(visible => ({
515
515
  visibility: visible ? 'visible' : 'hidden'
@@ -2,6 +2,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { pluginKey as tablePluginKey } from '../plugin-key';
6
7
  import { pluginKey as tableWidthPluginKey } from '../table-width';
7
8
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
@@ -13,8 +14,8 @@ export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newStat
13
14
  const wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
14
15
  const changedResizing = isResizing !== wasResizing;
15
16
 
16
- // Remove column controls when resizing
17
- if (isResizing) {
17
+ // Remove column controls when resizing and don't add column decoration controls when DnD enabled
18
+ if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
18
19
  return DecorationSet.empty;
19
20
  } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing || ((_tr$getMeta = tr.getMeta(tablePluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type) === 'HOVER_CELL') {
20
21
  return buildColumnControlsDecorations({
@@ -25,7 +25,6 @@ const maybeUpdateColumnControlsDecoration = ({
25
25
  decorationSet,
26
26
  tr
27
27
  }) => {
28
- var _meta$data;
29
28
  const table = findTable(tr.selection);
30
29
  const meta = tr.getMeta(tablePluginKey);
31
30
 
@@ -33,7 +32,7 @@ const maybeUpdateColumnControlsDecoration = ({
33
32
  if (!table && (meta === null || meta === void 0 ? void 0 : meta.type) !== 'HOVER_CELL') {
34
33
  return decorationSet;
35
34
  }
36
- return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection, meta === null || meta === void 0 ? void 0 : (_meta$data = meta.data) === null || _meta$data === void 0 ? void 0 : _meta$data.hoveredCell), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
35
+ return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
37
36
  };
38
37
 
39
38
  // @see: https://product-fabric.atlassian.net/browse/ED-7304
@@ -78,7 +78,7 @@ export const TableCssClassName = {
78
78
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
79
79
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
80
80
  /** Controls with drag handle */
81
- COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: `${tablePrefixSelector}-column-controls-decoration-with-drag`,
81
+ COLUMN_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-column-controls-with-drag`,
82
82
  ROW_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-row-controls-with-drag`,
83
83
  DRAG_HANDLE_BUTTON_CONTAINER: `${tablePrefixSelector}-drag-handle-button-container`,
84
84
  /** Other classes */
@@ -0,0 +1,60 @@
1
+ import React, { useMemo } from 'react';
2
+ import { TableCssClassName as ClassName } from '../../../types';
3
+ import { getColumnsWidths, getRowHeights } from '../../../utils';
4
+ import { DragHandle } from '../../DragHandle';
5
+ export const ColumnControls = ({
6
+ editorView,
7
+ tableActive,
8
+ tableRef,
9
+ hoveredCell,
10
+ isResizing,
11
+ tableHeight,
12
+ stickyTop,
13
+ localId
14
+ }) => {
15
+ var _rowHeights$;
16
+ const rowHeights = useMemo(() => {
17
+ // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
18
+ if (tableRef && !!tableHeight) {
19
+ return getRowHeights(tableRef);
20
+ }
21
+ return [0];
22
+ }, [tableRef, tableHeight]);
23
+ if (!tableRef) {
24
+ return null;
25
+ }
26
+ const firstRow = tableRef.querySelector('tr');
27
+ const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
28
+ const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
29
+ const colWidths = getColumnsWidths(editorView);
30
+ const widths = colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ');
31
+ const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
32
+ const onClick = (index, event) => {};
33
+ const onMouseOver = () => {};
34
+ const onMouseOut = () => {};
35
+ return /*#__PURE__*/React.createElement("div", {
36
+ className: ClassName.COLUMN_CONTROLS_WITH_DRAG
37
+ }, /*#__PURE__*/React.createElement("div", {
38
+ className: ClassName.COLUMN_CONTROLS_INNER,
39
+ "data-testid": "table-floating-column-controls",
40
+ style: {
41
+ gridTemplateColumns: widths,
42
+ marginTop
43
+ }
44
+ }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
45
+ style: {
46
+ gridColumn: `${colIndex + 1} / span 1`,
47
+ marginTop: `-15px`
48
+ },
49
+ "data-column-control-index": colIndex,
50
+ "data-testid": "table-floating-column-control"
51
+ }, /*#__PURE__*/React.createElement(DragHandle, {
52
+ direction: "column",
53
+ indexes: [],
54
+ onClick: event => onClick(colIndex, event),
55
+ onMouseOver: onMouseOver,
56
+ onMouseOut: onMouseOut,
57
+ tableLocalId: localId || ''
58
+ }))));
59
+ };
60
+ export default ColumnControls;
@@ -1,11 +1,16 @@
1
1
  import React, { useEffect, useMemo, useState } from 'react';
2
+ import ReactDOM from 'react-dom';
2
3
  import { findTable } from '@atlaskit/editor-tables';
4
+ import { TableCssClassName as ClassName } from '../../types';
5
+ import { ColumnControls } from './ColumnControls';
3
6
  import { ColumnDropTargets } from './ColumnDropTargets';
4
7
  export const TableFloatingColumnControls = ({
5
8
  editorView,
6
9
  tableRef,
7
10
  tableActive,
8
11
  hasHeaderRow,
12
+ hoveredCell,
13
+ isResizing,
9
14
  stickyHeader,
10
15
  selection
11
16
  }) => {
@@ -46,15 +51,27 @@ export const TableFloatingColumnControls = ({
46
51
  return null;
47
52
  }
48
53
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
49
- return /*#__PURE__*/React.createElement("div", {
54
+ const mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
55
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
56
+ className: ClassName.COLUMN_CONTROLS_WRAPPER
57
+ }, /*#__PURE__*/React.createElement("div", {
50
58
  onMouseDown: e => e.preventDefault(),
51
59
  "data-testid": "table-floating-column-controls-wrapper"
52
- }, tableActive && /*#__PURE__*/React.createElement(ColumnDropTargets, {
60
+ }, /*#__PURE__*/React.createElement(ColumnControls, {
53
61
  editorView: editorView,
62
+ hoveredCell: hoveredCell,
54
63
  tableRef: tableRef,
64
+ isResizing: isResizing,
65
+ tableActive: tableActive,
55
66
  stickyTop: tableActive ? stickyTop : undefined,
56
67
  tableHeight: tableRect.height,
57
68
  localId: selectedLocalId
58
- }));
69
+ }), /*#__PURE__*/React.createElement(ColumnDropTargets, {
70
+ editorView: editorView,
71
+ tableRef: tableRef,
72
+ stickyTop: tableActive ? stickyTop : undefined,
73
+ tableHeight: tableRect.height,
74
+ localId: selectedLocalId
75
+ }))), mountTo);
59
76
  };
60
77
  export default TableFloatingColumnControls;
@@ -7,7 +7,7 @@ import { B300, N0, N20A, N300, N40A, R500 } from '@atlaskit/theme/colors';
7
7
  import { fontSize } from '@atlaskit/theme/constants';
8
8
  import { TableCssClassName as ClassName } from '../types';
9
9
  import { columnControlsDecorationHeight, resizeHandlerAreaWidth, resizeLineWidth, rowControlsZIndex, stickyHeaderBorderBottomWidth, stickyRowOffsetTop, tableBorderColor, tableBorderDeleteColor, tableBorderRadiusSize, tableBorderSelectedColor, tableCellBackgroundColor, tableCellDeleteColor, tableCellSelectedColor, tableControlsSpacing, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tablePadding, tableScrollbarOffset, tableTextColor, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
10
- import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle } from './ui-styles';
10
+ import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle, rowControlsWrapperDotStyle } from './ui-styles';
11
11
  const cornerControlHeight = tableToolbarSize + 1;
12
12
 
13
13
  /*
@@ -487,6 +487,7 @@ export const tableStyles = props => {
487
487
  ${breakoutWidthStyling()}
488
488
 
489
489
  ${columnControlsDecoration(props)};
490
+ ${rowControlsWrapperDotStyle(props)};
490
491
 
491
492
  /* Corner controls */
492
493
  .${ClassName.CORNER_CONTROLS} {
@@ -730,10 +731,6 @@ export const tableStyles = props => {
730
731
  margin-top: 0;
731
732
  }
732
733
 
733
- .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} + * {
734
- margin-top: 0;
735
- }
736
-
737
734
  /*
738
735
  * Headings have a top margin by default, but we don't want this on the
739
736
  * first heading within table header cells.
@@ -291,26 +291,49 @@ export const floatingColumnControls = props => {
291
291
  .${ClassName.COLUMN_DROP_TARGET_CONTROLS} {
292
292
  box-sizing: border-box;
293
293
  position: absolute;
294
+ top: 0;
295
+ z-index: -1;
294
296
 
295
297
  .${ClassName.COLUMN_CONTROLS_INNER} {
296
298
  display: flex;
297
299
  flex-direction: row;
298
300
  }
299
301
  }
302
+
303
+ .${ClassName.COLUMN_CONTROLS_WITH_DRAG} {
304
+ box-sizing: border-box;
305
+
306
+ .${ClassName.COLUMN_CONTROLS_INNER} {
307
+ display: grid;
308
+ justify-items: center;
309
+ }
310
+ }
300
311
  `;
301
312
  };
302
- export const columnControlsDecoration = props => {
313
+ export const rowControlsWrapperDotStyle = props => {
303
314
  if (getBooleanFF('platform.editor.table.drag-and-drop')) {
304
315
  return css`
305
- .${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} {
316
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
317
+ display: none;
318
+ }
319
+ `;
320
+ } else {
321
+ return css`
322
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
323
+ content: ' ';
324
+ background-color: ${tableBorderColor(props)};
306
325
  position: absolute;
307
- // kinda a hacky way to center an element with absolute positioning inside a relative element
308
- top: 25%;
309
- left: 50%;
310
- transform: translate(-50%, -100%);
326
+ height: ${lineMarkerSize}px;
327
+ width: ${lineMarkerSize}px;
328
+ border-radius: 50%;
329
+ pointer-events: none;
330
+ top: -${tableToolbarSize + tableCellBorderWidth}px;
331
+ right: -1px;
311
332
  }
312
333
  `;
313
334
  }
335
+ };
336
+ export const columnControlsDecoration = props => {
314
337
  if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
315
338
  return css`
316
339
  .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
@@ -355,18 +378,6 @@ export const columnControlsDecoration = props => {
355
378
  // floating dot for adding column button - overriding style on last column to avoid scroll
356
379
  ${getFloatingDotOverrides(props)}
357
380
 
358
- div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
359
- content: ' ';
360
- background-color: ${tableBorderColor(props)};
361
- position: absolute;
362
- height: ${lineMarkerSize}px;
363
- width: ${lineMarkerSize}px;
364
- border-radius: 50%;
365
- pointer-events: none;
366
- top: -${tableToolbarSize + tableCellBorderWidth}px;
367
- right: -1px;
368
- }
369
-
370
381
  .${ClassName.WITH_CONTROLS} .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
371
382
  display: block;
372
383
  }
@@ -470,18 +481,6 @@ export const columnControlsDecoration = props => {
470
481
  // floating dot for adding column button - overriding style on last column to avoid scroll
471
482
  ${getFloatingDotOverrides(props)}
472
483
 
473
- div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
474
- content: ' ';
475
- background-color: ${tableBorderColor(props)};
476
- position: absolute;
477
- height: ${lineMarkerSize}px;
478
- width: ${lineMarkerSize}px;
479
- border-radius: 50%;
480
- pointer-events: none;
481
- top: -${tableToolbarSize + tableCellBorderWidth}px;
482
- right: -1px;
483
- }
484
-
485
484
  .${ClassName.WITH_CONTROLS} .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
486
485
  display: block;
487
486
  }
@@ -11,7 +11,6 @@ import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tab
11
11
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
12
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
13
13
  import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
14
- import { DragHandle } from '../ui/DragHandle';
15
14
  const filterDecorationByKey = (key, decorationSet) => decorationSet.find(undefined, undefined, spec => spec.key.indexOf(key) > -1);
16
15
  export const findColumnControlSelectedDecoration = decorationSet => filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
17
16
  export const findControlsHoverDecoration = decorationSet => filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
@@ -130,30 +129,10 @@ export const createColumnSelectedDecoration = tr => {
130
129
  });
131
130
  });
132
131
  };
133
- export const createColumnControlsDecoration = (selection, hoverLocation) => {
134
- // todo: issue here where table may not be selected yet
132
+ export const createColumnControlsDecoration = selection => {
135
133
  const cells = getCellsInRow(0)(selection) || [];
136
- const table = findTable(selection);
137
- if (getBooleanFF('platform.editor.table.drag-and-drop') && hoverLocation && !Number.isNaN(hoverLocation === null || hoverLocation === void 0 ? void 0 : hoverLocation.colIndex) && table) {
138
- const colIndex = hoverLocation.colIndex;
139
- const cell = cells[colIndex];
140
- return [Decoration.widget(cell.pos + 1, () => {
141
- const element = document.createElement('div');
142
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG);
143
- ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
144
- tableLocalId: table.node.attrs.localId,
145
- direction: 'column',
146
- indexes: [colIndex]
147
- }), element);
148
- return element;
149
- }, {
150
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${colIndex}`,
151
- // this decoration should be the first one, even before gap cursor.
152
- side: -100,
153
- destroy: node => {
154
- ReactDOM.unmountComponentAtNode(node);
155
- }
156
- })];
134
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
135
+ return [];
157
136
  } else {
158
137
  let index = 0;
159
138
  return cells.map(cell => {
@@ -9,7 +9,6 @@ export const isCornerButton = node => containsClassName(node, ClassName.CONTROLS
9
9
  export const isInsertRowButton = node => containsClassName(node, ClassName.CONTROLS_INSERT_ROW) || closestElement(node, `.${ClassName.CONTROLS_INSERT_ROW}`) || containsClassName(node, ClassName.CONTROLS_BUTTON_OVERLAY) && closestElement(node, `.${ClassName.ROW_CONTROLS}`);
10
10
  export const getColumnOrRowIndex = target => [parseInt(target.getAttribute('data-start-index') || '-1', 10), parseInt(target.getAttribute('data-end-index') || '-1', 10)];
11
11
  export const isColumnControlsDecorations = node => containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS);
12
- export const isColumnDragControlsDecorations = node => containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG) || closestElement(node, `.${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG}`);
13
12
  export const isRowControlsButton = node => containsClassName(node, ClassName.ROW_CONTROLS_BUTTON) || containsClassName(node, ClassName.NUMBERED_COLUMN_BUTTON);
14
13
  export const isRowDragControlsButton = node => containsClassName(node, ClassName.ROW_CONTROLS_WITH_DRAG) || closestElement(node, `.${ClassName.ROW_CONTROLS_WITH_DRAG}`);
15
14
  export const isResizeHandleDecoration = node => containsClassName(node, ClassName.RESIZE_HANDLE_DECORATION);
@@ -2,7 +2,7 @@ export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, is
2
2
  export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnInsertLine, createColumnLineResize, createRowInsertLine } from './decoration';
3
3
  export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell } from './paste';
5
- export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isColumnDragControlsDecorations, isRowDragControlsButton, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
5
+ export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowDragControlsButton, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
6
6
  export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames } from './column-controls';
7
7
  export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getRowsParams, getRowClassNames, copyPreviousRow } from './row-controls';
8
8
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
@@ -489,13 +489,13 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
489
489
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
490
490
  stickyHeader: this.state.stickyHeader
491
491
  }));
492
- var colControls = /*#__PURE__*/React.createElement("div", {
493
- className: ClassName.COLUMN_CONTROLS_WRAPPER
494
- }, /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
492
+ var colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
495
493
  editorView: view,
496
494
  tableRef: tableRef,
497
495
  tableActive: tableActive,
498
496
  hoveredRows: hoveredRows,
497
+ hoveredCell: hoveredCell,
498
+ isResizing: isResizing,
499
499
  ordering: ordering,
500
500
  hasHeaderRow: hasHeaderRow
501
501
  // pass `selection` and `tableHeight` to control re-render
@@ -504,7 +504,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
504
504
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
505
505
  stickyHeader: this.state.stickyHeader,
506
506
  getEditorFeatureFlags: this.props.getEditorFeatureFlags
507
- }));
507
+ });
508
508
  var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
509
509
  var shadowStyle = memoizeOne(function (visible) {
510
510
  return {
@@ -2,6 +2,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { pluginKey as tablePluginKey } from '../plugin-key';
6
7
  import { pluginKey as tableWidthPluginKey } from '../table-width';
7
8
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
@@ -15,8 +16,8 @@ export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr
15
16
  var wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
16
17
  var changedResizing = isResizing !== wasResizing;
17
18
 
18
- // Remove column controls when resizing
19
- if (isResizing) {
19
+ // Remove column controls when resizing and don't add column decoration controls when DnD enabled
20
+ if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
20
21
  return DecorationSet.empty;
21
22
  } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing || ((_tr$getMeta = tr.getMeta(tablePluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type) === 'HOVER_CELL') {
22
23
  return buildColumnControlsDecorations({
@@ -24,7 +24,6 @@ var maybeUpdateColumnSelectedDecoration = function maybeUpdateColumnSelectedDeco
24
24
  return updateDecorations(tr.doc, decorationSet, createColumnSelectedDecoration(tr), TableDecorations.COLUMN_SELECTED);
25
25
  };
26
26
  var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDecoration(_ref3) {
27
- var _meta$data;
28
27
  var decorationSet = _ref3.decorationSet,
29
28
  tr = _ref3.tr;
30
29
  var table = findTable(tr.selection);
@@ -34,7 +33,7 @@ var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDeco
34
33
  if (!table && (meta === null || meta === void 0 ? void 0 : meta.type) !== 'HOVER_CELL') {
35
34
  return decorationSet;
36
35
  }
37
- return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection, meta === null || meta === void 0 || (_meta$data = meta.data) === null || _meta$data === void 0 ? void 0 : _meta$data.hoveredCell), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
36
+ return updateDecorations(tr.doc, decorationSet, createColumnControlsDecoration(tr.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
38
37
  };
39
38
 
40
39
  // @see: https://product-fabric.atlassian.net/browse/ED-7304
@@ -80,7 +80,7 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
80
80
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-column-marker"),
81
81
  CONTROLS_CORNER_BUTTON: "".concat(tablePrefixSelector, "-corner-button"),
82
82
  /** Controls with drag handle */
83
- COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: "".concat(tablePrefixSelector, "-column-controls-decoration-with-drag"),
83
+ COLUMN_CONTROLS_WITH_DRAG: "".concat(tablePrefixSelector, "-column-controls-with-drag"),
84
84
  ROW_CONTROLS_WITH_DRAG: "".concat(tablePrefixSelector, "-row-controls-with-drag"),
85
85
  DRAG_HANDLE_BUTTON_CONTAINER: "".concat(tablePrefixSelector, "-drag-handle-button-container"),
86
86
  /** Other classes */
@@ -0,0 +1,63 @@
1
+ import React, { useMemo } from 'react';
2
+ import { TableCssClassName as ClassName } from '../../../types';
3
+ import { getColumnsWidths, getRowHeights } from '../../../utils';
4
+ import { DragHandle } from '../../DragHandle';
5
+ export var ColumnControls = function ColumnControls(_ref) {
6
+ var _rowHeights$;
7
+ var editorView = _ref.editorView,
8
+ tableActive = _ref.tableActive,
9
+ tableRef = _ref.tableRef,
10
+ hoveredCell = _ref.hoveredCell,
11
+ isResizing = _ref.isResizing,
12
+ tableHeight = _ref.tableHeight,
13
+ stickyTop = _ref.stickyTop,
14
+ localId = _ref.localId;
15
+ var rowHeights = useMemo(function () {
16
+ // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
17
+ if (tableRef && !!tableHeight) {
18
+ return getRowHeights(tableRef);
19
+ }
20
+ return [0];
21
+ }, [tableRef, tableHeight]);
22
+ if (!tableRef) {
23
+ return null;
24
+ }
25
+ var firstRow = tableRef.querySelector('tr');
26
+ var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
27
+ var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
28
+ var colWidths = getColumnsWidths(editorView);
29
+ var widths = colWidths.map(function (width) {
30
+ return width ? "".concat(width - 1, "px") : '0px';
31
+ }).join(' ');
32
+ var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
33
+ var _onClick = function onClick(index, event) {};
34
+ var onMouseOver = function onMouseOver() {};
35
+ var onMouseOut = function onMouseOut() {};
36
+ return /*#__PURE__*/React.createElement("div", {
37
+ className: ClassName.COLUMN_CONTROLS_WITH_DRAG
38
+ }, /*#__PURE__*/React.createElement("div", {
39
+ className: ClassName.COLUMN_CONTROLS_INNER,
40
+ "data-testid": "table-floating-column-controls",
41
+ style: {
42
+ gridTemplateColumns: widths,
43
+ marginTop: marginTop
44
+ }
45
+ }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
46
+ style: {
47
+ gridColumn: "".concat(colIndex + 1, " / span 1"),
48
+ marginTop: "-15px"
49
+ },
50
+ "data-column-control-index": colIndex,
51
+ "data-testid": "table-floating-column-control"
52
+ }, /*#__PURE__*/React.createElement(DragHandle, {
53
+ direction: "column",
54
+ indexes: [],
55
+ onClick: function onClick(event) {
56
+ return _onClick(colIndex, event);
57
+ },
58
+ onMouseOver: onMouseOver,
59
+ onMouseOut: onMouseOut,
60
+ tableLocalId: localId || ''
61
+ }))));
62
+ };
63
+ export default ColumnControls;
@@ -3,13 +3,18 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
3
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  import React, { useEffect, useMemo, useState } from 'react';
6
+ import ReactDOM from 'react-dom';
6
7
  import { findTable } from '@atlaskit/editor-tables';
8
+ import { TableCssClassName as ClassName } from '../../types';
9
+ import { ColumnControls } from './ColumnControls';
7
10
  import { ColumnDropTargets } from './ColumnDropTargets';
8
11
  export var TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
9
12
  var editorView = _ref.editorView,
10
13
  tableRef = _ref.tableRef,
11
14
  tableActive = _ref.tableActive,
12
15
  hasHeaderRow = _ref.hasHeaderRow,
16
+ hoveredCell = _ref.hoveredCell,
17
+ isResizing = _ref.isResizing,
13
18
  stickyHeader = _ref.stickyHeader,
14
19
  selection = _ref.selection;
15
20
  var _useState = useState({
@@ -64,17 +69,29 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
64
69
  return null;
65
70
  }
66
71
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
67
- return /*#__PURE__*/React.createElement("div", {
72
+ var mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
73
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
74
+ className: ClassName.COLUMN_CONTROLS_WRAPPER
75
+ }, /*#__PURE__*/React.createElement("div", {
68
76
  onMouseDown: function onMouseDown(e) {
69
77
  return e.preventDefault();
70
78
  },
71
79
  "data-testid": "table-floating-column-controls-wrapper"
72
- }, tableActive && /*#__PURE__*/React.createElement(ColumnDropTargets, {
80
+ }, /*#__PURE__*/React.createElement(ColumnControls, {
73
81
  editorView: editorView,
82
+ hoveredCell: hoveredCell,
74
83
  tableRef: tableRef,
84
+ isResizing: isResizing,
85
+ tableActive: tableActive,
75
86
  stickyTop: tableActive ? stickyTop : undefined,
76
87
  tableHeight: tableRect.height,
77
88
  localId: selectedLocalId
78
- }));
89
+ }), /*#__PURE__*/React.createElement(ColumnDropTargets, {
90
+ editorView: editorView,
91
+ tableRef: tableRef,
92
+ stickyTop: tableActive ? stickyTop : undefined,
93
+ tableHeight: tableRect.height,
94
+ localId: selectedLocalId
95
+ }))), mountTo);
79
96
  };
80
97
  export default TableFloatingColumnControls;