@atlaskit/editor-plugin-table 7.10.0 → 7.10.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 (42) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/commands/column-resize.js +7 -1
  3. package/dist/cjs/nodeviews/TableRow.js +1 -1
  4. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  5. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +1 -1
  6. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  7. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  8. package/dist/cjs/transforms/column-width.js +3 -1
  9. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  10. package/dist/es2019/commands/column-resize.js +7 -1
  11. package/dist/es2019/nodeviews/TableRow.js +1 -1
  12. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  13. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +1 -1
  14. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  15. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  16. package/dist/es2019/transforms/column-width.js +3 -1
  17. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  18. package/dist/esm/commands/column-resize.js +7 -1
  19. package/dist/esm/nodeviews/TableRow.js +1 -1
  20. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  21. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +1 -1
  22. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  23. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  24. package/dist/esm/transforms/column-width.js +3 -1
  25. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  26. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  27. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  28. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  29. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
  30. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  31. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  32. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  33. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
  34. package/package.json +4 -1
  35. package/src/commands/column-resize.ts +11 -3
  36. package/src/nodeviews/TableRow.ts +2 -2
  37. package/src/pm-plugins/table-resizing/utils/colgroup.ts +5 -5
  38. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  39. package/src/pm-plugins/table-resizing/utils/resize-column.ts +7 -5
  40. package/src/pm-plugins/table-resizing/utils/resize-state.ts +16 -10
  41. package/src/transforms/column-width.ts +10 -2
  42. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +28 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#92552](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92552) [`7cd874b858c8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7cd874b858c8) - Check target elements are actually HTMLElement rather than typecasting.
8
+
3
9
  ## 7.10.0
4
10
 
5
11
  ### Minor Changes
@@ -182,7 +182,13 @@ var changeColumnWidthByStep = exports.changeColumnWidthByStep = function changeC
182
182
  var map = _editorTables.TableMap.get(originalTable);
183
183
  var domAtPos = view.domAtPos.bind(view);
184
184
  var colIndex = map.colCount($cell.pos - tableStartPosition) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
185
- var dom = domAtPos(tableStartPosition).node;
185
+ var dom = null;
186
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.explicit-html-element-check')) {
187
+ var domAtPosition = domAtPos(tableStartPosition);
188
+ dom = domAtPosition.node instanceof HTMLTableElement ? domAtPosition.node : null;
189
+ } else {
190
+ dom = domAtPos(tableStartPosition).node;
191
+ }
186
192
  if (dom && dom.nodeName !== 'TABLE') {
187
193
  dom = dom.closest('table');
188
194
  }
@@ -403,7 +403,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
403
403
  this.focused = isCurrentTableSelected;
404
404
  var wrapper = tree.wrapper;
405
405
  var tableContainer = wrapper.parentElement;
406
- var tableContentWrapper = tableContainer.parentElement;
406
+ var tableContentWrapper = tableContainer === null || tableContainer === void 0 ? void 0 : tableContainer.parentElement;
407
407
  var layoutContainer = tableContentWrapper && tableContentWrapper.parentElement;
408
408
  if (isCurrentTableSelected) {
409
409
  this.colControlsOffset = _consts.tableControlsSpacing;
@@ -63,13 +63,13 @@ var generateColgroup = exports.generateColgroup = function generateColgroup(tabl
63
63
  var insertColgroupFromNode = exports.insertColgroupFromNode = function insertColgroupFromNode(tableRef, table) {
64
64
  var isTableScalingEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
65
65
  var shouldRemove = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
66
- var colgroup = tableRef.querySelector('colgroup');
66
+ var colgroup = tableRef === null || tableRef === void 0 ? void 0 : tableRef.querySelector('colgroup');
67
67
  if (colgroup && shouldRemove) {
68
- tableRef.removeChild(colgroup);
68
+ tableRef === null || tableRef === void 0 || tableRef.removeChild(colgroup);
69
69
  }
70
- colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef : undefined);
70
+ colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef !== null && tableRef !== void 0 ? tableRef : undefined : undefined);
71
71
  if (shouldRemove) {
72
- tableRef.insertBefore(colgroup, tableRef.firstChild);
72
+ tableRef === null || tableRef === void 0 || tableRef.insertBefore(colgroup, tableRef === null || tableRef === void 0 ? void 0 : tableRef.firstChild);
73
73
  }
74
74
  return colgroup.children;
75
75
  };
