@atlaskit/editor-plugin-table 7.5.5 → 7.5.7

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 (100) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/commands/selection.js +23 -1
  3. package/dist/cjs/event-handlers.js +25 -9
  4. package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
  5. package/dist/cjs/nodeviews/TableCell.js +5 -30
  6. package/dist/cjs/nodeviews/TableComponent.js +96 -41
  7. package/dist/cjs/nodeviews/TableContainer.js +19 -17
  8. package/dist/cjs/nodeviews/TableResizer.js +1 -1
  9. package/dist/cjs/plugin.js +2 -3
  10. package/dist/cjs/pm-plugins/main.js +3 -18
  11. package/dist/cjs/pm-plugins/sticky-headers/types.js +1 -5
  12. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +3 -7
  13. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +11 -1
  14. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +22 -23
  15. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +2 -2
  16. package/dist/cjs/pm-plugins/table-selection-keymap.js +3 -0
  17. package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
  18. package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
  19. package/dist/cjs/utils/column-controls.js +5 -5
  20. package/dist/cjs/utils/dom.js +13 -15
  21. package/dist/es2019/commands/selection.js +22 -0
  22. package/dist/es2019/event-handlers.js +25 -9
  23. package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
  24. package/dist/es2019/nodeviews/TableCell.js +1 -24
  25. package/dist/es2019/nodeviews/TableComponent.js +69 -31
  26. package/dist/es2019/nodeviews/TableContainer.js +16 -18
  27. package/dist/es2019/nodeviews/TableResizer.js +1 -1
  28. package/dist/es2019/plugin.js +2 -3
  29. package/dist/es2019/pm-plugins/main.js +3 -18
  30. package/dist/es2019/pm-plugins/sticky-headers/types.js +0 -1
  31. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +3 -7
  32. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +10 -0
  33. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +21 -22
  34. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +2 -2
  35. package/dist/es2019/pm-plugins/table-selection-keymap.js +5 -2
  36. package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
  37. package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
  38. package/dist/es2019/utils/column-controls.js +6 -6
  39. package/dist/es2019/utils/dom.js +13 -15
  40. package/dist/esm/commands/selection.js +22 -0
  41. package/dist/esm/event-handlers.js +25 -9
  42. package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
  43. package/dist/esm/nodeviews/TableCell.js +5 -30
  44. package/dist/esm/nodeviews/TableComponent.js +96 -41
  45. package/dist/esm/nodeviews/TableContainer.js +20 -18
  46. package/dist/esm/nodeviews/TableResizer.js +1 -1
  47. package/dist/esm/plugin.js +2 -3
  48. package/dist/esm/pm-plugins/main.js +3 -18
  49. package/dist/esm/pm-plugins/sticky-headers/types.js +0 -1
  50. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +3 -7
  51. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +10 -0
  52. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +23 -24
  53. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +2 -2
  54. package/dist/esm/pm-plugins/table-selection-keymap.js +5 -2
  55. package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
  56. package/dist/esm/ui/TableFloatingControls/index.js +113 -224
  57. package/dist/esm/utils/column-controls.js +6 -6
  58. package/dist/esm/utils/dom.js +13 -15
  59. package/dist/types/commands/selection.d.ts +1 -0
  60. package/dist/types/event-handlers.d.ts +3 -4
  61. package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  62. package/dist/types/nodeviews/TableCell.d.ts +1 -5
  63. package/dist/types/nodeviews/TableComponent.d.ts +4 -0
  64. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  65. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
  66. package/dist/types/types.d.ts +0 -3
  67. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
  68. package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
  69. package/dist/types/utils/dom.d.ts +10 -2
  70. package/dist/types-ts4.5/commands/selection.d.ts +1 -0
  71. package/dist/types-ts4.5/event-handlers.d.ts +3 -4
  72. package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  73. package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
  74. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
  75. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  76. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
  77. package/dist/types-ts4.5/types.d.ts +0 -3
  78. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
  79. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
  80. package/dist/types-ts4.5/utils/dom.d.ts +10 -2
  81. package/package.json +8 -6
  82. package/src/commands/selection.ts +33 -0
  83. package/src/event-handlers.ts +105 -103
  84. package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
  85. package/src/nodeviews/TableCell.ts +0 -26
  86. package/src/nodeviews/TableComponent.tsx +81 -34
  87. package/src/nodeviews/TableContainer.tsx +19 -25
  88. package/src/nodeviews/TableResizer.tsx +1 -4
  89. package/src/plugin.tsx +5 -4
  90. package/src/pm-plugins/main.ts +3 -22
  91. package/src/pm-plugins/table-resizing/utils/colgroup.ts +3 -6
  92. package/src/pm-plugins/table-resizing/utils/misc.ts +13 -0
  93. package/src/pm-plugins/table-resizing/utils/resize-state.ts +22 -28
  94. package/src/pm-plugins/table-resizing/utils/scale-table.ts +3 -10
  95. package/src/pm-plugins/table-selection-keymap.ts +10 -0
  96. package/src/types.ts +0 -4
  97. package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
  98. package/src/ui/TableFloatingControls/index.tsx +155 -241
  99. package/src/utils/column-controls.ts +5 -6
  100. package/src/utils/dom.ts +12 -19
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.5.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#80086](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80086) [`c30ac781b469`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c30ac781b469) - Add keyboard support Cmd-A to select whole table
8
+ - [#81017](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81017) [`df5a993963d9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/df5a993963d9) - prevent scaled table columns being resized below min width
9
+
10
+ ## 7.5.6
11
+
12
+ ### Patch Changes
13
+
14
+ - [#72764](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/72764) [`1a23abba80b0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1a23abba80b0) - Minor performance improvements to reduce reflows and re-renders
15
+
3
16
  ## 7.5.5
4
17
 
5
18
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.shiftArrowUpFromTable = exports.selectRows = exports.selectColumns = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
6
+ exports.shiftArrowUpFromTable = exports.selectRows = exports.selectColumns = exports.modASelectTable = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
@@ -419,4 +419,26 @@ var shiftArrowUpFromTable = exports.shiftArrowUpFromTable = function shiftArrowU
419
419
  return false;
420
420
  };
421
421
  };
