@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
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.TableContainer = exports.ResizableTableContainer = exports.InnerContainer = void 0;
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _react = _interopRequireWildcard(require("react"));
11
12
  var _classnames = _interopRequireDefault(require("classnames"));
12
13
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
@@ -54,9 +55,14 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
54
55
  tableRef = _ref2.tableRef,
55
56
  isResizing = _ref2.isResizing,
56
57
  pluginInjectionApi = _ref2.pluginInjectionApi,
57
- isTableScalingEnabled = _ref2.isTableScalingEnabled;
58
+ isTableScalingEnabled = _ref2.isTableScalingEnabled,
59
+ tableWrapperHeight = _ref2.tableWrapperHeight;
58
60
  var containerRef = (0, _react.useRef)(null);
59
61
  var tableWidthRef = (0, _react.useRef)(_editorSharedStyles.akEditorDefaultLayoutWidth);
62
+ var _useState = (0, _react.useState)(false),
63
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
64
+ resizing = _useState2[0],
65
+ setIsResizing = _useState2[1];
60
66
  var updateContainerHeight = (0, _react.useCallback)(function (height) {
61
67
  var _containerRef$current;
62
68
  // current StickyHeader State is not stable to be fetch.
@@ -64,31 +70,24 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
64
70
  // consistently fetch and refactor below
65
71
  var stickyHeaders = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getElementsByClassName('pm-table-sticky');
66
72
  if (!stickyHeaders || stickyHeaders.length < 1) {
67
- var _containerRef$current2;
68
73
  // when starting to drag, we need to keep the original space,
69
74
  // -- When sticky header not appear, margin top(24px) and margin bottom(16px), should be 40px,
70
75
  // 1px is border width but collapse make it 0.5.
71
76
  // -- When sticky header appear, we should add first row height but reduce
72
77
  // collapsed border
73
- (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 || _containerRef$current2.style.setProperty('height', typeof height === 'number' ? "".concat(height + 40.5, "px") : 'auto');
78
+ return typeof height === 'number' ? "".concat(height + 40.5, "px") : 'auto';
74
79
  } else {
75
- var _containerRef$current3, _containerRef$current4;
76
- var stickyHeaderHeight = ((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.getElementsByTagName('th')[0].getBoundingClientRect().height) || 0;
77
- (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 || _containerRef$current4.style.setProperty('height', typeof height === 'number' ? "".concat(height + stickyHeaderHeight + 39.5, "px") : 'auto');
80
+ var _containerRef$current2;
81
+ var stickyHeaderHeight = ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.getElementsByTagName('th')[0].getBoundingClientRect().height) || 0;
82
+ return typeof height === 'number' ? "".concat(height + stickyHeaderHeight + 39.5, "px") : 'auto';
78
83
  }
79
84
  }, []);
80
- var resizeObserverRef = (0, _react.useRef)(new ResizeObserver(function (entries) {
81
- updateContainerHeight(entries[entries.length - 1].contentRect.height);
82
- }));
83
85
  var onResizeStart = (0, _react.useCallback)(function () {
84
- if (tableRef) {
85
- resizeObserverRef.current.observe(tableRef);
86
- }
87
- }, [tableRef]);
86
+ setIsResizing(true);
87
+ }, []);
88
88
  var onResizeStop = (0, _react.useCallback)(function () {
89
- updateContainerHeight('auto');
90
- resizeObserverRef.current.disconnect();
91
- }, [updateContainerHeight]);
89
+ setIsResizing(false);
90
+ }, []);
92
91
  var updateWidth = (0, _react.useCallback)(function (width) {
93
92
  if (!containerRef.current) {
94
93
  return;
@@ -151,7 +150,8 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
151
150
  }
152
151
  }, /*#__PURE__*/_react.default.createElement("div", {
153
152
  style: {
154
- width: tableWidthRef.current
153
+ width: tableWidthRef.current,
154
+ height: resizing ? updateContainerHeight(tableWrapperHeight !== null && tableWrapperHeight !== void 0 ? tableWrapperHeight : 'auto') : 'auto'
155
155
  },
156
156
  className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
157
157
  ref: containerRef
@@ -173,6 +173,7 @@ var TableContainer = exports.TableContainer = function TableContainer(_ref3) {
173
173
  getPos = _ref3.getPos,
174
174
  tableRef = _ref3.tableRef,
175
175
  isNested = _ref3.isNested,
176
+ tableWrapperHeight = _ref3.tableWrapperHeight,
176
177
  isResizing = _ref3.isResizing,
177
178
  pluginInjectionApi = _ref3.pluginInjectionApi,
178
179
  isTableScalingEnabled = _ref3.isTableScalingEnabled;
@@ -184,6 +185,7 @@ var TableContainer = exports.TableContainer = function TableContainer(_ref3) {
184
185
  editorView: editorView,
185
186
  getPos: getPos,
186
187
  tableRef: tableRef,
188
+ tableWrapperHeight: tableWrapperHeight,
187
189
  isResizing: isResizing,
188
190
  pluginInjectionApi: pluginInjectionApi,
189
191
  isTableScalingEnabled: isTableScalingEnabled
@@ -65,7 +65,7 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
65
65
  };
66
66
  var getResizerMinWidth = function getResizerMinWidth(node) {
67
67
  var currentColumnCount = (0, _utils3.getColgroupChildrenLength)(node);
68
- var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * _utils3.COLUMN_MIN_WIDTH : 3 * _utils3.COLUMN_MIN_WIDTH;
68
+ var minColumnWidth = Math.min(3, currentColumnCount) * _utils3.COLUMN_MIN_WIDTH;
69
69
  // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
70
70
  // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
71
71
  return minColumnWidth + 1;
@@ -57,11 +57,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
57
57
  current: null
58
58
  };
59
59
  var defaultGetEditorContainerWidth = function defaultGetEditorContainerWidth() {
60
- var _document$body$offset, _document, _api$width$sharedStat, _api$width;
61
- var defaultState = {
60
+ var _api$width$sharedStat, _api$width, _document$body$offset, _document;
61
+ 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 : {
62
62
  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
63
63
  };
64
- 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;
65
64
  };
66
65
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
67
66
  return {
@@ -33,7 +33,6 @@ var _pluginKey = require("./plugin-key");
33
33
  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; }
34
34
  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, _defineProperty2.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; }
35
35
  var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled) {
36
- var _window;
37
36
  var state = (0, _pluginFactory.createPluginState)(dispatch, _objectSpread(_objectSpread(_objectSpread({
38
37
  pluginConfig: pluginConfig,
39
38
  isTableHovered: false,
@@ -50,15 +49,6 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
50
49
  }, _defaultTableSelection.defaultHoveredCell), _defaultTableSelection.defaultTableSelection), {}, {
51
50
  getIntl: getIntl
52
51
  }));
53
- var elementContentRects = {};
54
- var observer = (_window = window) !== null && _window !== void 0 && _window.ResizeObserver ? new ResizeObserver(function (entries) {
55
- entries.forEach(function (entry) {
56
- if (!entry.target.id) {
57
- return;
58
- }
59
- elementContentRects[entry.target.id] = entry.contentRect;
60
- });
61
- }) : undefined;
62
52
 
63
53
  // Used to prevent invalid table cell spans being reported more than once per editor/document
64
54
  var invalidTableIds = [];
@@ -161,11 +151,6 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
161
151
  } else if (pluginState.isResizeHandleWidgetAdded) {
162
152
  (0, _misc.removeResizeHandleDecorations)()(state, dispatch);
163
153
  }
164
- },
165
- destroy: function destroy() {
166
- if (observer) {
167
- observer.disconnect();
168
- }
169
154
  }
170
155
  };
171
156
  },
