@atlaskit/editor-plugin-table 7.10.0 → 7.10.2

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 (64) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/commands/column-resize.js +7 -1
  3. package/dist/cjs/commands/insert.js +4 -7
  4. package/dist/cjs/commands/misc.js +10 -3
  5. package/dist/cjs/nodeviews/TableRow.js +1 -1
  6. package/dist/cjs/plugin.js +1 -1
  7. package/dist/cjs/pm-plugins/analytics/plugin.js +17 -22
  8. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  9. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +1 -1
  10. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  11. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  12. package/dist/cjs/transforms/column-width.js +3 -1
  13. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  14. package/dist/es2019/commands/column-resize.js +7 -1
  15. package/dist/es2019/commands/insert.js +4 -7
  16. package/dist/es2019/commands/misc.js +10 -3
  17. package/dist/es2019/nodeviews/TableRow.js +1 -1
  18. package/dist/es2019/plugin.js +1 -1
  19. package/dist/es2019/pm-plugins/analytics/plugin.js +21 -26
  20. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  21. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +1 -1
  22. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  23. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  24. package/dist/es2019/transforms/column-width.js +3 -1
  25. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  26. package/dist/esm/commands/column-resize.js +7 -1
  27. package/dist/esm/commands/insert.js +4 -7
  28. package/dist/esm/commands/misc.js +10 -3
  29. package/dist/esm/nodeviews/TableRow.js +1 -1
  30. package/dist/esm/plugin.js +1 -1
  31. package/dist/esm/pm-plugins/analytics/plugin.js +17 -22
  32. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  33. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +1 -1
  34. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  35. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  36. package/dist/esm/transforms/column-width.js +3 -1
  37. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  38. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  39. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  40. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  41. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
  42. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -2
  43. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +4 -4
  44. package/dist/types/ui/TableFloatingControls/index.d.ts +2 -2
  45. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  46. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  47. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  48. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
  49. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -2
  50. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +4 -4
  51. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +2 -2
  52. package/package.json +8 -8
  53. package/src/commands/column-resize.ts +11 -3
  54. package/src/commands/insert.ts +7 -13
  55. package/src/commands/misc.ts +14 -8
  56. package/src/nodeviews/TableRow.ts +2 -2
  57. package/src/plugin.tsx +1 -3
  58. package/src/pm-plugins/analytics/plugin.ts +24 -33
  59. package/src/pm-plugins/table-resizing/utils/colgroup.ts +5 -5
  60. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  61. package/src/pm-plugins/table-resizing/utils/resize-column.ts +7 -5
  62. package/src/pm-plugins/table-resizing/utils/resize-state.ts +16 -10
  63. package/src/transforms/column-width.ts +10 -2
  64. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +28 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.10.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#95062](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/95062) [`06171107f90c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/06171107f90c) - Cleanup analytics moved event feature flag.
8
+
9
+ ## 7.10.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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.
14
+
3
15
  ## 7.10.0
4
16
 
5
17
  ### 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
  }
@@ -12,7 +12,6 @@ var _state = require("@atlaskit/editor-prosemirror/state");
12
12
  var _utils = require("@atlaskit/editor-prosemirror/utils");
13
13
  var _tableMap = require("@atlaskit/editor-tables/table-map");
14
14
  var _utils2 = require("@atlaskit/editor-tables/utils");
15
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
15
  var _commands = require("../pm-plugins/analytics/commands");
17
16
  var _tableAnalytics = require("../pm-plugins/table-analytics");
18
17
  var _columnWidth = require("../transforms/column-width");
@@ -46,7 +45,7 @@ function addColumnAt() {
46
45
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
47
46
  updatedTr = (0, _columnWidth.rescaleColumns)(isTableScalingEnabled)(table, view)(updatedTr);
48
47
  }
49
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event') && view) {
48
+ if (view) {
50
49
  updatedTr = (0, _commands.updateRowOrColumnMovedTransform)({
51
50
  type: 'column'
52
51
  }, 'addRowOrColumn')(view.state, updatedTr);
@@ -134,11 +133,9 @@ var insertRow = exports.insertRow = function insertRow(row, moveCursorToTheNewRo
134
133
  } else {
135
134
  tr.setSelection(selection.map(tr.doc, tr.mapping));
136
135
  }
137
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event')) {
138
- (0, _commands.updateRowOrColumnMovedTransform)({
139
- type: 'row'
140
- }, 'addRowOrColumn')(state, tr);
141
- }
136
+ (0, _commands.updateRowOrColumnMovedTransform)({
137
+ type: 'row'
138
+ }, 'addRowOrColumn')(state, tr);
142
139
  dispatch(tr);
