@atlaskit/editor-plugin-table 7.5.5 → 7.5.6

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 (69) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/event-handlers.js +25 -9
  3. package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
  4. package/dist/cjs/nodeviews/TableCell.js +5 -30
  5. package/dist/cjs/nodeviews/TableComponent.js +74 -24
  6. package/dist/cjs/nodeviews/TableContainer.js +19 -17
  7. package/dist/cjs/nodeviews/TableResizer.js +1 -1
  8. package/dist/cjs/plugin.js +2 -3
  9. package/dist/cjs/pm-plugins/main.js +3 -18
  10. package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
  11. package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
  12. package/dist/cjs/utils/column-controls.js +5 -5
  13. package/dist/cjs/utils/dom.js +13 -15
  14. package/dist/es2019/event-handlers.js +25 -9
  15. package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
  16. package/dist/es2019/nodeviews/TableCell.js +1 -24
  17. package/dist/es2019/nodeviews/TableComponent.js +63 -27
  18. package/dist/es2019/nodeviews/TableContainer.js +16 -18
  19. package/dist/es2019/nodeviews/TableResizer.js +1 -1
  20. package/dist/es2019/plugin.js +2 -3
  21. package/dist/es2019/pm-plugins/main.js +3 -18
  22. package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
  23. package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
  24. package/dist/es2019/utils/column-controls.js +6 -6
  25. package/dist/es2019/utils/dom.js +13 -15
  26. package/dist/esm/event-handlers.js +25 -9
  27. package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
  28. package/dist/esm/nodeviews/TableCell.js +5 -30
  29. package/dist/esm/nodeviews/TableComponent.js +74 -24
  30. package/dist/esm/nodeviews/TableContainer.js +20 -18
  31. package/dist/esm/nodeviews/TableResizer.js +1 -1
  32. package/dist/esm/plugin.js +2 -3
  33. package/dist/esm/pm-plugins/main.js +3 -18
  34. package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
  35. package/dist/esm/ui/TableFloatingControls/index.js +113 -224
  36. package/dist/esm/utils/column-controls.js +6 -6
  37. package/dist/esm/utils/dom.js +13 -15
  38. package/dist/types/event-handlers.d.ts +3 -4
  39. package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  40. package/dist/types/nodeviews/TableCell.d.ts +1 -5
  41. package/dist/types/nodeviews/TableComponent.d.ts +4 -0
  42. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  43. package/dist/types/types.d.ts +0 -3
  44. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
  45. package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
  46. package/dist/types/utils/dom.d.ts +10 -2
  47. package/dist/types-ts4.5/event-handlers.d.ts +3 -4
  48. package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  49. package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
  50. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
  51. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  52. package/dist/types-ts4.5/types.d.ts +0 -3
  53. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
  54. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
  55. package/dist/types-ts4.5/utils/dom.d.ts +10 -2
  56. package/package.json +3 -4
  57. package/src/event-handlers.ts +105 -103
  58. package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
  59. package/src/nodeviews/TableCell.ts +0 -26
  60. package/src/nodeviews/TableComponent.tsx +76 -32
  61. package/src/nodeviews/TableContainer.tsx +19 -25
  62. package/src/nodeviews/TableResizer.tsx +1 -4
  63. package/src/plugin.tsx +5 -4
  64. package/src/pm-plugins/main.ts +3 -22
  65. package/src/types.ts +0 -4
  66. package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
  67. package/src/ui/TableFloatingControls/index.tsx +155 -241
  68. package/src/utils/column-controls.ts +5 -6
  69. package/src/utils/dom.ts +12 -19
@@ -6,6 +6,9 @@ import _inherits from "@babel/runtime/helpers/inherits";
6
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
7
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
8
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
+ 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; } } }; }
10
+ 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); }
11
+ 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; }
9
12
  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; }