@@ -271,10 +256,10 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
271
256
  return new _TableRow.default(node, view, getPos, eventDispatcher);
272
257
  },
273
258
  tableCell: function tableCell(node, view, getPos) {
274
- return new _TableCell.default(node, view, getPos, eventDispatcher, observer);
259
+ return new _TableCell.default(node, view, getPos, eventDispatcher);
275
260
  },
276
261
  tableHeader: function tableHeader(node, view, getPos) {
277
- return new _TableCell.default(node, view, getPos, eventDispatcher, observer);
262
+ return new _TableCell.default(node, view, getPos, eventDispatcher);
278
263
  }
279
264
  },
280
265
  handleDOMEvents: {
@@ -284,7 +269,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
284
269
  mouseover: (0, _eventHandlers.withCellTracking)((0, _eventHandlers.whenTableInFocus)(_eventHandlers.handleMouseOver)),
285
270
  mouseleave: _eventHandlers.handleMouseLeave,
286
271
  mouseout: (0, _eventHandlers.whenTableInFocus)(_eventHandlers.handleMouseOut),
287
- mousemove: (0, _eventHandlers.whenTableInFocus)(_eventHandlers.handleMouseMove, elementContentRects),
272
+ mousemove: (0, _eventHandlers.whenTableInFocus)(_eventHandlers.handleMouseMove),
288
273
  mouseenter: _eventHandlers.handleMouseEnter,
289
274
  mouseup: (0, _eventHandlers.whenTableInFocus)(_eventHandlers.handleMouseUp),
290
275
  click: (0, _eventHandlers.withCellTracking)((0, _eventHandlers.whenTableInFocus)(_eventHandlers.handleClick))
@@ -1,5 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ "use strict";
@@ -11,7 +11,7 @@ var _utils = require("@atlaskit/editor-common/utils");
11
11
  var _model = require("@atlaskit/editor-prosemirror/model");
12
12
  var _tableMap = require("@atlaskit/editor-tables/table-map");
13
13
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
- var _consts = require("./consts");
14
+ var _misc = require("./misc");
15
15
  /**
16
16
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
17
17
  * than the table and table wrapper elements. This is necessary as there is no longer
@@ -31,14 +31,10 @@ var generateColgroup = exports.generateColgroup = function generateColgroup(tabl
31
31
  // We slice here to guard against our colwidth array having more entries
32
32
  // Than the we actually span. We'll patch the document at a later point.
33
33
  if (tableRef) {
34
- var _tableRef$parentEleme;
35
- var tableWidth = table.attrs && table.attrs.width;
36
- var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
37
- var scalePercent = renderWidth / tableWidth;
38
- scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
34
+ var scalePercent = (0, _misc.getTableScalingPercent)(table, tableRef);
39
35
  cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
40
36
  var fixedColWidth = getColWidthFix(width, map.width);
41
- var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
37
+ var scaledWidth = fixedColWidth * scalePercent;
42
38
  var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
43
39
  cols.push(['col', {
44
40
  style: "width: ".concat(finalWidth, "px;")
@@ -7,7 +7,7 @@ exports.currentColWidth = currentColWidth;
7
7
  exports.domCellAround = domCellAround;
8
8
  exports.getDefaultLayoutMaxWidth = getDefaultLayoutMaxWidth;
9
9
  exports.getLayoutSize = getLayoutSize;
10
- exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElementWidth = void 0;
10
+ exports.getTableScalingPercent = exports.getTableMaxWidth = exports.getTableElementWidth = exports.getTableContainerElementWidth = void 0;
11
11
  exports.pointsAtCell = pointsAtCell;
12
12
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
13
13
  var _styles = require("@atlaskit/editor-common/styles");
@@ -16,6 +16,7 @@ var _utils = require("@atlaskit/editor-common/utils");
16
16
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
17
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
18
  var _colgroup = require("./colgroup");
19
+ var _consts = require("./consts");
19
20
  // Translates named layouts in number values.
20
21
  function getLayoutSize(tableLayout) {
21
22
  var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -99,4 +100,13 @@ var getTableElementWidth = exports.getTableElementWidth = function getTableEleme
99
100
  };
100
101
  var getTableContainerElementWidth = exports.getTableContainerElementWidth = function getTableContainerElementWidth(table) {
101
102
  return (0, _nodeWidth.getTableContainerWidth)(table);
103
+ };
104
+ var getTableScalingPercent = exports.getTableScalingPercent = function getTableScalingPercent(table, tableRef) {
105
+ var _tableRef$parentEleme;
106
+ var tableWidth = getTableContainerElementWidth(table);
107
+ var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
108
+ // minus 1 here to avoid any 1px scroll in Firefox
109
+ var scalePercent = (renderWidth - 1) / tableWidth;
110
+ scalePercent = Math.max(scalePercent, 1 - _consts.MAX_SCALING_PERCENT);
111
+ return Math.min(scalePercent, 1);
102
112
  };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.updateColgroup = exports.normaliseTableLayout = exports.getTotalWidth = exports.getResizeState = exports.getNewResizeStateFromSelectedColumns = exports.evenSelectedColumnsWidths = exports.evenAllColumnsWidths = exports.bulkColumnsResize = exports.areColumnsEven = exports.adjustColumnsWidths = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _nodeWidth = require("@atlaskit/editor-common/node-width");
9
10
  var _styles = require("@atlaskit/editor-common/styles");
10
11
  var _utils = require("@atlaskit/editor-common/utils");
11
12
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -14,7 +15,6 @@ var _colgroup = require("./colgroup");
14
15
  var _columnState = require("./column-state");
15
16
  var _dom = require("./dom");
16
17
  var _misc = require("./misc");
17
- var _index = require("./index");
18
18
  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; }
19
19
  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, _defineProperty2.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; }
20
20
  var getResizeState = exports.getResizeState = function getResizeState(_ref) {
@@ -26,6 +26,10 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
26
26
  domAtPos = _ref.domAtPos,
27
27
  _ref$isTableScalingEn = _ref.isTableScalingEnabled,
28
28
  isTableScalingEnabled = _ref$isTableScalingEn === void 0 ? false : _ref$isTableScalingEn;
29
+ if (isTableScalingEnabled) {
30
+ var scalePercent = (0, _misc.getTableScalingPercent)(table, tableRef);
31
+ minWidth = Math.ceil(minWidth / scalePercent);
32
+ }
29
33
  // If the table has been resized, we can use the column widths from the table node
30
34
  if ((0, _colgroup.hasTableBeenResized)(table)) {
31
35
  var _cols = (0, _utils.calcTableColumnWidths)(table).map(function (width, index) {
@@ -58,11 +62,12 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
58
62
  var cols = Array.from(colgroupChildren).map(function (_, index) {
59
63
  // If the table hasn't been resized and we have a table width attribute, we can use it
60
64
  // to calculate the widths of the columns
61
- if (isTableScalingEnabled && table.attrs.width) {
65
+ if (isTableScalingEnabled) {
66
+ var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(table);
62
67
  return {
63
68
  index: index,
64
- width: table.attrs.width / colgroupChildren.length,
65
- minWidth: _index.COLUMN_MIN_WIDTH
69
+ width: tableNodeWidth / colgroupChildren.length,
70
+ minWidth: minWidth
66
71
  };
67
72
  }
68
73
  var cellsRefs = (0, _columnState.getCellsRefsInColumn)(index, table, start, domAtPos);
@@ -90,25 +95,19 @@ var updateColgroup = exports.updateColgroup = function updateColgroup(state, tab
90
95
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
91
96
  var columnsCount = cols.length;
92
97
  if (isTableScalingEnabled && tableNode) {
93
- var tableWidth = (0, _misc.getTableContainerElementWidth)(tableNode);
94
- if (tableWidth) {
95
- var _tableRef$parentEleme;
96
- var renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || _index.TABLE_DEFAULT_WIDTH;
97
- var scalePercent = renderWidth / tableWidth;
98
- scalePercent = Math.max(scalePercent, 1 - _index.MAX_SCALING_PERCENT);
99
- state.cols.filter(function (column) {
100
- return column && !!column.width;
101
- }) // if width is 0, we dont want to apply that.
102
- .forEach(function (column, i) {
103
- var fixedColWidth = (0, _colgroup.getColWidthFix)(column.width, columnsCount);
104
- var scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
105
- var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
106
- // we aren't handling the remaining pixels here when the 48px min width is reached
107
- if (cols[i]) {
108
- cols[i].style.width = "".concat(finalWidth, "px");
109
- }
110
- });
111
- }
98
+ var scalePercent = (0, _misc.getTableScalingPercent)(tableNode, tableRef);
99
+ state.cols.filter(function (column) {
100
+ return column && !!column.width;
101
+ }) // if width is 0, we dont want to apply that.
102
+ .forEach(function (column, i) {
103
+ var fixedColWidth = (0, _colgroup.getColWidthFix)(column.width, columnsCount);
104
+ var scaledWidth = fixedColWidth * scalePercent;
105
+ var finalWidth = Math.max(scaledWidth, _styles.tableCellMinWidth);
106
+ // we aren't handling the remaining pixels here when the 48px min width is reached
107
+ if (cols[i]) {
108
+ cols[i].style.width = "".concat(finalWidth, "px");
109
+ }
110
+ });
112
111
  } else {
113
112
  state.cols.filter(function (column) {
114
113
  return column && !!column.width;
@@ -133,9 +133,9 @@ var previewScaleTable = exports.previewScaleTable = function previewScaleTable(t
133
133
  (0, _dom.syncStickyRowToTable)(tableRef);
134
134
  return;
135
135
  }
136
- var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, isTableScalingEnabled) : scale(tableRef, options, domAtPos, isTableScalingEnabled);
136
+ var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) : scale(tableRef, options, domAtPos, false);
137
137
  if (resizeState) {
138
- (0, _resizeState.updateColgroup)(resizeState, tableRef, node, isTableScalingEnabled);
138
+ (0, _resizeState.updateColgroup)(resizeState, tableRef, node, false);
139
139
  }
140
140
  };
141
141
 
@@ -20,6 +20,9 @@ function tableSelectionKeymapPlugin(editorSelectionAPI) {
20
20
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.shift-arrowup-fix')) {
21
21
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.shiftArrowUp.common, (0, _selection.shiftArrowUpFromTable)(editorSelectionAPI)(), list);
22
22
  }
23
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.cmd-a-select-table')) {
24
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.selectTable.common, (0, _selection.modASelectTable)(editorSelectionAPI)(), list);
25
+ }
23
26
  return (0, _keymap.keymap)(list);
24
27
  }
25
28
  var _default = exports.default = tableSelectionKeymapPlugin;
@@ -15,9 +15,6 @@ var _ColumnControls = require("./ColumnControls");
15
15
  var _ColumnDropTargets = require("./ColumnDropTargets");
16
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
17
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
- 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; } } }; }
19
- 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); }
20
- 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; }
21
18
  var TableFloatingColumnControls = exports.TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
22
19
  var editorView = _ref.editorView,
23
20
  tableRef = _ref.tableRef,
@@ -32,54 +29,17 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
32
29
  isTableHovered = _ref.isTableHovered,
33
30
  tableContainerWidth = _ref.tableContainerWidth,
34
31
  isNumberColumnEnabled = _ref.isNumberColumnEnabled,
35
- getScrollOffset = _ref.getScrollOffset;
36
- var _useState = (0, _react.useState)({
37
- width: 0,
38
- height: 0
39
- }),
32
+ getScrollOffset = _ref.getScrollOffset,
33
+ tableWrapperHeight = _ref.tableWrapperHeight;
34
+ var _useState = (0, _react.useState)(false),
40
35
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
41
- tableRect = _useState2[0],
42
- setTableRect = _useState2[1];
43
- var _useState3 = (0, _react.useState)(false),
44
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
45
- isDragging = _useState4[0],
46
- setIsDragging = _useState4[1];
36
+ isDragging = _useState2[0],
37
+ setIsDragging = _useState2[1];
47
38
  var containerRef = (0, _react.useRef)(null);
48
39
  var node = getNode();
49
40
  var currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
50
41
  var hasHeaderColumn = (0, _utils.containsHeaderColumn)(node);
51
42
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
52
- (0, _react.useEffect)(function () {
53
- var _window;
54
- if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
55
- var resizeObserver = new ResizeObserver(function (entries) {
56
- var _iterator = _createForOfIteratorHelper(entries),
57
- _step;
58
- try {
59
- var _loop = function _loop() {
60
- var entry = _step.value;
61
- setTableRect(function (prev) {
62
- if (prev.width !== entry.contentRect.width || prev.height !== entry.contentRect.height) {
63
- return entry.contentRect;
64
- }
65
- return prev;
66
- });
67
- };
68
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
- _loop();
70
- }
71
- } catch (err) {
72
- _iterator.e(err);
73
- } finally {
74
- _iterator.f();
75
- }
76
- });
77
- resizeObserver.observe(tableRef);
78
- return function () {
79
- resizeObserver.disconnect();
80
- };
81
- }
82
- }, [tableRef]);
83
43
  (0, _react.useEffect)(function () {
84
44
  return (0, _adapter.monitorForElements)({
85
45
  canMonitor: function canMonitor(_ref2) {
@@ -100,11 +60,11 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
100
60
  }, [editorView, currentNodeLocalId]);
101
61
  var rowHeights = (0, _react.useMemo)(function () {
102
62
  // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
103
- if (tableRef && !!tableRect.height) {
63
+ if (tableRef && !!tableWrapperHeight) {
104
64
  return (0, _utils.getRowHeights)(tableRef);
105
65
  }
106
66
  return [0];
107
- }, [tableRef, tableRect.height]);
67
+ }, [tableRef, tableWrapperHeight]);
108
68
  if (!tableRef || !tableActive || isResizing) {
109
69
  return null;
110
70
  }
@@ -141,7 +101,7 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
141
101
  }), isDragging && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
142
102
  tableRef: tableRef,
143
103
  isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
144
- tableHeight: tableRect.height,
104
+ tableHeight: tableWrapperHeight,
145
105
  localId: currentNodeLocalId,
146
106
  colWidths: colWidths,
147
107
  getScrollOffset: getScrollOffset