422
+ };
423
+ var modASelectTable = exports.modASelectTable = function modASelectTable(editorSelectionAPI) {
424
+ return function () {
425
+ return function (state, dispatch) {
426
+ var selection = state.selection;
427
+ var table = (0, _utils.findTable)(selection);
428
+ if (!table) {
429
+ return false;
430
+ }
431
+ var $from = selection.$from,
432
+ $to = selection.$to;
433
+ var tableSelected = (0, _utils.isTableSelected)(selection);
434
+ if (!tableSelected && $from.pos > table.start + 1 && $to.pos < table.start + table.node.nodeSize) {
435
+ return selectFullTable(editorSelectionAPI)({
436
+ node: table.node,
437
+ startPos: table.start,
438
+ dir: TableSelectionDirection.BottomToTop
439
+ })(state, dispatch);
440
+ }
441
+ return false;
442
+ };
443
+ };
422
444
  };
@@ -8,6 +8,7 @@ exports.handleMouseUp = exports.handleMouseOver = exports.handleMouseOut = expor
8
8
  exports.handleTripleClick = handleTripleClick;
9
9
  exports.withCellTracking = exports.whenTableInFocus = exports.isTableInFocus = void 0;
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
11
12
  var _analytics = require("@atlaskit/editor-common/analytics");
12
13
  var _utils = require("@atlaskit/editor-common/utils");
13
14
  var _state5 = require("@atlaskit/editor-prosemirror/state");
@@ -257,7 +258,10 @@ var handleMouseLeave = exports.handleMouseLeave = function handleMouseLeave(view
257
258
  }
258
259
  return false;
259
260
  };