10
13
  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) { _defineProperty(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; }
11
14
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -45,6 +48,12 @@ var isIE11 = browser.ie_version === 11;
45
48
  // componentDidUpdate is called multiple times. The isOverflowing value is correct only on the last update.
46
49
  // To make sure we capture the last update, we use setTimeout.
47
50
  var initialOverflowCaptureTimeroutDelay = 300;
51
+
52
+ // This is a hard switch for controlling whether the overflow analytics should be dispatched. There has been 6months of data
53
+ // already collected which we could use but have not. This has been disabled rather then removed entirely in the event that
54
+ // the current collected data becomes stale and we want to start collecting fresh data again in future.
55
+ // PLEASE NOTE: that the current way this alaytics has been configured WILL cause reflows to occur. This is why the has been disabled.
56
+ var isOverflowAnalyticsEnabled = false;
48
57
  var TableComponent = /*#__PURE__*/function (_React$Component) {
49
58
  _inherits(TableComponent, _React$Component);
50
59
  var _super = _createSuper(TableComponent);
@@ -56,7 +65,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
56
65
  _defineProperty(_assertThisInitialized(_this), "state", (_defineProperty2 = {
57
66
  scroll: 0,
58
67
  parentWidth: undefined
59
- }, _defineProperty(_defineProperty2, ShadowEvent.SHOW_BEFORE_SHADOW, false), _defineProperty(_defineProperty2, ShadowEvent.SHOW_AFTER_SHADOW, false), _defineProperty2));
68
+ }, _defineProperty(_defineProperty2, ShadowEvent.SHOW_BEFORE_SHADOW, false), _defineProperty(_defineProperty2, ShadowEvent.SHOW_AFTER_SHADOW, false), _defineProperty(_defineProperty2, "tableWrapperWidth", undefined), _defineProperty(_defineProperty2, "tableWrapperHeight", undefined), _defineProperty2));
60
69
  _defineProperty(_assertThisInitialized(_this), "updateShadowState", function (shadowKey, value) {
61
70
  if (_this.state[shadowKey] === value) {
62
71
  return;
@@ -288,6 +297,29 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
288
297
  _this.layoutSize = _this.tableNodeLayoutSize(_this.node, _containerWidth.width, {
289
298
  isFullWidthModeEnabled: isFullWidthModeEnabled
290
299
  });
300
+ _this.resizeObserver = new ResizeObserver(function (entries) {
301
+ var _iterator = _createForOfIteratorHelper(entries),
302
+ _step;
303
+ try {
304
+ var _loop = function _loop() {
305
+ var entry = _step.value;
306
+ _this.setState(function (prev) {
307
+ var _entry$contentRect, _entry$contentRect2;
308
+ 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), {}, {
309
+ tableWrapperWidth: entry.contentRect.width,
310
+ tableWrapperHeight: entry.contentRect.height
311
+ });
312
+ });
313
+ };
314
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
315
+ _loop();
316
+ }
317
+ } catch (err) {
318
+ _iterator.e(err);
319
+ } finally {
320
+ _iterator.f();
321
+ }
322
+ });
291
323
 
292
324
  // Disable inline table editing and resizing controls in Firefox
293
325
  // https://github.com/ProseMirror/prosemirror/issues/432
@@ -347,12 +379,15 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
347
379
  this.onStickyState(currentStickyState);
348
380
  }
349
381
  eventDispatcher.on(stickyHeadersPluginKey.key, this.onStickyState);
350
- var initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
351
- this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
382
+ if (isOverflowAnalyticsEnabled) {
383
+ var initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
384
+ this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
385
+ }
352
386
  }