@@ -103,7 +103,7 @@ var getTableContainerElementWidth = exports.getTableContainerElementWidth = func
103
103
  var getTableScalingPercent = exports.getTableScalingPercent = function getTableScalingPercent(table, tableRef) {
104
104
  var _tableRef$parentEleme;
105
105
  var tableWidth = getTableContainerElementWidth(table);
106
- var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
106
+ var renderWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
107
107
  // minus 1 here to avoid any 1px scroll in Firefox
108
108
  var scalePercent = (renderWidth - 1) / tableWidth;
109
109
  scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
@@ -22,7 +22,7 @@ var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, col
22
22
  var _tableRef$closest;
23
23
  // when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
24
24
  var tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
25
- var tableContainerWidth = (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
25
+ var tableContainerWidth = tableRef === null || tableRef === void 0 || (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
26
26
  var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
27
27
  resizeAmount = amount * 2;
28
28
  if (isOverflowed) {
@@ -53,11 +53,13 @@ var resizeColumn = exports.resizeColumn = function resizeColumn(resizeState, col
53
53
  };
54
54
  var updateTable = function updateTable(resizeAmount, tableRef, tableNode) {
55
55
  var currentWidth = (0, _misc.getTableContainerElementWidth)(tableNode);
56
- var resizingContainer = tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
56
+ var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(_types.TableCssClassName.TABLE_RESIZER_CONTAINER));
57
57
  var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
58
58
  if (resizingContainer && resizingItem) {
59
59
  var newWidth = "".concat(currentWidth + resizeAmount, "px");
60
- tableRef.style.width = newWidth;
60
+ if (tableRef) {
61
+ tableRef.style.width = newWidth;
62
+ }
61
63
  resizingContainer.style.width = newWidth;
62
64
  resizingItem.style.width = newWidth;
63
65
  }
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
10
10
  var _styles = require("@atlaskit/editor-common/styles");
11
11
  var _utils = require("@atlaskit/editor-common/utils");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _utils2 = require("../../../utils");
13
14
  var _colgroup = require("./colgroup");
14
15
  var _columnState = require("./column-state");
@@ -92,8 +93,8 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
92
93
 
93
94
  // updates Colgroup DOM node with new widths
94
95
  var updateColgroup = exports.updateColgroup = function updateColgroup(state, tableRef, tableNode, isTableScalingEnabled) {
95
- var cols = tableRef.querySelectorAll('col');
96
- var columnsCount = cols.length;
96
+ var cols = tableRef === null || tableRef === void 0 ? void 0 : tableRef.querySelectorAll('col');
97
+ var columnsCount = cols === null || cols === void 0 ? void 0 : cols.length;
97
98
  /**
98
99
  updateColgroup will update whole table scale when click the column resize handle, this behavior will affect when table overflowed, when now resize handle been dragged and extend to make table overflowed, table will show overflow. This need to be confirmed because it conflict with how isTableScalingEnabled work.
99
100
  We don't want to scale the table when resizing columns, only when viewpoint shrinks the table.
@@ -105,11 +106,11 @@ var updateColgroup = exports.updateColgroup = function updateColgroup(state, tab
105
106
  return column && !!column.width;
106
107
  }) // if width is 0, we dont want to apply that.
107
108
  .forEach(function (column, i) {
108
- var fixedColWidth = (0, _colgroup.getColWidthFix)(column.width, columnsCount);
109
+ var fixedColWidth = (0, _colgroup.getColWidthFix)(column.width, columnsCount !== null && columnsCount !== void 0 ? columnsCount : 0);
109
110
  var scaledWidth = fixedColWidth * scalePercent;
110
111
  var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
111
112
  // we aren't handling the remaining pixels here when the 48px min width is reached
112
- if (cols[i]) {
113
+ if (cols !== null && cols !== void 0 && cols[i]) {
113
114
  cols[i].style.width = "".concat(finalWidth, "px");
114
115
  }
115
116
  });
@@ -118,8 +119,8 @@ var updateColgroup = exports.updateColgroup = function updateColgroup(state, tab
118
119
  return column && !!column.width;
119
120
  }) // if width is 0, we dont want to apply that.
120
121
  .forEach(function (column, i) {
121
- if (cols[i]) {
122
- cols[i].style.width = "".concat((0, _colgroup.getColWidthFix)(column.width, columnsCount), "px");
122
+ if (cols !== null && cols !== void 0 && cols[i]) {
123
+ cols[i].style.width = "".concat((0, _colgroup.getColWidthFix)(column.width, columnsCount !== null && columnsCount !== void 0 ? columnsCount : 0), "px");
123
124
  }
124
125
  });
125
126
  }
@@ -319,7 +320,8 @@ var getNewResizeStateFromSelectedColumns = exports.getNewResizeStateFromSelected
319
320
  return;
320
321
  }
321
322
  var maybeTable = domAtPos(table.start).node;
322
- var tableRef = maybeTable.closest('table');
323
+ var maybeTableElement = maybeTable instanceof HTMLElement ? maybeTable : null;
324
+ var tableRef = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.explicit-html-element-check') ? maybeTableElement === null || maybeTableElement === void 0 ? void 0 : maybeTableElement.closest('table') : maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.closest('table');
323
325
  if (!tableRef) {
324
326
  return;
325
327
  }
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _styles = require("@atlaskit/editor-common/styles");
10
10
  var _transform = require("@atlaskit/editor-prosemirror/transform");
11
11
  var _tableMap = require("@atlaskit/editor-tables/table-map");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _utils = require("../pm-plugins/table-resizing/utils");
13
14
  var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
14
15
  var _resizeState = require("../pm-plugins/table-resizing/utils/resize-state");
@@ -105,7 +106,8 @@ var rescaleColumns = exports.rescaleColumns = function rescaleColumns() {
105
106
  var newTable = tr.doc.nodeAt(table.pos);
106
107
  var domAtPos = view.domAtPos.bind(view);
107
108
  var maybeTable = domAtPos(table.start).node;
108
- var tableRef = maybeTable.closest('table');
109
+ var maybeTableElement = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.explicit-html-element-check') ? maybeTable instanceof HTMLElement ? maybeTable : null : maybeTable;
110
+ var tableRef = maybeTableElement === null || maybeTableElement === void 0 ? void 0 : maybeTableElement.closest('table');
109
111
  if (!tableRef || !newTable) {
110
112
  return tr;
111
113
  }
@@ -11,6 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
11
11
  var _reactIntlNext = require("react-intl-next");
12
12
  var _editorTables = require("@atlaskit/editor-tables");
13
13
  var _utils = require("@atlaskit/editor-tables/utils");
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
15
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
15
16
  var _commands = require("../../../commands");
16
17
  var _commands2 = require("../../../pm-plugins/drag-and-drop/commands");
@@ -100,14 +101,26 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
100
101
  }
101
102
  }, [editorView, tableActive]);
102
103
  var handleMouseMove = (0, _react.useCallback)(function (e) {
103
- var isParentDragControls = e.nativeEvent.target.closest(".".concat(_types.TableCssClassName.DRAG_ROW_CONTROLS));
104
- var rowIndex = e.nativeEvent.target.getAttribute('data-start-index');
104
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.explicit-html-element-check')) {
105
+ var target = e.nativeEvent.target instanceof Element ? e.nativeEvent.target : null;
106
+ var isParentDragControls = target === null || target === void 0 ? void 0 : target.closest(".".concat(_types.TableCssClassName.DRAG_ROW_CONTROLS));
107
+ var _rowIndex = target === null || target === void 0 ? void 0 : target.getAttribute('data-start-index');
105
108
 
106
- // avoid updating if event target is not related
107
- if (!isParentDragControls || !rowIndex) {
108
- return;
109
+ // avoid updating if event target is not related
110
+ if (!isParentDragControls || !_rowIndex) {
111
+ return;
112
+ }
113
+ updateCellHoverLocation(Number(_rowIndex));
114
+ } else {
115
+ var _isParentDragControls = e.nativeEvent.target.closest(".".concat(_types.TableCssClassName.DRAG_ROW_CONTROLS));
116
+ var _rowIndex2 = e.nativeEvent.target.getAttribute('data-start-index');
117
+
118
+ // avoid updating if event target is not related
119
+ if (!_isParentDragControls || !_rowIndex2) {
120
+ return;
121
+ }
122
+ updateCellHoverLocation(Number(_rowIndex2));
109
123
  }
110
- updateCellHoverLocation(Number(rowIndex));
111
124
  }, [updateCellHoverLocation]);
112
125
  var rowIndexes = (0, _react.useMemo)(function () {
113
126
  return [rowIndex];
@@ -177,7 +177,13 @@ export const changeColumnWidthByStep = ({
177
177
  const map = TableMap.get(originalTable);
178
178
  const domAtPos = view.domAtPos.bind(view);
179
179
  const colIndex = map.colCount($cell.pos - tableStartPosition) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
180
- let dom = domAtPos(tableStartPosition).node;
180
+ let dom = null;
181
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
182
+ const domAtPosition = domAtPos(tableStartPosition);
183
+ dom = domAtPosition.node instanceof HTMLTableElement ? domAtPosition.node : null;
184
+ } else {
185
+ dom = domAtPos(tableStartPosition).node;
186
+ }
181
187
  if (dom && dom.nodeName !== 'TABLE') {
182
188
  dom = dom.closest('table');
183
189
  }
@@ -369,7 +369,7 @@ export default class TableRow extends TableNodeView {
369
369
  wrapper
370
370
  } = tree;
371
371
  const tableContainer = wrapper.parentElement;
372
- const tableContentWrapper = tableContainer.parentElement;
372
+ const tableContentWrapper = tableContainer === null || tableContainer === void 0 ? void 0 : tableContainer.parentElement;
373
373
  const layoutContainer = tableContentWrapper && tableContentWrapper.parentElement;
374
374
  if (isCurrentTableSelected) {
375
375
  this.colControlsOffset = tableControlsSpacing;
@@ -49,13 +49,13 @@ export const generateColgroup = (table, tableRef) => {
49
49
  return cols;
50
50
  };
51
51
  export const insertColgroupFromNode = (tableRef, table, isTableScalingEnabled = false, shouldRemove = true) => {
52
- let colgroup = tableRef.querySelector('colgroup');
52
+ let colgroup = tableRef === null || tableRef === void 0 ? void 0 : tableRef.querySelector('colgroup');
53
53
  if (colgroup && shouldRemove) {
54
- tableRef.removeChild(colgroup);
54
+ tableRef === null || tableRef === void 0 ? void 0 : tableRef.removeChild(colgroup);
55
55
  }
56
- colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef : undefined);
56
+ colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef !== null && tableRef !== void 0 ? tableRef : undefined : undefined);
57
57
  if (shouldRemove) {
58
- tableRef.insertBefore(colgroup, tableRef.firstChild);
58
+ tableRef === null || tableRef === void 0 ? void 0 : tableRef.insertBefore(colgroup, tableRef === null || tableRef === void 0 ? void 0 : tableRef.firstChild);
59
59
  }
60
60
  return colgroup.children;
61
61
  };
@@ -93,7 +93,7 @@ export const getTableContainerElementWidth = table => {
93
93
  export const getTableScalingPercent = (table, tableRef) => {
94
94
  var _tableRef$parentEleme;
95
95
  const tableWidth = getTableContainerElementWidth(table);
96
- let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
96
+ let renderWidth = (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
97
97
  // minus 1 here to avoid any 1px scroll in Firefox
98
98
  let scalePercent = (renderWidth - 1) / tableWidth;
99
99
  scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
@@ -13,7 +13,7 @@ export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode,
13
13
  var _tableRef$closest;
14
14
  // when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
15
15
  const tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
16
- const tableContainerWidth = (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
16
+ const tableContainerWidth = tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
17
17
  const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
18
18
  resizeAmount = amount * 2;
19
19
  if (isOverflowed) {
@@ -45,11 +45,13 @@ export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode,
45
45
  };
46
46
  const updateTable = (resizeAmount, tableRef, tableNode) => {
47
47
  const currentWidth = getTableContainerElementWidth(tableNode);
48
- const resizingContainer = tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
48
+ const resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(`.${ClassName.TABLE_RESIZER_CONTAINER}`);
49
49
  const resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
50
50
  if (resizingContainer && resizingItem) {
51
51
  const newWidth = `${currentWidth + resizeAmount}px`;
52
- tableRef.style.width = newWidth;
52
+ if (tableRef) {
53
+ tableRef.style.width = newWidth;
54
+ }
53
55
  resizingContainer.style.width = newWidth;
54
56
  resizingItem.style.width = newWidth;
55
57
  }
@@ -1,6 +1,7 @@
1
1
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
2
2
  import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
3
3
  import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
5
  import { getSelectedTableInfo } from '../../../utils';
5
6
  import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
6
7
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
@@ -72,8 +73,8 @@ export const getResizeState = ({
72
73
 
73
74
  // updates Colgroup DOM node with new widths
74
75
  export const updateColgroup = (state, tableRef, tableNode, isTableScalingEnabled) => {
75
- const cols = tableRef.querySelectorAll('col');
76
- const columnsCount = cols.length;
76
+ const cols = tableRef === null || tableRef === void 0 ? void 0 : tableRef.querySelectorAll('col');
77
+ const columnsCount = cols === null || cols === void 0 ? void 0 : cols.length;
77
78
  /**
78
79
  updateColgroup will update whole table scale when click the column resize handle, this behavior will affect when table overflowed, when now resize handle been dragged and extend to make table overflowed, table will show overflow. This need to be confirmed because it conflict with how isTableScalingEnabled work.
79
80
  We don't want to scale the table when resizing columns, only when viewpoint shrinks the table.
@@ -83,19 +84,19 @@ export const updateColgroup = (state, tableRef, tableNode, isTableScalingEnabled
83
84
  const scalePercent = getTableScalingPercent(tableNode, tableRef);
84
85
  state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
85
86
  .forEach((column, i) => {
86
- const fixedColWidth = getColWidthFix(column.width, columnsCount);
87
+ const fixedColWidth = getColWidthFix(column.width, columnsCount !== null && columnsCount !== void 0 ? columnsCount : 0);
87
88
  const scaledWidth = fixedColWidth * scalePercent;
88
89
  const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
89
90
  // we aren't handling the remaining pixels here when the 48px min width is reached
90
- if (cols[i]) {
91
+ if (cols !== null && cols !== void 0 && cols[i]) {
91
92
  cols[i].style.width = `${finalWidth}px`;
92
93
  }
93
94
  });
94
95
  } else {
95
96
  state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
96
97
  .forEach((column, i) => {
97
- if (cols[i]) {
98
- cols[i].style.width = `${getColWidthFix(column.width, columnsCount)}px`;
98
+ if (cols !== null && cols !== void 0 && cols[i]) {
99
+ cols[i].style.width = `${getColWidthFix(column.width, columnsCount !== null && columnsCount !== void 0 ? columnsCount : 0)}px`;
99
100
  }
100
101
  });
101
102
  }
@@ -290,7 +291,8 @@ export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getE
290
291
  return;
291
292
  }
292
293
  const maybeTable = domAtPos(table.start).node;
293
- const tableRef = maybeTable.closest('table');
294
+ const maybeTableElement = maybeTable instanceof HTMLElement ? maybeTable : null;
295
+ const tableRef = getBooleanFF('platform.editor.explicit-html-element-check') ? maybeTableElement === null || maybeTableElement === void 0 ? void 0 : maybeTableElement.closest('table') : maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.closest('table');
294
296
  if (!tableRef) {
295
297
  return;
296
298
  }
@@ -1,6 +1,7 @@
1
1
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
2
  import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import { TableMap } from '@atlaskit/editor-tables/table-map';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
5
  import { getTableContainerElementWidth, getTableElementWidth, hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
5
6
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
6
7
  import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
@@ -94,7 +95,8 @@ export const rescaleColumns = (isTableScalingEnabled = false) => (table, view) =
94
95
  const newTable = tr.doc.nodeAt(table.pos);
95
96
  const domAtPos = view.domAtPos.bind(view);
96
97
  const maybeTable = domAtPos(table.start).node;
97
- const tableRef = maybeTable.closest('table');
98
+ const maybeTableElement = getBooleanFF('platform.editor.explicit-html-element-check') ? maybeTable instanceof HTMLElement ? maybeTable : null : maybeTable;
99
+ const tableRef = maybeTableElement === null || maybeTableElement === void 0 ? void 0 : maybeTableElement.closest('table');
98
100
  if (!tableRef || !newTable) {
99
101
  return tr;
100
102
  }
@@ -4,6 +4,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'reac
4
4
  import { injectIntl } from 'react-intl-next';
5
5
  import { CellSelection } from '@atlaskit/editor-tables';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
8
9
  import { clearHoverSelection } from '../../../commands';
9
10
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
@@ -90,14 +91,26 @@ const DragControlsComponent = ({
90
91
  }
91
92
  }, [editorView, tableActive]);
92
93
  const handleMouseMove = useCallback(e => {
93
- const isParentDragControls = e.nativeEvent.target.closest(`.${ClassName.DRAG_ROW_CONTROLS}`);
94
- const rowIndex = e.nativeEvent.target.getAttribute('data-start-index');
94
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
95
+ const target = e.nativeEvent.target instanceof Element ? e.nativeEvent.target : null;
96
+ const isParentDragControls = target === null || target === void 0 ? void 0 : target.closest(`.${ClassName.DRAG_ROW_CONTROLS}`);
97
+ const rowIndex = target === null || target === void 0 ? void 0 : target.getAttribute('data-start-index');
95
98
 
96
- // avoid updating if event target is not related
97
- if (!isParentDragControls || !rowIndex) {
98
- return;
99
+ // avoid updating if event target is not related
100
+ if (!isParentDragControls || !rowIndex) {
101
+ return;
102
+ }
103
+ updateCellHoverLocation(Number(rowIndex));
104
+ } else {
105
+ const isParentDragControls = e.nativeEvent.target.closest(`.${ClassName.DRAG_ROW_CONTROLS}`);
106
+ const rowIndex = e.nativeEvent.target.getAttribute('data-start-index');
107
+
108
+ // avoid updating if event target is not related
109
+ if (!isParentDragControls || !rowIndex) {
110
+ return;
111
+ }
112
+ updateCellHoverLocation(Number(rowIndex));
99
113
  }
100
- updateCellHoverLocation(Number(rowIndex));
101
114
  }, [updateCellHoverLocation]);
102
115
  const rowIndexes = useMemo(() => {
103
116
  return [rowIndex];
@@ -176,7 +176,13 @@ export var changeColumnWidthByStep = function changeColumnWidthByStep(_ref4) {
176
176
  var map = TableMap.get(originalTable);
177
177
  var domAtPos = view.domAtPos.bind(view);
178
178
  var colIndex = map.colCount($cell.pos - tableStartPosition) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
179
- var dom = domAtPos(tableStartPosition).node;
179
+ var dom = null;
180
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
181
+ var domAtPosition = domAtPos(tableStartPosition);
182
+ dom = domAtPosition.node instanceof HTMLTableElement ? domAtPosition.node : null;
183
+ } else {
184
+ dom = domAtPos(tableStartPosition).node;
185
+ }
180
186
  if (dom && dom.nodeName !== 'TABLE') {
181
187
  dom = dom.closest('table');
182
188
  }
@@ -396,7 +396,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
396
396
  this.focused = isCurrentTableSelected;
397
397
  var wrapper = tree.wrapper;
398
398
  var tableContainer = wrapper.parentElement;
399
- var tableContentWrapper = tableContainer.parentElement;
399
+ var tableContentWrapper = tableContainer === null || tableContainer === void 0 ? void 0 : tableContainer.parentElement;
400
400
  var layoutContainer = tableContentWrapper && tableContentWrapper.parentElement;
401
401
  if (isCurrentTableSelected) {
402
402
  this.colControlsOffset = tableControlsSpacing;
@@ -56,13 +56,13 @@ export var generateColgroup = function generateColgroup(table, tableRef) {
56
56
  export var insertColgroupFromNode = function insertColgroupFromNode(tableRef, table) {
57
57
  var isTableScalingEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
58
58
  var shouldRemove = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
59
- var colgroup = tableRef.querySelector('colgroup');
59
+ var colgroup = tableRef === null || tableRef === void 0 ? void 0 : tableRef.querySelector('colgroup');
60
60
  if (colgroup && shouldRemove) {
61
- tableRef.removeChild(colgroup);
61
+ tableRef === null || tableRef === void 0 || tableRef.removeChild(colgroup);
62
62
  }
63
- colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef : undefined);
63
+ colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef !== null && tableRef !== void 0 ? tableRef : undefined : undefined);
64
64
  if (shouldRemove) {
65
- tableRef.insertBefore(colgroup, tableRef.firstChild);
65
+ tableRef === null || tableRef === void 0 || tableRef.insertBefore(colgroup, tableRef === null || tableRef === void 0 ? void 0 : tableRef.firstChild);
66
66
  }
67
67
  return colgroup.children;
68
68
  };
@@ -93,7 +93,7 @@ export var getTableContainerElementWidth = function getTableContainerElementWidt
93
93
  export var getTableScalingPercent = function getTableScalingPercent(table, tableRef) {
94
94
  var _tableRef$parentEleme;
95
95
  var tableWidth = getTableContainerElementWidth(table);
96
- var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
96
+ var renderWidth = (tableRef === null || tableRef === void 0 || (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
97
97
  // minus 1 here to avoid any 1px scroll in Firefox
98
98
  var scalePercent = (renderWidth - 1) / tableWidth;
99
99
  scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
@@ -17,7 +17,7 @@ export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, t
17
17
  var _tableRef$closest;
18
18
  // when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
19
19
  var tableWidth = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth;
20
- var tableContainerWidth = (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
20
+ var tableContainerWidth = tableRef === null || tableRef === void 0 || (_tableRef$closest = tableRef.closest('.resizer-item')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
21
21
  var isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
22
22
  resizeAmount = amount * 2;
23
23
  if (isOverflowed) {
@@ -48,11 +48,13 @@ export var resizeColumn = function resizeColumn(resizeState, colIndex, amount, t
48
48
  };
49
49
  var updateTable = function updateTable(resizeAmount, tableRef, tableNode) {
50
50
  var currentWidth = getTableContainerElementWidth(tableNode);
51
- var resizingContainer = tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
51
+ var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
52
52
  var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
53
53
  if (resizingContainer && resizingItem) {
54
54
  var newWidth = "".concat(currentWidth + resizeAmount, "px");
55
- tableRef.style.width = newWidth;
55
+ if (tableRef) {
56
+ tableRef.style.width = newWidth;
57
+ }
56
58
  resizingContainer.style.width = newWidth;
57
59
  resizingItem.style.width = newWidth;
58
60
  }
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
5
5
  import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
6
6
  import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { getSelectedTableInfo } from '../../../utils';
8
9
  import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
9
10
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
@@ -85,8 +86,8 @@ export var getResizeState = function getResizeState(_ref) {
85
86
 
86
87
  // updates Colgroup DOM node with new widths
87
88
  export var updateColgroup = function updateColgroup(state, tableRef, tableNode, isTableScalingEnabled) {
88
- var cols = tableRef.querySelectorAll('col');
89
- var columnsCount = cols.length;
89
+ var cols = tableRef === null || tableRef === void 0 ? void 0 : tableRef.querySelectorAll('col');
90
+ var columnsCount = cols === null || cols === void 0 ? void 0 : cols.length;
90
91
  /**
91
92
  updateColgroup will update whole table scale when click the column resize handle, this behavior will affect when table overflowed, when now resize handle been dragged and extend to make table overflowed, table will show overflow. This need to be confirmed because it conflict with how isTableScalingEnabled work.
92
93
  We don't want to scale the table when resizing columns, only when viewpoint shrinks the table.
@@ -98,11 +99,11 @@ export var updateColgroup = function updateColgroup(state, tableRef, tableNode,
98
99
  return column && !!column.width;
99
100
  }) // if width is 0, we dont want to apply that.
100
101
  .forEach(function (column, i) {
101
- var fixedColWidth = getColWidthFix(column.width, columnsCount);
102
+ var fixedColWidth = getColWidthFix(column.width, columnsCount !== null && columnsCount !== void 0 ? columnsCount : 0);
102
103
  var scaledWidth = fixedColWidth * scalePercent;
103
104
  var finalWidth = Math.max(scaledWidth, tableCellMinWidth);
104
105
  // we aren't handling the remaining pixels here when the 48px min width is reached
105
- if (cols[i]) {
106
+ if (cols !== null && cols !== void 0 && cols[i]) {
106
107
  cols[i].style.width = "".concat(finalWidth, "px");
107
108
  }
108
109
  });
@@ -111,8 +112,8 @@ export var updateColgroup = function updateColgroup(state, tableRef, tableNode,
111
112
  return column && !!column.width;
112
113
  }) // if width is 0, we dont want to apply that.
113
114
  .forEach(function (column, i) {
114
- if (cols[i]) {
115
- cols[i].style.width = "".concat(getColWidthFix(column.width, columnsCount), "px");
115
+ if (cols !== null && cols !== void 0 && cols[i]) {
116
+ cols[i].style.width = "".concat(getColWidthFix(column.width, columnsCount !== null && columnsCount !== void 0 ? columnsCount : 0), "px");
116
117
  }
117
118
  });
118
119
  }
@@ -312,7 +313,8 @@ export var getNewResizeStateFromSelectedColumns = function getNewResizeStateFrom
312
313
  return;
313
314
  }
314
315
  var maybeTable = domAtPos(table.start).node;
315
- var tableRef = maybeTable.closest('table');
316
+ var maybeTableElement = maybeTable instanceof HTMLElement ? maybeTable : null;
317
+ var tableRef = getBooleanFF('platform.editor.explicit-html-element-check') ? maybeTableElement === null || maybeTableElement === void 0 ? void 0 : maybeTableElement.closest('table') : maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.closest('table');
316
318
  if (!tableRef) {
317
319
  return;
318
320
  }
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
5
  import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { getTableContainerElementWidth, getTableElementWidth, hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
8
9
  import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
9
10
  import { getResizeState } from '../pm-plugins/table-resizing/utils/resize-state';
@@ -99,7 +100,8 @@ export var rescaleColumns = function rescaleColumns() {
99
100
  var newTable = tr.doc.nodeAt(table.pos);
100
101
  var domAtPos = view.domAtPos.bind(view);
101
102
  var maybeTable = domAtPos(table.start).node;
102
- var tableRef = maybeTable.closest('table');
103
+ var maybeTableElement = getBooleanFF('platform.editor.explicit-html-element-check') ? maybeTable instanceof HTMLElement ? maybeTable : null : maybeTable;
104
+ var tableRef = maybeTableElement === null || maybeTableElement === void 0 ? void 0 : maybeTableElement.closest('table');
103
105
  if (!tableRef || !newTable) {
104
106
  return tr;
105
107
  }
@@ -5,6 +5,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'reac
5
5
  import { injectIntl } from 'react-intl-next';
6
6
  import { CellSelection } from '@atlaskit/editor-tables';
7
7
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
9
10
  import { clearHoverSelection } from '../../../commands';
10
11
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
@@ -90,14 +91,26 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
90
91
  }
91
92
  }, [editorView, tableActive]);
92
93
  var handleMouseMove = useCallback(function (e) {
93
- var isParentDragControls = e.nativeEvent.target.closest(".".concat(ClassName.DRAG_ROW_CONTROLS));
94
- var rowIndex = e.nativeEvent.target.getAttribute('data-start-index');
94
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
95
+ var target = e.nativeEvent.target instanceof Element ? e.nativeEvent.target : null;
96
+ var isParentDragControls = target === null || target === void 0 ? void 0 : target.closest(".".concat(ClassName.DRAG_ROW_CONTROLS));
97
+ var _rowIndex = target === null || target === void 0 ? void 0 : target.getAttribute('data-start-index');
95
98
 
96
- // avoid updating if event target is not related
97
- if (!isParentDragControls || !rowIndex) {
98
- return;
99
+ // avoid updating if event target is not related
100
+ if (!isParentDragControls || !_rowIndex) {
101
+ return;
102
+ }
103
+ updateCellHoverLocation(Number(_rowIndex));
104
+ } else {
105
+ var _isParentDragControls = e.nativeEvent.target.closest(".".concat(ClassName.DRAG_ROW_CONTROLS));
106
+ var _rowIndex2 = e.nativeEvent.target.getAttribute('data-start-index');
107
+
108
+ // avoid updating if event target is not related
109
+ if (!_isParentDragControls || !_rowIndex2) {
110
+ return;
111
+ }
112
+ updateCellHoverLocation(Number(_rowIndex2));
99
113
  }
100
- updateCellHoverLocation(Number(rowIndex));
101
114
  }, [updateCellHoverLocation]);
102
115
  var rowIndexes = useMemo(function () {
103
116
  return [rowIndex];
@@ -10,7 +10,7 @@ type Col = Array<string | {
10
10
  */
11
11
  export declare const getColWidthFix: (colwidth: number, tableColumnCount: number) => number;
12
12
  export declare const generateColgroup: (table: PmNode, tableRef?: HTMLElement) => Col[];
13
- export declare const insertColgroupFromNode: (tableRef: HTMLTableElement, table: PmNode, isTableScalingEnabled?: boolean, shouldRemove?: boolean) => HTMLCollection;
13
+ export declare const insertColgroupFromNode: (tableRef: HTMLTableElement | null, table: PmNode, isTableScalingEnabled?: boolean, shouldRemove?: boolean) => HTMLCollection;
14
14
  export declare const hasTableBeenResized: (table: PmNode) => boolean;
15
15
  /**
16
16
  * Check if a table has all the column width set to tableCellMinWidth(48px) or null
@@ -24,5 +24,5 @@ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getE
24
24
  */
25
25
  export declare const getTableElementWidth: (table: PMNode) => number;
26
26
  export declare const getTableContainerElementWidth: (table: PMNode) => number;
27
- export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement) => number;
27
+ export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement | null) => number;
28
28
  export {};
@@ -1,3 +1,3 @@
1
1
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { ResizeState } from './types';
3
- export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean) => ResizeState;
3
+ export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean) => ResizeState;
@@ -7,7 +7,7 @@ export declare const getResizeState: ({ minWidth, maxSize, table, tableRef, star
7
7
  minWidth: number;
8
8
  maxSize: number;
9
9
  table: PMNode;
10
- tableRef: HTMLTableElement;
10
+ tableRef: HTMLTableElement | null;
11
11
  start: number;
12
12
  domAtPos: (pos: number) => {
13
13
  node: Node;
@@ -15,7 +15,7 @@ export declare const getResizeState: ({ minWidth, maxSize, table, tableRef, star
15
15
  };
16
16
  isTableScalingEnabled: boolean;
17
17
  }) => ResizeState;
18
- export declare const updateColgroup: (state: ResizeState, tableRef: HTMLElement, tableNode?: PMNode, isTableScalingEnabled?: boolean) => void;
18
+ export declare const updateColgroup: (state: ResizeState, tableRef: HTMLElement | null, tableNode?: PMNode, isTableScalingEnabled?: boolean) => void;
19
19
  export declare const getTotalWidth: ({ cols }: ResizeState) => number;
20
20
  export declare const adjustColumnsWidths: (resizeState: ResizeState, maxSize: number) => ResizeState;
21
21
  export declare const evenAllColumnsWidths: (resizeState: ResizeState) => ResizeState;
@@ -10,7 +10,7 @@ type Col = Array<string | {
10
10
  */
11
11
  export declare const getColWidthFix: (colwidth: number, tableColumnCount: number) => number;
12
12
  export declare const generateColgroup: (table: PmNode, tableRef?: HTMLElement) => Col[];
13
- export declare const insertColgroupFromNode: (tableRef: HTMLTableElement, table: PmNode, isTableScalingEnabled?: boolean, shouldRemove?: boolean) => HTMLCollection;
13
+ export declare const insertColgroupFromNode: (tableRef: HTMLTableElement | null, table: PmNode, isTableScalingEnabled?: boolean, shouldRemove?: boolean) => HTMLCollection;
14
14
  export declare const hasTableBeenResized: (table: PmNode) => boolean;
15
15
  /**
16
16
  * Check if a table has all the column width set to tableCellMinWidth(48px) or null
@@ -24,5 +24,5 @@ export declare const getTableMaxWidth: ({ table, tableStart, state, layout, getE
24
24
  */
25
25
  export declare const getTableElementWidth: (table: PMNode) => number;
26
26
  export declare const getTableContainerElementWidth: (table: PMNode) => number;
27
- export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement) => number;
27
+ export declare const getTableScalingPercent: (table: PMNode, tableRef: HTMLElement | null) => number;
28
28
  export {};
@@ -1,3 +1,3 @@
1
1
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { ResizeState } from './types';
3
- export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean) => ResizeState;
3
+ export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean) => ResizeState;
@@ -7,7 +7,7 @@ export declare const getResizeState: ({ minWidth, maxSize, table, tableRef, star
7
7
  minWidth: number;
8
8
  maxSize: number;
9
9
  table: PMNode;
10
- tableRef: HTMLTableElement;
10
+ tableRef: HTMLTableElement | null;
11
11
  start: number;
12
12
  domAtPos: (pos: number) => {
13
13
  node: Node;
@@ -15,7 +15,7 @@ export declare const getResizeState: ({ minWidth, maxSize, table, tableRef, star
15
15
  };
16
16
  isTableScalingEnabled: boolean;
17
17
  }) => ResizeState;
18
- export declare const updateColgroup: (state: ResizeState, tableRef: HTMLElement, tableNode?: PMNode, isTableScalingEnabled?: boolean) => void;
18
+ export declare const updateColgroup: (state: ResizeState, tableRef: HTMLElement | null, tableNode?: PMNode, isTableScalingEnabled?: boolean) => void;
19
19
  export declare const getTotalWidth: ({ cols }: ResizeState) => number;
20
20
  export declare const adjustColumnsWidths: (resizeState: ResizeState, maxSize: number) => ResizeState;
21
21
  export declare const evenAllColumnsWidths: (resizeState: ResizeState) => ResizeState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.10.0",
3
+ "version": "7.10.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -147,6 +147,9 @@
147
147
  },
148
148
  "platform.editor.table.colum-resizing-improvements": {
149
149
  "type": "boolean"
150
+ },
151
+ "platform.editor.explicit-html-element-check": {
152
+ "type": "boolean"
150
153
  }
151
154
  }
152
155
  }