143
140
  }
144
141
  return true;
@@ -195,9 +195,16 @@ var getTableElementMoveTypeBySlice = exports.getTableElementMoveTypeBySlice = fu
195
195
  if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
196
196
  return 'row';
197
197
  }
198
- var map = _tableMap.TableMap.get(currentTable.node);
199
- var slicedMap = _tableMap.TableMap.get(slice.content.firstChild);
200
- return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
198
+
199
+ // `TableMap.get` can throw if the content is invalid - in which case we should just
200
+ // return undefined
201
+ try {
202
+ var map = _tableMap.TableMap.get(currentTable.node);
203
+ var slicedMap = _tableMap.TableMap.get(slice.content.firstChild);
204
+ return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
205
+ } catch (e) {
206
+ return undefined;
207
+ }
201
208
  };
202
209
  var isInsideFirstCellOfRowOrColumn = exports.isInsideFirstCellOfRowOrColumn = function isInsideFirstCellOfRowOrColumn(selection, type) {
203
210
  var table = (0, _utils2.findTable)(selection);
@@ -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;
@@ -255,7 +255,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
255
255
  plugin: function plugin(_ref15) {
256
256
  var dispatch = _ref15.dispatch,
257
257
  dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
258
- return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event') ? (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent) : undefined;
258
+ return (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent);
259
259
  }
260
260
  }, {
261
261
  name: 'tableGetEditorViewReferencePlugin',
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createPlugin = void 0;
7
7
  var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
9
  var _misc = require("../../commands/misc");
11
10
  var _commands = require("./commands");
12
11
  var _pluginFactory = require("./plugin-factory");
@@ -40,33 +39,29 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
40
39
  handlePaste: function handlePaste(_ref, event, slice) {
41
40
  var state = _ref.state,
42
41
  dispatch = _ref.dispatch;
43
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event')) {
44
- var schema = state.schema;
45
- var type = (0, _misc.getTableElementMoveTypeBySlice)(slice, state);
42
+ var schema = state.schema;
43
+ var type = (0, _misc.getTableElementMoveTypeBySlice)(slice, state);
46
44
 
47
- // if the selection wasn't in the first cell of a row or column, don't count it
48
- if (!type || !(0, _misc.isInsideFirstCellOfRowOrColumn)(state.selection, type)) {
49
- return;
50
- }
51
- var count = (0, _misc.countCellsInSlice)(slice, schema, type);
52
- (0, _commands.updateRowOrColumnMoved)({
53
- numberOfCells: count,
54
- type: type
55
- }, 'pasted')(state, dispatch);
45
+ // if the selection wasn't in the first cell of a row or column, don't count it
46
+ if (!type || !(0, _misc.isInsideFirstCellOfRowOrColumn)(state.selection, type)) {
47
+ return;
56
48
  }
49
+ var count = (0, _misc.countCellsInSlice)(slice, schema, type);
50
+ (0, _commands.updateRowOrColumnMoved)({
51
+ numberOfCells: count,
52
+ type: type
53
+ }, 'pasted')(state, dispatch);
57
54
  },
58
55
  transformCopied: function transformCopied(slice, _ref2) {
59
56
  var state = _ref2.state,
60
57
  dispatch = _ref2.dispatch;
61
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event')) {
62
- var schema = state.schema;
63
- var type = (0, _misc.getTableSelectionType)(state.selection);
64
- var count = (0, _misc.countCellsInSlice)(slice, schema, type);
65
- (0, _commands.updateRowOrColumnMoved)({
66
- numberOfCells: count,
67
- type: type
68
- }, 'copyOrCut')(state, dispatch);
69
- }
58
+ var schema = state.schema;
59
+ var type = (0, _misc.getTableSelectionType)(state.selection);
60
+ var count = (0, _misc.countCellsInSlice)(slice, schema, type);
61
+ (0, _commands.updateRowOrColumnMoved)({
62
+ numberOfCells: count,
63
+ type: type
64
+ }, 'copyOrCut')(state, dispatch);
70
65
  return slice;
71
66
  }
72
67
  }
@@ -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
  }
@@ -5,7 +5,6 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
8
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
8
  import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
10
9
  import { META_KEYS } from '../pm-plugins/table-analytics';
11
10
  import { rescaleColumns } from '../transforms/column-width';
@@ -34,7 +33,7 @@ export function addColumnAt(isTableScalingEnabled = false) {
34
33
  // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
35
34
  updatedTr = rescaleColumns(isTableScalingEnabled)(table, view)(updatedTr);
36
35
  }