353
387
  }, {
354
388
  key: "componentWillUnmount",
355
389
  value: function componentWillUnmount() {
390
+ var _this$resizeObserver;
356
391
  var _this$props8 = this.props,
357
392
  allowColumnResizing = _this$props8.allowColumnResizing,
358
393
  eventDispatcher = _this$props8.eventDispatcher,
@@ -365,6 +400,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
365
400
  if (isDragAndDropEnabled && this.dragAndDropCleanupFn) {
366
401
  this.dragAndDropCleanupFn();
367
402
  }
403
+ (_this$resizeObserver = this.resizeObserver) === null || _this$resizeObserver === void 0 || _this$resizeObserver.disconnect();
368
404
  var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
369
405
  stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
370
406
  if (stickyScrollbar) {
@@ -493,26 +529,36 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
493
529
  }
494
530
  this.handleTableResizingDebounced();
495
531
  }
496
- var newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
497
- var prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
498
- if (this.initialOverflowCaptureTimerId) {
499
- clearTimeout(this.initialOverflowCaptureTimerId);
532
+ if (isOverflowAnalyticsEnabled) {
533
+ var newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
534
+ var prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
535
+ if (this.initialOverflowCaptureTimerId) {
536
+ clearTimeout(this.initialOverflowCaptureTimerId);
537
+ }
538
+ if (!this.isInitialOverflowSent) {
539
+ this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
540
+ }
541
+ if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
542
+ var _this$state2;
543
+ var _this$props$view = this.props.view,
544
+ dispatch = _this$props$view.dispatch,
545
+ tr = _this$props$view.state.tr;
546
+ dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
547
+ isOverflowing: newIsOverflowing,
548
+ wasOverflowing: prevIsOverflowing,
549
+ editorWidth: this.props.containerWidth.width || 0,
550
+ width: this.node.attrs.width || 0,
551
+ parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
552
+ }));
553
+ }
500
554
  }
501
- if (!this.isInitialOverflowSent) {
502
- this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
503
- }
504
- if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
505
- var _this$state2;
506
- var _this$props$view = this.props.view,
507
- dispatch = _this$props$view.dispatch,
508
- tr = _this$props$view.state.tr;
509
- dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
510
- isOverflowing: newIsOverflowing,
511
- wasOverflowing: prevIsOverflowing,
512
- editorWidth: this.props.containerWidth.width || 0,
513
- width: this.node.attrs.width || 0,
514
- parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
515
- }));
555
+ }
556
+ }, {
557
+ key: "observeTable",
558
+ value: function observeTable(table) {
559
+ if (table) {
560
+ var _this$resizeObserver2;
561
+ (_this$resizeObserver2 = this.resizeObserver) === null || _this$resizeObserver2 === void 0 || _this$resizeObserver2.observe(table);
516
562
  }
517
563
  }
518
564
  }, {
@@ -570,7 +616,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
570
616
  ,
571
617
  selection: view.state.selection,
572
618
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
573
- stickyHeader: this.state.stickyHeader
619
+ stickyHeader: this.state.stickyHeader,
620
+ tableWrapperWidth: this.state.tableWrapperWidth
574
621
  });
575
622
  var tableContainerWidth = getTableContainerWidth(node);
576
623
  var colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
@@ -596,7 +643,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
596
643
  getScrollOffset: function getScrollOffset() {
597
644
  var _this3$wrapper;
598
645
  return ((_this3$wrapper = _this3.wrapper) === null || _this3$wrapper === void 0 ? void 0 : _this3$wrapper.scrollLeft) || 0;
599
- }
646
+ },
647
+ tableWrapperHeight: this.state.tableWrapperHeight
600
648
  }) : null;
601
649
  var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
602
650
  var shadowStyle = memoizeOne(function (visible) {
@@ -630,6 +678,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
630
678
  isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
631
679
  isNested: isNested,
632
680
  pluginInjectionApi: pluginInjectionApi,
681
+ tableWrapperHeight: this.state.tableWrapperHeight,
633
682
  isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
634
683
  isResizing: isResizing,
635
684
  isTableScalingEnabled: isTableScalingEnabled
@@ -670,6 +719,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
670
719
  if (tableElement !== _this3.table) {
671
720
  _this3.table = tableElement;
672
721
  _this3.createShadowSentinels(_this3.table);
722
+ _this3.observeTable(_this3.table);
673
723
  }
674
724
  }
675
725
  }