@@ -319,11 +319,19 @@ export const changeColumnWidthByStep =
319
319
  ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) -
320
320
  1;
321
321
 
322
- let dom: HTMLTableElement = domAtPos(tableStartPosition)
323
- .node as HTMLTableElement;
322
+ let dom: HTMLTableElement | null = null;
323
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
324
+ const domAtPosition = domAtPos(tableStartPosition);
325
+ dom =
326
+ domAtPosition.node instanceof HTMLTableElement
327
+ ? domAtPosition.node
328
+ : null;
329
+ } else {
330
+ dom = domAtPos(tableStartPosition).node as HTMLTableElement;
331
+ }
324
332
 
325
333
  if (dom && dom.nodeName !== 'TABLE') {
326
- dom = dom.closest('table') as HTMLTableElement;
334
+ dom = dom.closest('table');
327
335
  }
328
336
 
329
337
  const cellAttrs = cell?.node.attrs;
@@ -494,8 +494,8 @@ export default class TableRow
494
494
 
495
495
  const { wrapper } = tree;
496
496
 
497
- const tableContainer = wrapper.parentElement!;
498
- const tableContentWrapper = tableContainer.parentElement;
497
+ const tableContainer = wrapper.parentElement;
498
+ const tableContentWrapper = tableContainer?.parentElement;
499
499
 