260
- var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, event, elementContentRects) {
261
+
262
+ // IMPORTANT: The mouse move handler has been setup with RAF schedule to avoid Reflows which will occur as some methods
263
+ // need to access the mouse event offset position and also the target clientWidth vallue.
264
+ var handleMouseMoveDebounce = (0, _rafSchd.default)(function (view, event, offsetX) {
261
265
  if (!(event.target instanceof HTMLElement)) {
262
266
  return false;
263
267
  }
@@ -266,13 +270,12 @@ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, e
266
270
  var state = view.state,
267
271
  dispatch = view.dispatch;
268
272
  var _getPluginState6 = (0, _pluginFactory2.getPluginState)(state),
269
- insertColumnButtonIndex = _getPluginState6.insertColumnButtonIndex,
270
- isDragAndDropEnabled = _getPluginState6.isDragAndDropEnabled;
273
+ insertColumnButtonIndex = _getPluginState6.insertColumnButtonIndex;
271
274
  var _getColumnOrRowIndex9 = (0, _utils3.getColumnOrRowIndex)(element),
272
275
  _getColumnOrRowIndex10 = (0, _slicedToArray2.default)(_getColumnOrRowIndex9, 2),
273
276
  startIndex = _getColumnOrRowIndex10[0],
274
277
  endIndex = _getColumnOrRowIndex10[1];
275
- var positionColumn = (0, _utils3.getMousePositionHorizontalRelativeByElement)(event, elementContentRects, undefined, isDragAndDropEnabled) === 'right' ? endIndex : startIndex;
278
+ var positionColumn = (0, _utils3.getMousePositionHorizontalRelativeByElement)(event, offsetX, undefined) === 'right' ? endIndex : startIndex;
276
279
  if (positionColumn !== insertColumnButtonIndex) {
277
280
  return (0, _commands.showInsertColumnButton)(positionColumn)(state, dispatch);
278
281
  }
@@ -292,7 +295,7 @@ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, e
292
295
  }
293
296
  }
294
297
  if (!(0, _utils3.isResizeHandleDecoration)(element) && (0, _utils3.isCell)(element)) {
295
- var _positionColumn = (0, _utils3.getMousePositionHorizontalRelativeByElement)(event, elementContentRects, _types.RESIZE_HANDLE_AREA_DECORATION_GAP);
298
+ var _positionColumn = (0, _utils3.getMousePositionHorizontalRelativeByElement)(event, offsetX, _types.RESIZE_HANDLE_AREA_DECORATION_GAP);
296
299
  if (_positionColumn !== null) {
297
300
  var _state4 = view.state,
298
301
  _dispatch5 = view.dispatch;
@@ -317,6 +320,19 @@ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, e
317
320
  }
318
321
  }
319
322
  return false;
323
+ });
324
+ var handleMouseMove = exports.handleMouseMove = function handleMouseMove(view, event) {
325
+ if (!(event.target instanceof HTMLElement)) {
326
+ return false;
327
+ }
328
+
329
+ // NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
330
+ // within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
331
+ // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
332
+ // in the deferred callback handler.
333
+ // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
334
+ handleMouseMoveDebounce(view, event, _utils.browser.gecko ? event.offsetX : NaN);
335
+ return false;
320
336
  };