@@ -1,7 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  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; }
3
4
  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) { _defineProperty(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; }
4
- import React, { forwardRef, useCallback, useRef } from 'react';
5
+ import React, { forwardRef, useCallback, useRef, useState } from 'react';
5
6
  import classNames from 'classnames';
6
7
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
7
8
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
@@ -44,9 +45,14 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
44
45
  tableRef = _ref2.tableRef,
45
46
  isResizing = _ref2.isResizing,
46
47
  pluginInjectionApi = _ref2.pluginInjectionApi,
47
- isTableScalingEnabled = _ref2.isTableScalingEnabled;
48
+ isTableScalingEnabled = _ref2.isTableScalingEnabled,
49
+ tableWrapperHeight = _ref2.tableWrapperHeight;
48
50
  var containerRef = useRef(null);
49
51
  var tableWidthRef = useRef(akEditorDefaultLayoutWidth);
52
+ var _useState = useState(false),
53
+ _useState2 = _slicedToArray(_useState, 2),
54
+ resizing = _useState2[0],
55
+ setIsResizing = _useState2[1];
50
56
  var updateContainerHeight = useCallback(function (height) {
51
57
  var _containerRef$current;
52
58
  // current StickyHeader State is not stable to be fetch.
@@ -54,31 +60,24 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
54
60
  // consistently fetch and refactor below
55
61
  var stickyHeaders = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getElementsByClassName('pm-table-sticky');
56
62
  if (!stickyHeaders || stickyHeaders.length < 1) {
57
- var _containerRef$current2;
58
63
  // when starting to drag, we need to keep the original space,
59
64
  // -- When sticky header not appear, margin top(24px) and margin bottom(16px), should be 40px,
60
65
  // 1px is border width but collapse make it 0.5.
61
66
  // -- When sticky header appear, we should add first row height but reduce
62
67
  // collapsed border
63
- (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 || _containerRef$current2.style.setProperty('height', typeof height === 'number' ? "".concat(height + 40.5, "px") : 'auto');
68
+ return typeof height === 'number' ? "".concat(height + 40.5, "px") : 'auto';
64
69
  } else {
65
- var _containerRef$current3, _containerRef$current4;
66
- var stickyHeaderHeight = ((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.getElementsByTagName('th')[0].getBoundingClientRect().height) || 0;
67
- (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 || _containerRef$current4.style.setProperty('height', typeof height === 'number' ? "".concat(height + stickyHeaderHeight + 39.5, "px") : 'auto');
70
+ var _containerRef$current2;
71
+ var stickyHeaderHeight = ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.getElementsByTagName('th')[0].getBoundingClientRect().height) || 0;
72
+ return typeof height === 'number' ? "".concat(height + stickyHeaderHeight + 39.5, "px") : 'auto';
68
73
  }
69
74
  }, []);
70
- var resizeObserverRef = useRef(new ResizeObserver(function (entries) {
71
- updateContainerHeight(entries[entries.length - 1].contentRect.height);
72
- }));
73
75
  var onResizeStart = useCallback(function () {
74
- if (tableRef) {
75
- resizeObserverRef.current.observe(tableRef);
76
- }
77
- }, [tableRef]);
76
+ setIsResizing(true);
77
+ }, []);
78
78
  var onResizeStop = useCallback(function () {
79
- updateContainerHeight('auto');
80
- resizeObserverRef.current.disconnect();
81
- }, [updateContainerHeight]);
79
+ setIsResizing(false);
80
+ }, []);
82
81
  var updateWidth = useCallback(function (width) {
83
82
  if (!containerRef.current) {
84
83
  return;
@@ -141,7 +140,8 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
141
140
  }
142
141
  }, /*#__PURE__*/React.createElement("div", {
143
142
  style: {
144
- width: tableWidthRef.current
143
+ width: tableWidthRef.current,
144
+ height: resizing ? updateContainerHeight(tableWrapperHeight !== null && tableWrapperHeight !== void 0 ? tableWrapperHeight : 'auto') : 'auto'
145
145
  },
146
146
  className: ClassName.TABLE_RESIZER_CONTAINER,
147
147
  ref: containerRef
@@ -163,6 +163,7 @@ export var TableContainer = function TableContainer(_ref3) {
163
163
  getPos = _ref3.getPos,
164
164
  tableRef = _ref3.tableRef,
165
165
  isNested = _ref3.isNested,
166
+ tableWrapperHeight = _ref3.tableWrapperHeight,
166
167
  isResizing = _ref3.isResizing,
167
168
  pluginInjectionApi = _ref3.pluginInjectionApi,
168
169
  isTableScalingEnabled = _ref3.isTableScalingEnabled;
@@ -174,6 +175,7 @@ export var TableContainer = function TableContainer(_ref3) {
174
175
  editorView: editorView,
175
176
  getPos: getPos,
176
177
  tableRef: tableRef,
178
+ tableWrapperHeight: tableWrapperHeight,
177
179
  isResizing: isResizing,
178
180
  pluginInjectionApi: pluginInjectionApi,
179
181
  isTableScalingEnabled: isTableScalingEnabled
@@ -55,7 +55,7 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
55
55
  };
56
56
  var getResizerMinWidth = function getResizerMinWidth(node) {
57
57
  var currentColumnCount = getColgroupChildrenLength(node);
58
- var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
58
+ var minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
59
59
  // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
60
60
  // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
61
61
  return minColumnWidth + 1;
@@ -50,11 +50,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
50
50
  current: null
51
51
  };
52
52
  var defaultGetEditorContainerWidth = function defaultGetEditorContainerWidth() {
53
- var _document$body$offset, _document, _api$width$sharedStat, _api$width;
54
- var defaultState = {
53
+ var _api$width$sharedStat, _api$width, _document$body$offset, _document;
54
+ return (_api$width$sharedStat = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : {
55
55
  width: (_document$body$offset = (_document = document) === null || _document === void 0 || (_document = _document.body) === null || _document === void 0 ? void 0 : _document.offsetWidth) !== null && _document$body$offset !== void 0 ? _document$body$offset : 500
56
56
  };
57
- return (_api$width$sharedStat = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
58
57
  };
59
58
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
60
59
  return {
@@ -26,7 +26,6 @@ import { defaultHoveredCell, defaultTableSelection } from './default-table-selec
26
26
  import { createPluginState, getPluginState } from './plugin-factory';
27
27
  import { pluginKey } from './plugin-key';
28
28
  export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled) {
29
- var _window;
30
29
  var state = createPluginState(dispatch, _objectSpread(_objectSpread(_objectSpread({
31
30
  pluginConfig: pluginConfig,
32
31
  isTableHovered: false,
@@ -43,15 +42,6 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
43
42
  }, defaultHoveredCell), defaultTableSelection), {}, {
44
43
  getIntl: getIntl
45
44
  }));
46
- var elementContentRects = {};
47
- var observer = (_window = window) !== null && _window !== void 0 && _window.ResizeObserver ? new ResizeObserver(function (entries) {
48
- entries.forEach(function (entry) {
49
- if (!entry.target.id) {
50
- return;
51
- }
52
- elementContentRects[entry.target.id] = entry.contentRect;
53
- });
54
- }) : undefined;
55
45
 
56
46
  // Used to prevent invalid table cell spans being reported more than once per editor/document
57
47
  var invalidTableIds = [];
@@ -154,11 +144,6 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
154
144
  } else if (pluginState.isResizeHandleWidgetAdded) {
155
145
  removeResizeHandleDecorations()(state, dispatch);
156
146
  }
157
- },
158
- destroy: function destroy() {
159
- if (observer) {
160
- observer.disconnect();
161
- }
162
147
  }
163
148
  };
164
149
  },
@@ -264,10 +249,10 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
264
249
  return new TableRow(node, view, getPos, eventDispatcher);
265
250
  },
266
251
  tableCell: function tableCell(node, view, getPos) {
267
- return new TableCell(node, view, getPos, eventDispatcher, observer);
252
+ return new TableCell(node, view, getPos, eventDispatcher);
268
253
  },
269
254
  tableHeader: function tableHeader(node, view, getPos) {
270
- return new TableCell(node, view, getPos, eventDispatcher, observer);
255
+ return new TableCell(node, view, getPos, eventDispatcher);
271
256
  }
272
257
  },
273
258
  handleDOMEvents: {
@@ -277,7 +262,7 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
277
262
  mouseover: withCellTracking(whenTableInFocus(handleMouseOver)),
278
263
  mouseleave: handleMouseLeave,
279
264
  mouseout: whenTableInFocus(handleMouseOut),
280
- mousemove: whenTableInFocus(handleMouseMove, elementContentRects),
265
+ mousemove: whenTableInFocus(handleMouseMove),
281
266
  mouseenter: handleMouseEnter,
282
267
  mouseup: whenTableInFocus(handleMouseUp),
283
268
  click: withCellTracking(whenTableInFocus(handleClick))
@@ -1,7 +1,4 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- 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; } } }; }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
2
  import React, { useEffect, useMemo, useRef, useState } from 'react';