500
500
  const layoutContainer =
501
501
  tableContentWrapper && tableContentWrapper.parentElement;
@@ -69,22 +69,22 @@ export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
69
69
  };
70
70
 
71
71
  export const insertColgroupFromNode = (
72
- tableRef: HTMLTableElement,
72
+ tableRef: HTMLTableElement | null,
73
73
  table: PmNode,
74
74
  isTableScalingEnabled = false,
75
75
  shouldRemove = true,
76
76
  ): HTMLCollection => {
77
- let colgroup = tableRef.querySelector('colgroup') as HTMLElement;
77
+ let colgroup = tableRef?.querySelector('colgroup') as HTMLElement;
78
78
  if (colgroup && shouldRemove) {
79
- tableRef.removeChild(colgroup);
79
+ tableRef?.removeChild(colgroup);
80
80
  }
81
81
 
82
82
  colgroup = renderColgroupFromNode(
83
83
  table,
84
- isTableScalingEnabled ? tableRef : undefined,
84
+ isTableScalingEnabled ? tableRef ?? undefined : undefined,
85
85
  );
86
86
  if (shouldRemove) {
87
- tableRef.insertBefore(colgroup, tableRef.firstChild);
87
+ tableRef?.insertBefore(colgroup, tableRef?.firstChild);
88
88
  }
89
89
 
90
90
  return colgroup.children;
@@ -158,10 +158,10 @@ export const getTableContainerElementWidth = (table: PMNode) => {
158
158
 
159
159
  export const getTableScalingPercent = (
160
160
  table: PMNode,
161
- tableRef: HTMLElement,
161
+ tableRef: HTMLElement | null,
162
162
  ) => {
163
163
  const tableWidth = getTableContainerElementWidth(table);
164
- let renderWidth = tableRef.parentElement?.clientWidth || tableWidth;
164
+ let renderWidth = tableRef?.parentElement?.clientWidth || tableWidth;
165
165
  // minus 1 here to avoid any 1px scroll in Firefox
166
166
  let scalePercent = (renderWidth - 1) / tableWidth;
167
167
  scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
@@ -13,7 +13,7 @@ export const resizeColumn = (
13
13
  resizeState: ResizeState,
14
14
  colIndex: number,
15
15
  amount: number,
16
- tableRef: HTMLElement,
16
+ tableRef: HTMLElement | null,
17
17
  tableNode: PmNode,
18
18
  selectedColumns?: number[],
19
19
  isTableScalingEnabled = false,
@@ -25,7 +25,7 @@ export const resizeColumn = (
25
25
  if (getBooleanFF('platform.editor.table.colum-resizing-improvements')) {
26
26
  // when table initially not overflow, but enter overflow, we need to calculate the resize amount by two part, before and after overflow, before overflow should be double, after should not be double.
27
27
  const tableWidth = tableRef?.clientWidth;
28
- const tableContainerWidth = tableRef.closest('.resizer-item')?.clientWidth;
28
+ const tableContainerWidth = tableRef?.closest('.resizer-item')?.clientWidth;
29
29
 
30
30
  const isOverflowed = !!(
31
31
  tableWidth &&
@@ -92,18 +92,20 @@ export const resizeColumn = (
92
92
 
93
93
  const updateTable = (
94
94
  resizeAmount: number,
95
- tableRef: HTMLElement,
95
+ tableRef: HTMLElement | null,
96
96
  tableNode: PmNode,
97
97
  ) => {
98
98
  const currentWidth = getTableContainerElementWidth(tableNode);
99
- const resizingContainer = tableRef.closest(
99
+ const resizingContainer = tableRef?.closest(
100
100
  `.${ClassName.TABLE_RESIZER_CONTAINER}`,
101
101
  );
102
102
  const resizingItem = resizingContainer?.querySelector('.resizer-item');
103
103
 
104
104
  if (resizingContainer && resizingItem) {
105
105
  const newWidth = `${currentWidth + resizeAmount}px`;
106
- tableRef.style.width = newWidth;
106
+ if (tableRef) {
107
+ tableRef.style.width = newWidth;
108
+ }
107
109
  (resizingContainer as HTMLElement).style.width = newWidth;
108
110
  (resizingItem as HTMLElement).style.width = newWidth;
109
111
  }
@@ -8,6 +8,7 @@ import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
8
8
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
9
9
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
10
10
  import type { Rect } from '@atlaskit/editor-tables/table-map';
11
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
12
 
12
13
  import { getSelectedTableInfo } from '../../../utils';
13
14
 
@@ -34,7 +35,7 @@ export const getResizeState = ({
34
35
  minWidth: number;
35
36
  maxSize: number;
36
37
  table: PMNode;
37
- tableRef: HTMLTableElement;
38
+ tableRef: HTMLTableElement | null;
38
39
  start: number;
39
40
  domAtPos: (pos: number) => { node: Node; offset: number };
40
41
  isTableScalingEnabled: boolean;
@@ -107,12 +108,12 @@ export const getResizeState = ({
107
108
  // updates Colgroup DOM node with new widths
108
109
  export const updateColgroup = (
109
110
  state: ResizeState,
110
- tableRef: HTMLElement,
111
+ tableRef: HTMLElement | null,
111
112
  tableNode?: PMNode,
112
113
  isTableScalingEnabled?: boolean,
113
114
  ): void => {
114
- const cols = tableRef.querySelectorAll('col');
115
- const columnsCount = cols.length;
115
+ const cols = tableRef?.querySelectorAll('col');
116
+ const columnsCount = cols?.length;
116
117
  /**
117
118
  updateColgroup will update whole table scale when click the column resize handle, this behavior will affect when table overflowed, when now resize handle been dragged and extend to make table overflowed, table will show overflow. This need to be confirmed because it conflict with how isTableScalingEnabled work.
118
119
  We don't want to scale the table when resizing columns, only when viewpoint shrinks the table.
@@ -123,11 +124,11 @@ export const updateColgroup = (
123
124
  state.cols
124
125
  .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
125
126
  .forEach((column, i) => {
126
- const fixedColWidth = getColWidthFix(column.width, columnsCount);
127
+ const fixedColWidth = getColWidthFix(column.width, columnsCount ?? 0);
127
128
  const scaledWidth = fixedColWidth * scalePercent;
128
129
  const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
129
130
  // we aren't handling the remaining pixels here when the 48px min width is reached
130
- if (cols[i]) {
131
+ if (cols?.[i]) {
131
132
  cols[i].style.width = `${finalWidth}px`;
132
133
  }
133
134
  });
@@ -135,10 +136,10 @@ export const updateColgroup = (
135
136
  state.cols
136
137
  .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
137
138
  .forEach((column, i) => {
138
- if (cols[i]) {
139
+ if (cols?.[i]) {
139
140
  cols[i].style.width = `${getColWidthFix(
140
141
  column.width,
141
- columnsCount,
142
+ columnsCount ?? 0,
142
143
  )}px`;
143
144
  }
144
145
  });
@@ -361,8 +362,13 @@ export const getNewResizeStateFromSelectedColumns = (
361
362
  return;
362
363
  }
363
364
 
364
- const maybeTable = domAtPos(table.start).node as HTMLElement;
365
- const tableRef = maybeTable.closest('table');
365
+ const maybeTable = domAtPos(table.start).node;
366
+
367
+ const maybeTableElement =
368
+ maybeTable instanceof HTMLElement ? maybeTable : null;
369
+ const tableRef = getBooleanFF('platform.editor.explicit-html-element-check')
370
+ ? maybeTableElement?.closest('table')
371
+ : (maybeTable as HTMLElement)?.closest('table');
366
372
 
367
373
  if (!tableRef) {
368
374
  return;
@@ -6,6 +6,7 @@ import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
6
6
  import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
10
 
10
11
  import type { ResizeState } from '../pm-plugins/table-resizing/utils';
11
12
  import {
@@ -119,8 +120,15 @@ export const rescaleColumns =
119
120
 
120
121
  const newTable = tr.doc.nodeAt(table.pos);
121
122
  const domAtPos = view.domAtPos.bind(view);
122
- const maybeTable = domAtPos(table.start).node as HTMLElement;
123
- const tableRef = maybeTable.closest('table');
123
+ const maybeTable = domAtPos(table.start).node;
124
+ const maybeTableElement = getBooleanFF(
125
+ 'platform.editor.explicit-html-element-check',
126
+ )
127
+ ? maybeTable instanceof HTMLElement
128
+ ? maybeTable
129
+ : null
130
+ : (maybeTable as HTMLElement | null);
131
+ const tableRef = maybeTableElement?.closest('table');
124
132
 
125
133
  if (!tableRef || !newTable) {
126
134
  return tr;
@@ -16,6 +16,7 @@ import type { Selection } from '@atlaskit/editor-prosemirror/state';
16
16
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
17
17
  import { CellSelection } from '@atlaskit/editor-tables';
18
18
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
19
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
19
20
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
20
21
  import { token } from '@atlaskit/tokens';
21
22
 
@@ -142,19 +143,35 @@ const DragControlsComponent = ({
142
143
 
143
144
  const handleMouseMove = useCallback(
144
145
  (e: MouseEvent) => {
145
- const isParentDragControls = (e.nativeEvent.target as Element).closest(
146
- `.${ClassName.DRAG_ROW_CONTROLS}`,
147
- );
148
- const rowIndex = (e.nativeEvent.target as Element).getAttribute(
149
- 'data-start-index',
150
- );
146
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
147
+ const target =
148
+ e.nativeEvent.target instanceof Element ? e.nativeEvent.target : null;
149
+ const isParentDragControls = target?.closest(
150
+ `.${ClassName.DRAG_ROW_CONTROLS}`,
151
+ );
152
+ const rowIndex = target?.getAttribute('data-start-index');
151
153
 
152
- // avoid updating if event target is not related
153
- if (!isParentDragControls || !rowIndex) {
154
- return;
155
- }
154
+ // avoid updating if event target is not related
155
+ if (!isParentDragControls || !rowIndex) {
156
+ return;
157
+ }
156
158
 
157
- updateCellHoverLocation(Number(rowIndex));
159
+ updateCellHoverLocation(Number(rowIndex));
160
+ } else {
161
+ const isParentDragControls = (e.nativeEvent.target as Element).closest(
162
+ `.${ClassName.DRAG_ROW_CONTROLS}`,
163
+ );
164
+ const rowIndex = (e.nativeEvent.target as Element).getAttribute(
165
+ 'data-start-index',
166
+ );
167
+
168
+ // avoid updating if event target is not related
169
+ if (!isParentDragControls || !rowIndex) {
170
+ return;
171
+ }
172
+
173
+ updateCellHoverLocation(Number(rowIndex));
174
+ }
158
175
  },
159
176
  [updateCellHoverLocation],
160
177
  );