@atlaskit/editor-plugin-table 2.8.6 → 2.9.1

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 (77) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/plugins/table/nodeviews/OverflowShadowsObserver.js +2 -1
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +6 -6
  4. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +10 -1
  5. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +22 -5
  6. package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +4 -1
  7. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +13 -2
  8. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +1 -6
  9. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +21 -8
  10. package/dist/cjs/plugins/table/ui/common-styles.js +12 -4
  11. package/dist/cjs/plugins/table/ui/consts.js +3 -1
  12. package/dist/cjs/plugins/table/ui/ui-styles.js +16 -7
  13. package/dist/es2019/plugins/table/nodeviews/OverflowShadowsObserver.js +2 -1
  14. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +6 -6
  15. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +10 -1
  16. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +22 -5
  17. package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +4 -1
  18. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +9 -1
  19. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +1 -6
  20. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +18 -7
  21. package/dist/es2019/plugins/table/ui/common-styles.js +27 -9
  22. package/dist/es2019/plugins/table/ui/consts.js +1 -0
  23. package/dist/es2019/plugins/table/ui/ui-styles.js +51 -4
  24. package/dist/esm/plugins/table/nodeviews/OverflowShadowsObserver.js +2 -1
  25. package/dist/esm/plugins/table/nodeviews/TableComponent.js +6 -6
  26. package/dist/esm/plugins/table/nodeviews/TableContainer.js +10 -1
  27. package/dist/esm/plugins/table/nodeviews/TableResizer.js +22 -5
  28. package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +4 -1
  29. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +11 -1
  30. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +1 -6
  31. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +22 -9
  32. package/dist/esm/plugins/table/ui/common-styles.js +12 -4
  33. package/dist/esm/plugins/table/ui/consts.js +1 -0
  34. package/dist/esm/plugins/table/ui/ui-styles.js +17 -8
  35. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +5 -4
  36. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +6 -5
  37. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +2 -1
  38. package/dist/types/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  39. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +8 -1
  40. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +5 -5
  41. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +5 -5
  42. package/dist/types/plugins/table/types.d.ts +8 -8
  43. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  44. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -1
  45. package/dist/types/plugins/table/utils/decoration.d.ts +6 -4
  46. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +5 -4
  47. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +6 -5
  48. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +2 -1
  49. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  50. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +8 -1
  51. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +5 -5
  52. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +5 -5
  53. package/dist/types-ts4.5/plugins/table/types.d.ts +8 -8
  54. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  55. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -1
  56. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +6 -4
  57. package/package.json +2 -2
  58. package/report.api.md +1 -1
  59. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +157 -61
  60. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +5 -1
  61. package/src/plugins/table/nodeviews/TableComponent.tsx +16 -15
  62. package/src/plugins/table/nodeviews/TableContainer.tsx +18 -12
  63. package/src/plugins/table/nodeviews/TableResizer.tsx +36 -5
  64. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +0 -1
  65. package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +18 -9
  66. package/src/plugins/table/pm-plugins/table-resizing/utils/colgroup.ts +17 -8
  67. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +9 -13
  68. package/src/plugins/table/pm-plugins/table-resizing/utils/resize-state.ts +34 -17
  69. package/src/plugins/table/types.ts +8 -8
  70. package/src/plugins/table/ui/common-styles.ts +28 -9
  71. package/src/plugins/table/ui/consts.ts +1 -0
  72. package/src/plugins/table/ui/ui-styles.ts +59 -4
  73. package/src/plugins/table/utils/decoration.ts +8 -11
  74. package/tmp/api-report-tmp.d.ts +1 -1
  75. package/dist/cjs/version.json +0 -5
  76. package/dist/es2019/version.json +0 -5
  77. package/dist/esm/version.json +0 -5