6
3
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
7
4
  import { TableCssClassName as ClassName } from '../../types';
@@ -22,54 +19,17 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
22
19
  isTableHovered = _ref.isTableHovered,
23
20
  tableContainerWidth = _ref.tableContainerWidth,
24
21
  isNumberColumnEnabled = _ref.isNumberColumnEnabled,
25
- getScrollOffset = _ref.getScrollOffset;
26
- var _useState = useState({
27
- width: 0,
28
- height: 0
29
- }),
22
+ getScrollOffset = _ref.getScrollOffset,
23
+ tableWrapperHeight = _ref.tableWrapperHeight;
24
+ var _useState = useState(false),
30
25
  _useState2 = _slicedToArray(_useState, 2),
31
- tableRect = _useState2[0],
32
- setTableRect = _useState2[1];
33
- var _useState3 = useState(false),
34
- _useState4 = _slicedToArray(_useState3, 2),
35
- isDragging = _useState4[0],
36
- setIsDragging = _useState4[1];
26
+ isDragging = _useState2[0],
27
+ setIsDragging = _useState2[1];
37
28
  var containerRef = useRef(null);
38
29
  var node = getNode();
39
30
  var currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
40
31
  var hasHeaderColumn = containsHeaderColumn(node);
41
32
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
42
- useEffect(function () {
43
- var _window;
44
- if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
45
- var resizeObserver = new ResizeObserver(function (entries) {
46
- var _iterator = _createForOfIteratorHelper(entries),
47
- _step;
48
- try {
49
- var _loop = function _loop() {
50
- var entry = _step.value;
51
- setTableRect(function (prev) {
52
- if (prev.width !== entry.contentRect.width || prev.height !== entry.contentRect.height) {
53
- return entry.contentRect;
54
- }
55
- return prev;
56
- });
57
- };
58
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
- _loop();
60
- }
61
- } catch (err) {
62
- _iterator.e(err);
63
- } finally {
64
- _iterator.f();
65
- }
66
- });
67
- resizeObserver.observe(tableRef);
68
- return function () {
69
- resizeObserver.disconnect();
70
- };
71
- }
72
- }, [tableRef]);
73
33
  useEffect(function () {
74
34
  return monitorForElements({
75
35
  canMonitor: function canMonitor(_ref2) {
@@ -90,11 +50,11 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
90
50
  }, [editorView, currentNodeLocalId]);
91
51
  var rowHeights = useMemo(function () {
92
52
  // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
93
- if (tableRef && !!tableRect.height) {
53
+ if (tableRef && !!tableWrapperHeight) {
94
54
  return getRowHeights(tableRef);
95
55
  }
96
56
  return [0];
97
- }, [tableRef, tableRect.height]);
57
+ }, [tableRef, tableWrapperHeight]);
98
58
  if (!tableRef || !tableActive || isResizing) {
99
59
  return null;
100
60
  }
@@ -131,7 +91,7 @@ export var TableFloatingColumnControls = function TableFloatingColumnControls(_r
131
91
  }), isDragging && /*#__PURE__*/React.createElement(ColumnDropTargets, {
132
92
  tableRef: tableRef,
133
93
  isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
134
- tableHeight: tableRect.height,
94
+ tableHeight: tableWrapperHeight,
135
95
  localId: currentNodeLocalId,
136
96
  colWidths: colWidths,
137
97
  getScrollOffset: getScrollOffset