37
- if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event') && view) {
36
+ if (view) {
38
37
  updatedTr = updateRowOrColumnMovedTransform({
39
38
  type: 'column'
40
39
  }, 'addRowOrColumn')(view.state, updatedTr);
@@ -113,11 +112,9 @@ export const insertRow = (row, moveCursorToTheNewRow) => (state, dispatch) => {
113
112
  } else {
114
113
  tr.setSelection(selection.map(tr.doc, tr.mapping));
115
114
  }
116
- if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
117
- updateRowOrColumnMovedTransform({
118
- type: 'row'
119
- }, 'addRowOrColumn')(state, tr);
120
- }
115
+ updateRowOrColumnMovedTransform({
116
+ type: 'row'
117
+ }, 'addRowOrColumn')(state, tr);
121
118
  dispatch(tr);
122
119
  }
123
120
  return true;
@@ -201,9 +201,16 @@ export const getTableElementMoveTypeBySlice = (slice, state) => {
201
201
  if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
202
202
  return 'row';
203
203
  }
204
- const map = TableMap.get(currentTable.node);
205
- const slicedMap = TableMap.get(slice.content.firstChild);
206
- return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
204
+
205
+ // `TableMap.get` can throw if the content is invalid - in which case we should just
206
+ // return undefined
207
+ try {
208
+ const map = TableMap.get(currentTable.node);
209
+ const slicedMap = TableMap.get(slice.content.firstChild);
210
+ return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
211
+ } catch (e) {
212
+ return undefined;
213
+ }
207
214
  };
208
215
  export const isInsideFirstCellOfRowOrColumn = (selection, type) => {
209
216
  const table = findTable(selection);
@@ -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;
@@ -247,7 +247,7 @@ const tablesPlugin = ({
247
247
  plugin: ({
248
248
  dispatch,
249
249
  dispatchAnalyticsEvent
250
- }) => getBooleanFF('platform.editor.table.analytics-plugin-moved-event') ? createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent) : undefined
250
+ }) => createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent)
251
251
  }, {
252
252
  name: 'tableGetEditorViewReferencePlugin',
253
253
  plugin: () => {
@@ -1,6 +1,5 @@
1
1
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
3
  import { countCellsInSlice, getTableElementMoveTypeBySlice, getTableSelectionType, isInsideFirstCellOfRowOrColumn } from '../../commands/misc';
5
4
  import { resetRowOrColumnMovedTransform, updateRowOrColumnMoved } from './commands';
6
5
  import { createPluginState } from './plugin-factory';
@@ -34,38 +33,34 @@ export const createPlugin = (dispatch, dispatchAnalyticsEvent) => new SafePlugin
34
33
  state,
35
34
  dispatch
36
35
  }, event, slice) => {
37
- if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
38
- const {
39
- schema
40
- } = state;
41
- const type = getTableElementMoveTypeBySlice(slice, state);
36
+ const {
37
+ schema
38
+ } = state;
39
+ const type = getTableElementMoveTypeBySlice(slice, state);
42
40
 
43
- // if the selection wasn't in the first cell of a row or column, don't count it
44
- if (!type || !isInsideFirstCellOfRowOrColumn(state.selection, type)) {
45
- return;
46
- }
47
- const count = countCellsInSlice(slice, schema, type);
48
- updateRowOrColumnMoved({
49
- numberOfCells: count,
50
- type
51
- }, 'pasted')(state, dispatch);
41
+ // if the selection wasn't in the first cell of a row or column, don't count it
42
+ if (!type || !isInsideFirstCellOfRowOrColumn(state.selection, type)) {
43
+ return;
52
44
  }
45
+ const count = countCellsInSlice(slice, schema, type);
46
+ updateRowOrColumnMoved({
47
+ numberOfCells: count,
48
+ type
49
+ }, 'pasted')(state, dispatch);
53
50
  },
54
51
  transformCopied: (slice, {
55
52
  state,
56
53
  dispatch
57
54
  }) => {
58
- if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
59
- const {
60
- schema
61
- } = state;
62
- const type = getTableSelectionType(state.selection);
63
- const count = countCellsInSlice(slice, schema, type);
64
- updateRowOrColumnMoved({
65
- numberOfCells: count,
66
- type
67
- }, 'copyOrCut')(state, dispatch);
68
- }
55
+ const {
56
+ schema
57
+ } = state;
58
+ const type = getTableSelectionType(state.selection);
59
+ const count = countCellsInSlice(slice, schema, type);
60
+ updateRowOrColumnMoved({
61
+ numberOfCells: count,
62
+ type
63
+ }, 'copyOrCut')(state, dispatch);
69
64
  return slice;
70
65
  }
71
66
  }
@@ -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
  }