321
337
  function handleTripleClick(view, pos) {
322
338
  var state = view.state,
@@ -392,12 +408,12 @@ var isTableInFocus = exports.isTableInFocus = function isTableInFocus(view) {
392
408
  var _getPluginState10, _getResizePluginState;
393
409
  return !!((_getPluginState10 = (0, _pluginFactory2.getPluginState)(view.state)) !== null && _getPluginState10 !== void 0 && _getPluginState10.tableNode) && !((_getResizePluginState = (0, _pluginFactory3.getPluginState)(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
394
410
  };
395
- var whenTableInFocus = exports.whenTableInFocus = function whenTableInFocus(eventHandler, elementContentRects) {
411
+ var whenTableInFocus = exports.whenTableInFocus = function whenTableInFocus(eventHandler) {
396
412
  return function (view, mouseEvent) {
397
413
  if (!isTableInFocus(view)) {
398
414
  return false;
399
415
  }
400
- return eventHandler(view, mouseEvent, elementContentRects);
416
+ return eventHandler(view, mouseEvent);
401
417
  };
402
418
  };
403
419
  var trackCellLocation = function trackCellLocation(view, mouseEvent) {
@@ -427,11 +443,11 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
427
443
  }
428
444
  (0, _commands.hoverCell)(htmlRowIndex, colIndex)(view.state, view.dispatch);
429
445
  };
430
- var withCellTracking = exports.withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
446
+ var withCellTracking = exports.withCellTracking = function withCellTracking(eventHandler) {
431
447
  return function (view, mouseEvent) {
432
448
  if ((0, _pluginFactory2.getPluginState)(view.state).isDragAndDropEnabled && !(0, _pluginFactory.getPluginState)(view.state).isDragging) {
433
449
  trackCellLocation(view, mouseEvent);
434
450
  }
435
- return eventHandler(view, mouseEvent, elementContentRects);
451
+ return eventHandler(view, mouseEvent);
436
452
  };
437
453
  };
@@ -8,6 +8,7 @@ exports.OverflowShadowsObserver = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
11
12
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _types = require("../types");
13
14
  var _consts = require("../ui/consts");
@@ -49,8 +50,13 @@ var OverflowShadowsObserver = exports.OverflowShadowsObserver = /*#__PURE__*/fun
49
50
  });
50
51
  (0, _defineProperty2.default)(this, "observeShadowSentinels", function (isSticky) {
51
52
  var _this$table, _this$table2;
53
+ if (_this.isSticky === isSticky) {
54
+ return;
55
+ }
52
56
  _this.isSticky = !!isSticky;
53
57
 
58
+ // reset height
59
+ _this.stickyRowHeight = 0;
54
60
  // update sticky shadows
55
61
  _this.updateStickyShadowsHeightIfChanged();
56
62
  _this.leftShadowSentinel = (_this$table = _this.table) === null || _this$table === void 0 ? void 0 : _this$table.querySelector(".".concat(_types.TableCssClassName.TABLE_SHADOW_SENTINEL_LEFT));
@@ -67,8 +73,8 @@ var OverflowShadowsObserver = exports.OverflowShadowsObserver = /*#__PURE__*/fun
67
73
  * e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
68
74
  * reading it from sticky cell
69
75
  */
70
- (0, _defineProperty2.default)(this, "updateStickyShadows", function (stickyRowHeight) {
71
- var _this$wrapper, _this$wrapper2, _this$wrapper3;
76
+ (0, _defineProperty2.default)(this, "updateStickyShadows", (0, _rafSchd.default)(function (stickyRowHeight) {
77
+ var _this$wrapper;
72
78
  if (!_this.isSticky) {
73
79
  return;
74
80
  }
@@ -76,14 +82,21 @@ var OverflowShadowsObserver = exports.OverflowShadowsObserver = /*#__PURE__*/fun
76
82
  if (!stickyCell || !((_this$wrapper = _this.wrapper) !== null && _this$wrapper !== void 0 && _this$wrapper.parentElement)) {
77
83
  return;
78
84
  }
79
- var heightStyleOrCompute = "".concat(stickyRowHeight || stickyCell.clientHeight + 1, "px");
80
- // Use getElementsByClassName here for a live node list to capture
81
- // sticky shadows
82
- var liveRightShadows = (_this$wrapper2 = _this.wrapper) === null || _this$wrapper2 === void 0 || (_this$wrapper2 = _this$wrapper2.parentElement) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.getElementsByClassName("".concat(_types.TableCssClassName.TABLE_RIGHT_SHADOW));
83
- var liveLeftShadows = (_this$wrapper3 = _this.wrapper) === null || _this$wrapper3 === void 0 || (_this$wrapper3 = _this$wrapper3.parentElement) === null || _this$wrapper3 === void 0 ? void 0 : _this$wrapper3.getElementsByClassName("".concat(_types.TableCssClassName.TABLE_LEFT_SHADOW));
84
- (0, _updateOverflowShadows.updateShadowListForStickyStyles)(heightStyleOrCompute, liveLeftShadows);
85
- (0, _updateOverflowShadows.updateShadowListForStickyStyles)(heightStyleOrCompute, liveRightShadows);
86
- });
85
+
86
+ // Reflow Warning! - stickyCell.clientHeight
87
+ var newStickyRowHeight = stickyRowHeight || stickyCell.clientHeight + 1;
88
+ if (newStickyRowHeight !== _this.stickyRowHeight) {
89
+ var _this$wrapper2, _this$wrapper3;
90
+ _this.stickyRowHeight = newStickyRowHeight;
91
+ var heightStyleOrCompute = "".concat(newStickyRowHeight, "px");
92
+ // Use getElementsByClassName here for a live node list to capture
93
+ // sticky shadows
94
+ var liveRightShadows = (_this$wrapper2 = _this.wrapper) === null || _this$wrapper2 === void 0 || (_this$wrapper2 = _this$wrapper2.parentElement) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.getElementsByClassName("".concat(_types.TableCssClassName.TABLE_RIGHT_SHADOW));
95
+ var liveLeftShadows = (_this$wrapper3 = _this.wrapper) === null || _this$wrapper3 === void 0 || (_this$wrapper3 = _this$wrapper3.parentElement) === null || _this$wrapper3 === void 0 ? void 0 : _this$wrapper3.getElementsByClassName("".concat(_types.TableCssClassName.TABLE_LEFT_SHADOW));
96
+ (0, _updateOverflowShadows.updateShadowListForStickyStyles)(heightStyleOrCompute, liveLeftShadows);
97
+ (0, _updateOverflowShadows.updateShadowListForStickyStyles)(heightStyleOrCompute, liveRightShadows);
98
+ }
99
+ }));
87
100
  this.updateShadowState = updateShadowState;
88
101
  this.table = _table;
89
102
  this.wrapper = wrapper;
@@ -99,11 +112,7 @@ var OverflowShadowsObserver = exports.OverflowShadowsObserver = /*#__PURE__*/fun
99
112
  if (!stickyCell) {
100
113
  return;
101
114
  }
102
- var newStickyRowHeight = stickyCell.clientHeight + 1;
103
- if (newStickyRowHeight === this.stickyRowHeight) {
104
- this.stickyRowHeight = newStickyRowHeight;
105
- this.updateStickyShadows(this.stickyRowHeight);
106
- }
115
+ this.updateStickyShadows();
107
116
  }
108
117
  }, {
109
118
  key: "getStickyCell",
@@ -11,9 +11,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
11
11
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
12
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
13
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
- var _uuid = _interopRequireDefault(require("uuid"));
15
14
  var _adfSchema = require("@atlaskit/adf-schema");
16
- var _pluginFactory = require("../pm-plugins/plugin-factory");
17
15
  var _TableNodeViewBase = _interopRequireDefault(require("./TableNodeViewBase"));
18
16
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
19
17
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
@@ -22,26 +20,10 @@ var DEFAULT_ROW_SPAN = 1;
22
20
  var TableCell = exports.default = /*#__PURE__*/function (_ref) {
23
21
  (0, _inherits2.default)(TableCell, _ref);
24
22
  var _super = _createSuper(TableCell);
25
- function TableCell(node, view, getPos, eventDispatcher, observer) {
26
- var _this;
23
+ function TableCell(node, view, getPos, eventDispatcher) {
27
24
  (0, _classCallCheck2.default)(this, TableCell);
28
- _this = _super.call(this, node, view, getPos, eventDispatcher);
29
- _this.observer = observer;
30
- var _getPluginState = (0, _pluginFactory.getPluginState)(view.state),
31
- pluginConfig = _getPluginState.pluginConfig,
32
- isDragAndDropEnabled = _getPluginState.isDragAndDropEnabled;
33
- _this.isStickyHeaderEnabled = !!pluginConfig.stickyHeaders;
34
- _this.isDragAndDropEnabled = !!isDragAndDropEnabled;
35
- if (observer) {
36
- _this.contentDOM.id = (0, _uuid.default)();
37
- observer.observe(_this.contentDOM);
38
- }
39
- return _this;
25
+ return _super.call(this, node, view, getPos, eventDispatcher);
40
26
  }
41
-
42
- // @ts-ignore
43
-
44
- // @ts-ignore
45
27
  (0, _createClass2.default)(TableCell, [{
46
28
  key: "update",
47
29
  value: function update(node) {
@@ -51,17 +33,10 @@ var TableCell = exports.default = /*#__PURE__*/function (_ref) {
51
33
  }
52
34
  return didUpdate;
53
35
  }
54
- }, {
55
- key: "destroy",
56
- value: function destroy() {
57
- if (this.observer) {
58
- this.observer.unobserve(this.contentDOM);
59
- }
60
- }
61
36
  }, {
62
37
  key: "updateNodeView",
63
38
  value: function updateNodeView(node) {
64
- var _this2 = this;
39
+ var _this = this;
65
40
  if (this.node.type !== node.type) {
66
41
  return false;
67
42
  }
@@ -92,10 +67,10 @@ var TableCell = exports.default = /*#__PURE__*/function (_ref) {
92
67
  var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
93
68
  key = _ref5[0],
94
69
  value = _ref5[1];
95
- return _this2.dom.setAttribute(key, value || '');
70
+ return _this.dom.setAttribute(key, value || '');
96
71
  });
97
72
  removedAttrs.forEach(function (key) {
98
- return _this2.dom.removeAttribute(key);
73
+ return _this.dom.removeAttribute(key);
99
74
  });
100
75
  return true;
101
76
  }
@@ -43,6 +43,9 @@ var _ExternalDropTargets = require("./ExternalDropTargets");
43
43
  var _OverflowShadowsObserver = require("./OverflowShadowsObserver");
44
44
  var _TableContainer = require("./TableContainer");
45
45
  var _TableStickyScrollbar = require("./TableStickyScrollbar");
46
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
47
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
48
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
46
49
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
47
50
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
48
51
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
@@ -52,6 +55,12 @@ var isIE11 = _utils.browser.ie_version === 11;
52
55
  // componentDidUpdate is called multiple times. The isOverflowing value is correct only on the last update.
53
56
  // To make sure we capture the last update, we use setTimeout.
54
57
  var initialOverflowCaptureTimeroutDelay = 300;
58
+
59
+ // This is a hard switch for controlling whether the overflow analytics should be dispatched. There has been 6months of data
60
+ // already collected which we could use but have not. This has been disabled rather then removed entirely in the event that
61
+ // the current collected data becomes stale and we want to start collecting fresh data again in future.
62
+ // PLEASE NOTE: that the current way this alaytics has been configured WILL cause reflows to occur. This is why the has been disabled.
63
+ var isOverflowAnalyticsEnabled = false;
55
64
  var TableComponent = /*#__PURE__*/function (_React$Component) {
56
65
  (0, _inherits2.default)(TableComponent, _React$Component);
57
66
  var _super = _createSuper(TableComponent);
@@ -63,7 +72,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
63
72
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "state", (_defineProperty2 = {
64
73
  scroll: 0,
65
74
  parentWidth: undefined
66
- }, (0, _defineProperty3.default)(_defineProperty2, _types.ShadowEvent.SHOW_BEFORE_SHADOW, false), (0, _defineProperty3.default)(_defineProperty2, _types.ShadowEvent.SHOW_AFTER_SHADOW, false), _defineProperty2));
75
+ }, (0, _defineProperty3.default)(_defineProperty2, _types.ShadowEvent.SHOW_BEFORE_SHADOW, false), (0, _defineProperty3.default)(_defineProperty2, _types.ShadowEvent.SHOW_AFTER_SHADOW, false), (0, _defineProperty3.default)(_defineProperty2, "tableWrapperWidth", undefined), (0, _defineProperty3.default)(_defineProperty2, "tableWrapperHeight", undefined), _defineProperty2));
67
76
  (0, _defineProperty3.default)((0, _assertThisInitialized2.default)(_this), "updateShadowState", function (shadowKey, value) {
68
77
  if (_this.state[shadowKey] === value) {
69
78
  return;
@@ -295,6 +304,29 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
295
304
  _this.layoutSize = _this.tableNodeLayoutSize(_this.node, _containerWidth.width, {
296
305
  isFullWidthModeEnabled: isFullWidthModeEnabled
297
306
  });
307
+ _this.resizeObserver = new ResizeObserver(function (entries) {
308
+ var _iterator = _createForOfIteratorHelper(entries),
309
+ _step;
310
+ try {
311
+ var _loop = function _loop() {
312
+ var entry = _step.value;
313
+ _this.setState(function (prev) {
314
+ var _entry$contentRect, _entry$contentRect2;
315
+ return (prev === null || prev === void 0 ? void 0 : prev.tableWrapperWidth) === ((_entry$contentRect = entry.contentRect) === null || _entry$contentRect === void 0 ? void 0 : _entry$contentRect.width) && (prev === null || prev === void 0 ? void 0 : prev.tableWrapperHeight) === ((_entry$contentRect2 = entry.contentRect) === null || _entry$contentRect2 === void 0 ? void 0 : _entry$contentRect2.height) ? prev : _objectSpread(_objectSpread({}, prev), {}, {
316
+ tableWrapperWidth: entry.contentRect.width,
317
+ tableWrapperHeight: entry.contentRect.height
318
+ });
319
+ });
320
+ };
321
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
322
+ _loop();
323
+ }
324
+ } catch (err) {
325
+ _iterator.e(err);
326
+ } finally {
327
+ _iterator.f();
328
+ }
329
+ });
298
330
 
299
331
  // Disable inline table editing and resizing controls in Firefox
300
332
  // https://github.com/ProseMirror/prosemirror/issues/432
@@ -354,12 +386,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
354
386
  this.onStickyState(currentStickyState);
355
387
  }
356
388
  eventDispatcher.on(_stickyHeaders.pluginKey.key, this.onStickyState);
357
- var initialIsOveflowing = this.state[_types.ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[_types.ShadowEvent.SHOW_AFTER_SHADOW];
358
- this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
389
+ if (isOverflowAnalyticsEnabled) {
390
+ var initialIsOveflowing = this.state[_types.ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[_types.ShadowEvent.SHOW_AFTER_SHADOW];
391
+ this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
392
+ }
359
393
  }
360
394
  }, {
361
395
  key: "componentWillUnmount",
362
396
  value: function componentWillUnmount() {
397
+ var _this$resizeObserver;
363
398
  var _this$props8 = this.props,
364
399
  allowColumnResizing = _this$props8.allowColumnResizing,
365
400
  eventDispatcher = _this$props8.eventDispatcher,
@@ -372,6 +407,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
372
407
  if (isDragAndDropEnabled && this.dragAndDropCleanupFn) {
373
408
  this.dragAndDropCleanupFn();
374
409
  }
410
+ (_this$resizeObserver = this.resizeObserver) === null || _this$resizeObserver === void 0 || _this$resizeObserver.disconnect();
375
411
  var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
376
412
  stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
377
413
  if (stickyScrollbar) {
@@ -400,7 +436,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
400
436
  }, {
401
437
  key: "handleColgroupUpdates",
402
438
  value: function handleColgroupUpdates() {
403
- var _this$containerWidth;
439
+ var _this$containerWidth,
440
+ _this2 = this;
404
441
  var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
405
442
  var _this$props9 = this.props,
406
443
  getNode = _this$props9.getNode,
@@ -423,7 +460,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
423
460
  if (depth !== 0) {
424
461
  return;
425
462
  }
426
- var tableNodeWidth = tableNode.attrs.width;
463
+ var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(tableNode);
427
464
  var shouldTableScale = tableRenderWidth < tableNodeWidth;
428
465
  var containerWidthValue = containerWidth.width;
429
466
  var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
@@ -437,7 +474,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
437
474
  domAtPos: view.domAtPos,
438
475
  isTableScalingEnabled: true
439
476
  });
440
- (0, _utils4.updateColgroup)(resizeState, this.table, tableNode, true);
477
+
478
+ // Request animation frame required for Firefox
479
+ requestAnimationFrame(function () {
480
+ (0, _utils4.updateColgroup)(resizeState, _this2.table, tableNode, true);
481
+ });
441
482
  }
442
483
  this.containerWidth = containerWidth;
443
484
  }
@@ -445,7 +486,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
445
486
  key: "componentDidUpdate",
446
487
  value: function componentDidUpdate(_, prevState) {
447
488
  var _this$wrapper,
448
- _this2 = this;
489
+ _this3 = this;
449
490
  var _this$props10 = this.props,
450
491
  view = _this$props10.view,
451
492
  getNode = _this$props10.getNode,
@@ -469,7 +510,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
469
510
  // that happens when a table is nested in expand and expand's width is
470
511
  // changed via breakout button
471
512
  window.requestAnimationFrame(function () {
472
- _this2.overflowShadowsObserver = new _OverflowShadowsObserver.OverflowShadowsObserver(_this2.updateShadowState, _this2.table, _this2.wrapper);
513
+ _this3.overflowShadowsObserver = new _OverflowShadowsObserver.OverflowShadowsObserver(_this3.updateShadowState, _this3.table, _this3.wrapper);
473
514
  });
474
515
  } else {
475
516
  this.overflowShadowsObserver = new _OverflowShadowsObserver.OverflowShadowsObserver(this.updateShadowState, this.table, this.wrapper);
@@ -500,32 +541,42 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
500
541
  }
501
542
  this.handleTableResizingDebounced();
502
543
  }
503
- var newIsOverflowing = this.state[_types.ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[_types.ShadowEvent.SHOW_AFTER_SHADOW];
504
- var prevIsOverflowing = prevState[_types.ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[_types.ShadowEvent.SHOW_AFTER_SHADOW];
505
- if (this.initialOverflowCaptureTimerId) {
506
- clearTimeout(this.initialOverflowCaptureTimerId);
544
+ if (isOverflowAnalyticsEnabled) {
545
+ var newIsOverflowing = this.state[_types.ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[_types.ShadowEvent.SHOW_AFTER_SHADOW];
546
+ var prevIsOverflowing = prevState[_types.ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[_types.ShadowEvent.SHOW_AFTER_SHADOW];
547
+ if (this.initialOverflowCaptureTimerId) {
548
+ clearTimeout(this.initialOverflowCaptureTimerId);
549
+ }
550
+ if (!this.isInitialOverflowSent) {
551
+ this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
552
+ }
553
+ if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
554
+ var _this$state2;
555
+ var _this$props$view = this.props.view,
556
+ dispatch = _this$props$view.dispatch,
557
+ tr = _this$props$view.state.tr;
558
+ dispatch(tr.setMeta(_tableAnalytics.META_KEYS.OVERFLOW_STATE_CHANGED, {
559
+ isOverflowing: newIsOverflowing,
560
+ wasOverflowing: prevIsOverflowing,
561
+ editorWidth: this.props.containerWidth.width || 0,
562
+ width: this.node.attrs.width || 0,
563
+ parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
564
+ }));
565
+ }
507
566
  }
508
- if (!this.isInitialOverflowSent) {
509
- this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
510
- }
511
- if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
512
- var _this$state2;
513
- var _this$props$view = this.props.view,
514
- dispatch = _this$props$view.dispatch,
515
- tr = _this$props$view.state.tr;
516
- dispatch(tr.setMeta(_tableAnalytics.META_KEYS.OVERFLOW_STATE_CHANGED, {
517
- isOverflowing: newIsOverflowing,
518
- wasOverflowing: prevIsOverflowing,
519
- editorWidth: this.props.containerWidth.width || 0,
520
- width: this.node.attrs.width || 0,
521
- parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
522
- }));
567
+ }
568
+ }, {
569
+ key: "observeTable",
570
+ value: function observeTable(table) {
571
+ if (table) {
572
+ var _this$resizeObserver2;
573
+ (_this$resizeObserver2 = this.resizeObserver) === null || _this$resizeObserver2 === void 0 || _this$resizeObserver2.observe(table);
523
574
  }
524
575
  }
525
576
  }, {
526
577
  key: "render",
527
578
  value: function render() {
528
- var _this3 = this,
579
+ var _this4 = this,
529
580
  _classnames;
530
581
  var _this$props11 = this.props,
531
582
  view = _this$props11.view,
@@ -577,7 +628,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
577
628
  ,
578
629
  selection: view.state.selection,
579
630
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
580
- stickyHeader: this.state.stickyHeader
631
+ stickyHeader: this.state.stickyHeader,
632
+ tableWrapperWidth: this.state.tableWrapperWidth
581
633
  });
582
634
  var tableContainerWidth = (0, _nodeWidth.getTableContainerWidth)(node);
583
635
  var colControls = isDragAndDropEnabled ? /*#__PURE__*/_react.default.createElement(_TableFloatingColumnControls.default, {
@@ -601,9 +653,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
601
653
  tableContainerWidth: tableContainerWidth,
602
654
  isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
603
655
  getScrollOffset: function getScrollOffset() {
604
- var _this3$wrapper;
605
- return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
606
- }
656
+ var _this4$wrapper;
657
+ return ((_this4$wrapper = _this4.wrapper) === null || _this4$wrapper === void 0 ? void 0 : _this4$wrapper.scrollLeft) || 0;
658
+ },
659
+ tableWrapperHeight: this.state.tableWrapperHeight
607
660
  }) : null;
608
661
  var shadowPadding = allowControls && tableActive ? -_editorSharedStyles.akEditorTableToolbarSize : _styles.tableMarginSides;
609
662
  var shadowStyle = (0, _memoizeOne.default)(function (visible) {
@@ -637,6 +690,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
637
690
  isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
638
691
  isNested: isNested,
639
692
  pluginInjectionApi: pluginInjectionApi,
693
+ tableWrapperHeight: this.state.tableWrapperHeight,
640
694
  isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
641
695
  isResizing: isResizing,
642
696
  isTableScalingEnabled: isTableScalingEnabled
@@ -650,12 +704,12 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
650
704
  editorView: view,
651
705
  node: node,
652
706
  getScrollOffset: function getScrollOffset() {
653
- var _this3$wrapper2;
654
- return ((_this3$wrapper2 = _this3.wrapper) === null || _this3$wrapper2 === void 0 ? void 0 : _this3$wrapper2.scrollLeft) || 0;
707
+ var _this4$wrapper2;
708
+ return ((_this4$wrapper2 = _this4.wrapper) === null || _this4$wrapper2 === void 0 ? void 0 : _this4$wrapper2.scrollLeft) || 0;
655
709
  },
656
710
  getTableWrapperWidth: function getTableWrapperWidth() {
657
- var _this3$wrapper3;
658
- return ((_this3$wrapper3 = _this3.wrapper) === null || _this3$wrapper3 === void 0 ? void 0 : _this3$wrapper3.clientWidth) || 760;
711
+ var _this4$wrapper3;
712
+ return ((_this4$wrapper3 = _this4.wrapper) === null || _this4$wrapper3 === void 0 ? void 0 : _this4$wrapper3.clientWidth) || 760;
659
713
  }
660
714
  }), /*#__PURE__*/_react.default.createElement("div", {
661
715
  style: shadowStyle(showBeforeShadow),
@@ -670,13 +724,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
670
724
  }), /*#__PURE__*/_react.default.createElement("div", {
671
725
  className: (0, _classnames2.default)(_types.TableCssClassName.TABLE_NODE_WRAPPER),
672
726
  ref: function ref(elem) {
673
- _this3.wrapper = elem;
727
+ _this4.wrapper = elem;
674
728
  if (elem) {
675
- _this3.props.contentDOM(elem);
729
+ _this4.props.contentDOM(elem);
676
730
  var tableElement = elem.querySelector('table');
677
- if (tableElement !== _this3.table) {
678
- _this3.table = tableElement;
679
- _this3.createShadowSentinels(_this3.table);
731
+ if (tableElement !== _this4.table) {
732
+ _this4.table = tableElement;
733
+ _this4.createShadowSentinels(_this4.table);
734
+ _this4.observeTable(_this4.table);
680
735
  }
681
736
  }
682
737
  }