@@ -8,6 +8,7 @@ import { tableMarginSides } from '@atlaskit/editor-common/styles';
8
8
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
9
9
  import { akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
10
10
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
11
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
12
  import { autoSizeTable, clearHoverSelection } from '../commands';
12
13
  import { getPluginState } from '../pm-plugins/plugin-factory';
13
14
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
@@ -15,6 +16,7 @@ import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scal
15
16
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
16
17
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
17
18
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
19
+ import { tableOverflowShadowWidth } from '../ui/consts';
18
20
  import TableFloatingControls from '../ui/TableFloatingControls';
19
21
  import { containsHeaderRow, isTableNested, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns } from '../utils';
20
22
  import { OverflowShadowsObserver } from './OverflowShadowsObserver';
@@ -126,8 +128,7 @@ class TableComponent extends React.Component {
126
128
  if (shouldScaleTable) {
127
129
  this.scaleTable({
128
130
  parentWidth,
129
- layoutChanged,
130
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
131
+ layoutChanged
131
132
  });
132
133
  }
133
134
 
@@ -135,9 +136,8 @@ class TableComponent extends React.Component {
135
136
  if (options !== null && options !== void 0 && options.isTableResizingEnabled && hasNumberedColumnChanged) {
136
137
  if (!hasTableBeenResized(prevNode)) {
137
138
  this.scaleTable({
138
- parentWidth,
139
- layoutChanged,
140
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
139
+ parentWidth: node.attrs.width,
140
+ layoutChanged
141
141
  });
142
142
  }
143
143
  }
@@ -501,7 +501,7 @@ class TableComponent extends React.Component {
501
501
  }), this.state.stickyHeader && /*#__PURE__*/React.createElement("div", {
502
502
  style: {
503
503
  position: 'absolute',
504
- right: '-2px'
504
+ right: getBooleanFF('platform.editor.custom-table-width') ? `${tableOverflowShadowWidth}px` : '-2px'
505
505
  }
506
506
  }, /*#__PURE__*/React.createElement("div", {
507
507
  className: `${ClassName.TABLE_RIGHT_SHADOW} ${ClassName.TABLE_STICKY_SHADOW}`,
@@ -49,6 +49,14 @@ export const ResizableTableContainer = ({
49
49
  return;
50
50
  }
51
51
  const marginLeft = getMarginLeft(lineLength, width);
52
+
53
+ // make sure during resizing
54
+ // the pm-table-resizer-container width is the same as its child div resizer-item
55
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
56
+ // and cause the fabric-editor-popup-scroll-parent to overflow
57
+ if (containerRef.current.style.width !== `${width}px`) {
58
+ containerRef.current.style.width = `${width}px`;
59
+ }
52
60
  if (marginLeftRef.current !== marginLeft) {
53
61
  marginLeftRef.current = marginLeft;
54
62
  if (Number.isFinite(marginLeft)) {
@@ -82,6 +90,7 @@ export const ResizableTableContainer = ({
82
90
  }, /*#__PURE__*/React.createElement(TableResizer, {
83
91
  width: width,
84
92
  maxWidth: maxResizerWidth,
93
+ containerWidth: containerWidth,
85
94
  updateWidth: updateWidth,
86
95
  editorView: editorView,
87
96
  getPos: getPos,
@@ -126,7 +135,7 @@ export const TableContainer = ({
126
135
  return /*#__PURE__*/React.createElement(InnerContainer, {
127
136
  node: node,
128
137
  className: classNames(className, {
129
- 'less-padding': editorWidth < akEditorMobileBreakoutPoint
138
+ 'less-padding': editorWidth < akEditorMobileBreakoutPoint && !isNested
130
139
  }),
131
140
  style: {
132
141
  width: tableWidth,
@@ -36,12 +36,27 @@ const getResizerHandleHeight = tableRef => {
36
36
  const getResizerMinWidth = node => {
37
37
  const currentColumnCount = getColgroupChildrenLength(node);
38
38
  const minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
39
- return minColumnWidth;
39
+ // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
40
+ // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
41
+ return minColumnWidth + 1;
42
+ };
43
+
44
+ /**
45
+ * When guidelines are outside the viewport, filter them out, do not show
46
+ * So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
47
+ * @param guidelines
48
+ * @param containerWidth editorWidth
49
+ */
50
+ const getVisibleGuidelines = (guidelines, containerWidth) => {
51
+ return guidelines.filter(guideline => {
52
+ return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < containerWidth;
53
+ });
40
54
  };
41
55
  export const TableResizer = ({
42
56
  children,
43
57
  width,
44
58
  maxWidth,
59
+ containerWidth,
45
60
  updateWidth,
46
61
  editorView,
47
62
  getPos,
@@ -66,9 +81,10 @@ export const TableResizer = ({
66
81
  }) => {
67
82
  if (gap !== currentGap.current) {
68
83
  currentGap.current = gap;
69
- displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, defaultGuidelines));
84
+ const visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
85
+ displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
70
86
  }
71
- }, [displayGuideline]);
87
+ }, [displayGuideline, containerWidth]);
72
88
  const guidelineSnaps = useMemo(() => snappingEnabled ? {
73
89
  x: defaultSnappingWidths
74
90
  } : undefined, [snappingEnabled]);
@@ -83,8 +99,9 @@ export const TableResizer = ({
83
99
  dispatch(tr.setMeta(tableWidthPluginKey, {
84
100
  resizing: true
85
101
  }));
86
- setSnappingEnabled(displayGuideline(defaultGuidelines));
87
- }, [displayGuideline, editorView, startMeasure]);
102
+ const visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
103
+ setSnappingEnabled(displayGuideline(visibleGuidelines));
104
+ }, [displayGuideline, containerWidth, editorView, startMeasure]);
88
105
  const handleResize = useCallback((originalState, delta) => {
89
106
  countFrames();
90
107
  const newWidth = originalState.width + delta.width;
@@ -4,6 +4,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
4
4
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { updateColumnWidths } from '../../transforms';
8
9
  import { getSelectedColumnIndexes, updateResizeHandles } from '../../utils';
9
10
  import { evenColumns, setDragging, stopResizing } from './commands';
@@ -31,7 +32,9 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
31
32
  }
32
33
  const containerWidth = getEditorContainerWidth();
33
34
  const parentWidth = getParentNodeWidth(start, state, containerWidth);
34
- let maxSize = parentWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
35
+ let maxSize = getBooleanFF('platform.editor.custom-table-width') ? parentWidth ||
36
+ // its safe to reference table width from node as this will not have changed
37
+ originalTable.attrs.width || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {}) : parentWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
35
38
  if (originalTable.attrs.isNumberColumnEnabled) {
36
39
  maxSize -= akEditorTableNumberColumnWidth;
37
40
  }
@@ -3,9 +3,17 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
3
3
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
+ /**
7
+ * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
8
+ * than the table and table wrapper elements. This is necessary as there is no longer
9
+ * padding on the .pm-table-wrapper, so all elements need to be the same width to avoid
10
+ * overflow.
11
+ */
12
+ export const getColWidthFix = (colwidth, tableColumnCount) => colwidth - 1 / tableColumnCount;
6
13
  export const generateColgroup = table => {
7
14
  const cols = [];
8
15
  if (getBooleanFF('platform.editor.custom-table-width')) {
16
+ const map = TableMap.get(table);
9
17
  table.content.firstChild.content.forEach(cell => {
10
18
  const colspan = cell.attrs.colspan || 1;
11
19
  if (Array.isArray(cell.attrs.colwidth)) {
@@ -13,7 +21,7 @@ export const generateColgroup = table => {
13
21
  // Than the we actually span. We'll patch the document at a later point.
14
22
  cell.attrs.colwidth.slice(0, colspan).forEach(width => {
15
23
  cols.push(['col', {
16
- style: `width: ${width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth}px;`
24
+ style: `width: ${getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width)}px;`
17
25
  }]);
18
26
  });
19
27
  } else {
@@ -66,12 +66,7 @@ export const getTableMaxWidth = ({
66
66
  }) => {
67
67
  const containerWidth = getEditorContainerWidth();
68
68
  const parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
69
- let maxWidth;
70
- if (getBooleanFF('platform.editor.custom-table-width')) {
71
- maxWidth = parentWidth || table.attrs.width || getLayoutSize(layout, containerWidth.width, {});
72
- } else {
73
- maxWidth = parentWidth || getLayoutSize(layout, containerWidth.width, {});
74
- }
69
+ let maxWidth = getBooleanFF('platform.editor.custom-table-width') ? parentWidth || table.attrs.width || getLayoutSize(layout, containerWidth.width, {}) : parentWidth || getLayoutSize(layout, containerWidth.width, {});
75
70
  if (table.attrs.isNumberColumnEnabled) {
76
71
  maxWidth -= akEditorTableNumberColumnWidth;
77
72
  }
@@ -1,7 +1,8 @@
1
1
  import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
2
2
  import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { getSelectedTableInfo } from '../../../utils';
4
- import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
5
+ import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
5
6
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
6
7
  import { syncStickyRowToTable } from './dom';
7
8
  import { getTableMaxWidth } from './misc';
@@ -52,12 +53,22 @@ export const getResizeState = ({
52
53
  // updates Colgroup DOM node with new widths
53
54
  export const updateColgroup = (state, tableRef) => {
54
55
  const cols = tableRef.querySelectorAll('col');
55
- state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
56
- .forEach((column, i) => {
57
- if (cols[i]) {
58
- cols[i].style.width = `${column.width}px`;
59
- }
60
- });
56
+ if (getBooleanFF('platform.editor.custom-table-width')) {
57
+ const columnsCount = cols.length;
58
+ state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
59
+ .forEach((column, i) => {
60
+ if (cols[i]) {
61
+ cols[i].style.width = `${getColWidthFix(column.width, columnsCount)}px`;
62
+ }
63
+ });
64
+ } else {
65
+ state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
66
+ .forEach((column, i) => {
67
+ if (cols[i]) {
68
+ cols[i].style.width = `${column.width}px`;
69
+ }
70
+ });
71
+ }
61
72
 
62
73
  // colgroup has updated, reflect new widths in sticky header
63
74
  syncStickyRowToTable(tableRef);
@@ -2,6 +2,7 @@ import { css } from '@emotion/react';
2
2
  import { tableMarginTop, tableSharedStyle } from '@atlaskit/editor-common/styles';
3
3
  import { akEditorSelectedNodeClassName, akEditorSmallZIndex, akEditorStickyHeaderZIndex, akEditorTableCellOnStickyHeaderZIndex, akEditorTableNumberColumnWidth, akEditorTableToolbarSize, akEditorUnitZIndex, getSelectionStyles, relativeFontSizeToBase16, SelectionStyle } from '@atlaskit/editor-shared-styles';
4
4
  import { scrollbarStyles } from '@atlaskit/editor-shared-styles/scrollbar';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { B300, N0, N20A, N300, N40A, R500 } from '@atlaskit/theme/colors';
6
7
  import { fontSize } from '@atlaskit/theme/constants';
7
8
  import { TableCssClassName as ClassName } from '../types';
@@ -88,6 +89,31 @@ const breakoutWidthStyling = () => {
88
89
  }
89
90
  `;
90
91
  };
92
+ const tableWrapperStyles = () => {
93
+ if (getBooleanFF('platform.editor.custom-table-width')) {
94
+ return css`
95
+ .${ClassName.TABLE_NODE_WRAPPER} {
96
+ padding-bottom: 0px;
97
+ /* fixes gap cursor height */
98
+ overflow: auto;
99
+ overflow-y: hidden;
100
+ position: relative;
101
+ }
102
+ `;
103
+ } else {
104
+ return css`
105
+ .${ClassName.TABLE_NODE_WRAPPER} {
106
+ padding-right: ${insertColumnButtonOffset}px;
107
+ margin-right: -${insertColumnButtonOffset}px;
108
+ padding-bottom: 0px;
109
+ /* fixes gap cursor height */
110
+ overflow: auto;
111
+ overflow-y: hidden;
112
+ position: relative;
113
+ }
114
+ `;
115
+ }
116
+ };
91
117
 
92
118
  // TODO: https://product-fabric.atlassian.net/browse/DSP-4139
93
119
  export const tableStyles = props => {
@@ -658,15 +684,7 @@ export const tableStyles = props => {
658
684
  .${ClassName.ROW_CONTROLS_WRAPPER} {
659
685
  left: -${tableToolbarSize}px;
660
686
  }
661
- .${ClassName.TABLE_NODE_WRAPPER} {
662
- padding-right: ${insertColumnButtonOffset}px;
663
- margin-right: -${insertColumnButtonOffset}px;
664
- padding-bottom: 0px;
665
- /* fixes gap cursor height */
666
- overflow: auto;
667
- overflow-y: hidden;
668
- position: relative;
669
- }
687
+ ${tableWrapperStyles()}
670
688
  }
671
689
 
672
690
  .ProseMirror.${ClassName.IS_RESIZING} {
@@ -97,6 +97,7 @@ export const contextualMenuDropdownWidth = 180;
97
97
  export const stickyRowZIndex = resizeHandlerZIndex + 2;
98
98
  export const stickyRowOffsetTop = 8;
99
99
  export const stickyHeaderBorderBottomWidth = 1;
100
+ export const tableOverflowShadowWidth = 8;
100
101
  export const TABLE_SNAP_GAP = 9;
101
102
  export const TABLE_HIGHLIGHT_GAP = 10;
102
103
  export const TABLE_HIGHLIGHT_TOLERANCE = 2;
@@ -1,10 +1,11 @@
1
1
  import { css } from '@emotion/react';
2
2
  import { tableCellBorderWidth, tableMarginTop, tableMarginTopWithControl } from '@atlaskit/editor-common/styles';
3
3
  import { akEditorShadowZIndex, akEditorTableNumberColumnWidth, akEditorUnitZIndex } from '@atlaskit/editor-shared-styles';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
5
  import { B300, N0, N300, N40A, N60A, Y200, Y50 } from '@atlaskit/theme/colors';
5
6
  import { borderRadius } from '@atlaskit/theme/constants';
6
7
  import { TableCssClassName as ClassName } from '../types';
7
- import { columnControlsDecorationHeight, columnControlsSelectedZIndex, columnControlsZIndex, lineMarkerSize, resizeHandlerAreaWidth, resizeHandlerZIndex, resizeLineWidth, tableBorderColor, tableBorderDeleteColor, tableBorderSelectedColor, tableCellDeleteColor, tableCellHoverDeleteIconBackground, tableCellHoverDeleteIconColor, tableCellSelectedDeleteIconBackground, tableCellSelectedDeleteIconColor, tableDeleteButtonSize, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
8
+ import { columnControlsDecorationHeight, columnControlsSelectedZIndex, columnControlsZIndex, lineMarkerSize, resizeHandlerAreaWidth, resizeHandlerZIndex, resizeLineWidth, tableBorderColor, tableBorderDeleteColor, tableBorderSelectedColor, tableCellDeleteColor, tableCellHoverDeleteIconBackground, tableCellHoverDeleteIconColor, tableCellSelectedDeleteIconBackground, tableCellSelectedDeleteIconColor, tableDeleteButtonSize, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
8
9
  const InsertLine = (props, cssString) => css`
9
10
  .${ClassName.CONTROLS_INSERT_LINE} {
10
11
  background: ${tableBorderSelectedColor(props)};
@@ -186,7 +187,7 @@ export const OverflowShadow = props => css`
186
187
  pointer-events: none;
187
188
  top: ${tableMarginTop}px;
188
189
  z-index: ${akEditorShadowZIndex};
189
- width: 8px;
190
+ width: ${tableOverflowShadowWidth}px;
190
191
  }
191
192
  .${ClassName.TABLE_LEFT_SHADOW} {
192
193
  background: linear-gradient(
@@ -215,9 +216,8 @@ export const OverflowShadow = props => css`
215
216
  ${"var(--ds-shadow-overflow-perimeter, transparent)"} 0px,
216
217
  transparent 1px
217
218
  );
218
- left: calc(100% + 2px);
219
+ left: ${getBooleanFF('platform.editor.custom-table-width') ? `calc(100% - ${tableOverflowShadowWidth}px)` : 'calc(100% + 2px)'};
219
220
  }
220
-
221
221
  .${ClassName.WITH_CONTROLS} {
222
222
  .${ClassName.TABLE_RIGHT_SHADOW}, .${ClassName.TABLE_LEFT_SHADOW} {
223
223
  height: calc(100% - ${tableMarginTopWithControl}px);
@@ -247,6 +247,26 @@ const columnHeaderButtonSelected = props => css`
247
247
  border-color: ${tableBorderSelectedColor(props)};
248
248
  z-index: ${columnControlsSelectedZIndex};
249
249
  `;
250
+ const getFloatingDotOverrides = props => {
251
+ return getBooleanFF('platform.editor.custom-table-width') ? css`
252
+ tr
253
+ th:last-child
254
+ .${ClassName.COLUMN_CONTROLS_DECORATIONS}::before,
255
+ tr
256
+ td:last-child
257
+ .${ClassName.COLUMN_CONTROLS_DECORATIONS}::before {
258
+ content: '';
259
+ background-color: ${tableBorderColor(props)};
260
+ position: absolute;
261
+ height: ${lineMarkerSize}px;
262
+ width: ${lineMarkerSize}px;
263
+ border-radius: 50%;
264
+ pointer-events: none;
265
+ top: ${"var(--ds-space-025, 2px)"};
266
+ right: 0px;
267
+ }
268
+ ` : '';
269
+ };
250
270
  export const columnControlsDecoration = props => css`
251
271
  .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
252
272
  display: none;
@@ -256,6 +276,7 @@ export const columnControlsDecoration = props => css`
256
276
  left: -1px;
257
277
  top: -${columnControlsDecorationHeight + tableCellBorderWidth}px;
258
278
  height: ${columnControlsDecorationHeight}px;
279
+ // floating dot for adding column button
259
280
  &::before {
260
281
  content: ' ';
261
282
  background-color: ${tableBorderColor(props)};
@@ -284,6 +305,9 @@ export const columnControlsDecoration = props => css`
284
305
  }
285
306
  }
286
307
 
308
+ // floating dot for adding column button - overriding style on last column to avoid scroll
309
+ ${getFloatingDotOverrides(props)}
310
+
287
311
  div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
288
312
  content: ' ';
289
313
  background-color: ${tableBorderColor(props)};
@@ -366,6 +390,27 @@ export const hoveredWarningCell = css`
366
390
  }
367
391
  }
368
392
  `;
393
+
394
+ // move the resize handle zone completely inside the table cell to avoid overflow
395
+ const getLastColumnResizerOverrides = () => {
396
+ return getBooleanFF('platform.editor.custom-table-width') ? css`
397
+ tr
398
+ th:last-child
399
+ .${ClassName.RESIZE_HANDLE_DECORATION},
400
+ tr
401
+ td:last-child
402
+ .${ClassName.RESIZE_HANDLE_DECORATION} {
403
+ background-color: transparent;
404
+ position: absolute;
405
+ width: ${resizeHandlerAreaWidth}px;
406
+ height: 100%;
407
+ top: 0;
408
+ right: 0;
409
+ cursor: col-resize;
410
+ z-index: ${resizeHandlerZIndex};
411
+ }
412
+ ` : '';
413
+ };
369
414
  export const resizeHandle = props => css`
370
415
  .${ClassName.TABLE_CONTAINER} {
371
416
  .${ClassName.RESIZE_HANDLE_DECORATION} {
@@ -379,6 +424,8 @@ export const resizeHandle = props => css`
379
424
  z-index: ${resizeHandlerZIndex};
380
425
  }
381
426
 
427
+ ${getLastColumnResizerOverrides()}
428
+
382
429
  td.${ClassName.WITH_RESIZE_LINE}::before {
383
430
  content: ' ';
384
431
  position: absolute;
@@ -1,6 +1,7 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
5
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
5
6
  import { tableInsertColumnButtonSize } from '../ui/consts';
6
7
  import { updateShadowListForStickyStyles } from './update-overflow-shadows';
@@ -34,7 +35,7 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
34
35
  }, {
35
36
  threshold: [0, 1],
36
37
  root: _this.wrapper,
37
- rootMargin: "0px ".concat(tableInsertColumnButtonSize / 2, "px 0px 0px")
38
+ rootMargin: getBooleanFF('platform.editor.custom-table-width') ? '0px' : "0px ".concat(tableInsertColumnButtonSize / 2, "px 0px 0px")
38
39
  });
39
40
  return;
40
41
  }
@@ -18,6 +18,7 @@ import { tableMarginSides } from '@atlaskit/editor-common/styles';
18
18
  import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
19
19
  import { akEditorTableToolbarSize as tableToolbarSize } from '@atlaskit/editor-shared-styles';
20
20
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
21
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
21
22
  import { autoSizeTable, clearHoverSelection } from '../commands';
22
23
  import { getPluginState } from '../pm-plugins/plugin-factory';
23
24
  import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
@@ -25,6 +26,7 @@ import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scal
25
26
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
26
27
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
27
28
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
29
+ import { tableOverflowShadowWidth } from '../ui/consts';
28
30
  import TableFloatingControls from '../ui/TableFloatingControls';
29
31
  import { containsHeaderRow, isTableNested, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns } from '../utils';
30
32
  import { OverflowShadowsObserver } from './OverflowShadowsObserver';
@@ -134,8 +136,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
134
136
  if (shouldScaleTable) {
135
137
  _this.scaleTable({
136
138
  parentWidth: parentWidth,
137
- layoutChanged: layoutChanged,
138
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
139
+ layoutChanged: layoutChanged
139
140
  });
140
141
  }
141
142
 
@@ -143,9 +144,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
143
144
  if (options !== null && options !== void 0 && options.isTableResizingEnabled && hasNumberedColumnChanged) {
144
145
  if (!hasTableBeenResized(prevNode)) {
145
146
  _this.scaleTable({
146
- parentWidth: parentWidth,
147
- layoutChanged: layoutChanged,
148
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
147
+ parentWidth: node.attrs.width,
148
+ layoutChanged: layoutChanged
149
149
  });
150
150
  }
151
151
  }
@@ -496,7 +496,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
496
496
  }), this.state.stickyHeader && /*#__PURE__*/React.createElement("div", {
497
497
  style: {
498
498
  position: 'absolute',
499
- right: '-2px'
499
+ right: getBooleanFF('platform.editor.custom-table-width') ? "".concat(tableOverflowShadowWidth, "px") : '-2px'
500
500
  }
501
501
  }, /*#__PURE__*/React.createElement("div", {
502
502
  className: "".concat(ClassName.TABLE_RIGHT_SHADOW, " ").concat(ClassName.TABLE_STICKY_SHADOW),
@@ -47,6 +47,14 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
47
47
  return;
48
48
  }
49
49
  var marginLeft = getMarginLeft(lineLength, width);
50
+
51
+ // make sure during resizing
52
+ // the pm-table-resizer-container width is the same as its child div resizer-item
53
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
54
+ // and cause the fabric-editor-popup-scroll-parent to overflow
55
+ if (containerRef.current.style.width !== "".concat(width, "px")) {
56
+ containerRef.current.style.width = "".concat(width, "px");
57
+ }
50
58
  if (marginLeftRef.current !== marginLeft) {
51
59
  marginLeftRef.current = marginLeft;
52
60
  if (Number.isFinite(marginLeft)) {
@@ -80,6 +88,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
80
88
  }, /*#__PURE__*/React.createElement(TableResizer, {
81
89
  width: width,
82
90
  maxWidth: maxResizerWidth,
91
+ containerWidth: containerWidth,
83
92
  updateWidth: updateWidth,
84
93
  editorView: editorView,
85
94
  getPos: getPos,
@@ -122,7 +131,7 @@ export var TableContainer = function TableContainer(_ref3) {
122
131
  return /*#__PURE__*/React.createElement(InnerContainer, {
123
132
  node: node,
124
133
  className: classNames(className, {
125
- 'less-padding': editorWidth < akEditorMobileBreakoutPoint
134
+ 'less-padding': editorWidth < akEditorMobileBreakoutPoint && !isNested
126
135
  }),
127
136
  style: {
128
137
  width: tableWidth,
@@ -40,13 +40,28 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
40
40
  var getResizerMinWidth = function getResizerMinWidth(node) {
41
41
  var currentColumnCount = getColgroupChildrenLength(node);
42
42
  var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
43
- return minColumnWidth;
43
+ // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
44
+ // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
45
+ return minColumnWidth + 1;
46
+ };
47
+
48
+ /**
49
+ * When guidelines are outside the viewport, filter them out, do not show
50
+ * So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
51
+ * @param guidelines
52
+ * @param containerWidth editorWidth
53
+ */
54
+ var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth) {
55
+ return guidelines.filter(function (guideline) {
56
+ return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < containerWidth;
57
+ });
44
58
  };
45
59
  export var TableResizer = function TableResizer(_ref) {
46
60
  var _findTable, _editorView$state;
47
61
  var children = _ref.children,
48
62
  width = _ref.width,
49
63
  maxWidth = _ref.maxWidth,
64
+ containerWidth = _ref.containerWidth,
50
65
  updateWidth = _ref.updateWidth,
51
66
  editorView = _ref.editorView,
52
67
  getPos = _ref.getPos,
@@ -70,9 +85,10 @@ export var TableResizer = function TableResizer(_ref) {
70
85
  keys = _ref2.keys;
71
86
  if (gap !== currentGap.current) {
72
87
  currentGap.current = gap;
73
- displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, defaultGuidelines));
88
+ var visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
89
+ displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
74
90
  }
75
- }, [displayGuideline]);
91
+ }, [displayGuideline, containerWidth]);
76
92
  var guidelineSnaps = useMemo(function () {
77
93
  return snappingEnabled ? {
78
94
  x: defaultSnappingWidths
@@ -85,8 +101,9 @@ export var TableResizer = function TableResizer(_ref) {
85
101
  dispatch(tr.setMeta(tableWidthPluginKey, {
86
102
  resizing: true
87
103
  }));
88
- setSnappingEnabled(displayGuideline(defaultGuidelines));
89
- }, [displayGuideline, editorView, startMeasure]);
104
+ var visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
105
+ setSnappingEnabled(displayGuideline(visibleGuidelines));
106
+ }, [displayGuideline, containerWidth, editorView, startMeasure]);
90
107
  var handleResize = useCallback(function (originalState, delta) {
91
108
  countFrames();
92
109
  var newWidth = originalState.width + delta.width;
@@ -4,6 +4,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
4
4
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { updateColumnWidths } from '../../transforms';
8
9
  import { getSelectedColumnIndexes, updateResizeHandles } from '../../utils';
9
10
  import { evenColumns, setDragging, stopResizing } from './commands';
@@ -29,7 +30,9 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
29
30
  }
30
31
  var containerWidth = getEditorContainerWidth();
31
32
  var parentWidth = getParentNodeWidth(start, state, containerWidth);
32
- var maxSize = parentWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
33
+ var maxSize = getBooleanFF('platform.editor.custom-table-width') ? parentWidth ||
34
+ // its safe to reference table width from node as this will not have changed
35
+ originalTable.attrs.width || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {}) : parentWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
33
36
  if (originalTable.attrs.isNumberColumnEnabled) {
34
37
  maxSize -= akEditorTableNumberColumnWidth;
35
38
  }
@@ -4,9 +4,19 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
4
4
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ /**
8
+ * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
9
+ * than the table and table wrapper elements. This is necessary as there is no longer
10
+ * padding on the .pm-table-wrapper, so all elements need to be the same width to avoid
11
+ * overflow.
12
+ */
13
+ export var getColWidthFix = function getColWidthFix(colwidth, tableColumnCount) {
14
+ return colwidth - 1 / tableColumnCount;
15
+ };
7
16
  export var generateColgroup = function generateColgroup(table) {
8
17
  var cols = [];
9
18
  if (getBooleanFF('platform.editor.custom-table-width')) {
19
+ var map = TableMap.get(table);
10
20
  table.content.firstChild.content.forEach(function (cell) {
11
21
  var colspan = cell.attrs.colspan || 1;
12
22
  if (Array.isArray(cell.attrs.colwidth)) {
@@ -14,7 +24,7 @@ export var generateColgroup = function generateColgroup(table) {
14
24
  // Than the we actually span. We'll patch the document at a later point.
15
25
  cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
16
26
  cols.push(['col', {
17
- style: "width: ".concat(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, "px;")
27
+ style: "width: ".concat(getColWidthFix(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, map.width), "px;")
18
28
  }]);
19
29
  });
20
30
  } else {
@@ -64,12 +64,7 @@ export var getTableMaxWidth = function getTableMaxWidth(_ref2) {
64
64
  getEditorContainerWidth = _ref2.getEditorContainerWidth;
65
65
  var containerWidth = getEditorContainerWidth();
66
66
  var parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
67
- var maxWidth;
68
- if (getBooleanFF('platform.editor.custom-table-width')) {
69
- maxWidth = parentWidth || table.attrs.width || getLayoutSize(layout, containerWidth.width, {});
70
- } else {
71
- maxWidth = parentWidth || getLayoutSize(layout, containerWidth.width, {});
72
- }
67
+ var maxWidth = getBooleanFF('platform.editor.custom-table-width') ? parentWidth || table.attrs.width || getLayoutSize(layout, containerWidth.width, {}) : parentWidth || getLayoutSize(layout, containerWidth.width, {});
73
68
  if (table.attrs.isNumberColumnEnabled) {
74
69
  maxWidth -= akEditorTableNumberColumnWidth;
75
70
  }