@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
@@ -5,240 +5,130 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = void 0;
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
12
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
+ exports.default = exports.TableFloatingControls = void 0;
16
9
  var _react = _interopRequireWildcard(require("react"));
17
10
  var _utils = require("@atlaskit/editor-common/utils");
18
11
  var _commands = require("../../commands");
19
12
  var _types = require("../../types");
20
- var _utils2 = require("../../utils");
21
13
  var _CornerControls = require("./CornerControls");
22
14
  var _NumberColumn = _interopRequireDefault(require("./NumberColumn"));
23
15
  var _RowControls = require("./RowControls");
24
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); }
25
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; }
26
- 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; } } }; }
27
- 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); }
28
- 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; }
29
- 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); }; }
30
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
31
- var TableFloatingControls = exports.default = /*#__PURE__*/function (_Component) {
32
- (0, _inherits2.default)(TableFloatingControls, _Component);
33
- var _super = _createSuper(TableFloatingControls);
34
- function TableFloatingControls(props) {
35
- var _this;
36
- (0, _classCallCheck2.default)(this, TableFloatingControls);
37
- _this = _super.call(this, props);
38
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectRow", function (row, expand) {
39
- var editorView = _this.props.editorView;
40
- var state = editorView.state,
41
- dispatch = editorView.dispatch;
42
- // fix for issue ED-4665
43
- if (_utils.browser.ie_version === 11) {
44
- editorView.dom.blur();
45
- }
46
- (0, _commands.selectRow)(row, expand)(state, dispatch);
47
- });
48
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectRows", function (rowIndexes) {
49
- var editorView = _this.props.editorView;
50
- var state = editorView.state,
51
- dispatch = editorView.dispatch;
52
- // fix for issue ED-4665
53
- if (_utils.browser.ie_version === 11) {
54
- editorView.dom.blur();
55
- }
56
- (0, _commands.selectRows)(rowIndexes)(state, dispatch);
57
- });
58
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hoverRows", function (rows, danger) {
59
- var _this$props$editorVie = _this.props.editorView,
60
- state = _this$props$editorVie.state,
61
- dispatch = _this$props$editorVie.dispatch;
62
- (0, _commands.hoverRows)(rows, danger)(state, dispatch);
63
- });
64
- // re-use across numbered columns and row controls
65
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateCellHoverLocation", function (rowIndex) {
66
- var _this$props = _this.props,
67
- editorView = _this$props.editorView,
68
- tableActive = _this$props.tableActive;
69
- var state = editorView.state,
70
- dispatch = editorView.dispatch;
71
- if (tableActive) {
72
- // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
73
- // of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
74
- // also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
75
- // current column index. We can just force it to 0.
76
- (0, _commands.hoverCell)(rowIndex, 0)(state, dispatch);
77
- }
78
- });
79
- _this.state = {
80
- tableWrapperWidth: 0,
81
- /** Height needs to be tracked to re-render decorations correctly, do not remove */
82
- tableWrapperHeight: 0
83
- };
84
- return _this;
85
- }
86
- (0, _createClass2.default)(TableFloatingControls, [{
87
- key: "componentDidMount",
88
- value: function componentDidMount() {
89
- this.tryInitResizeObserver();
18
+ var TableFloatingControls = exports.TableFloatingControls = function TableFloatingControls(_ref) {
19
+ var editorView = _ref.editorView,
20
+ tableRef = _ref.tableRef,
21
+ tableNode = _ref.tableNode,
22
+ isInDanger = _ref.isInDanger,
23
+ isResizing = _ref.isResizing,
24
+ isNumberColumnEnabled = _ref.isNumberColumnEnabled,
25
+ isHeaderRowEnabled = _ref.isHeaderRowEnabled,
26
+ isHeaderColumnEnabled = _ref.isHeaderColumnEnabled,
27
+ tableActive = _ref.tableActive,
28
+ hasHeaderRow = _ref.hasHeaderRow,
29
+ hoveredRows = _ref.hoveredRows,
30
+ stickyHeader = _ref.stickyHeader,
31
+ isDragAndDropEnabled = _ref.isDragAndDropEnabled,
32
+ hoveredCell = _ref.hoveredCell,
33
+ isTableHovered = _ref.isTableHovered,
34
+ tableWrapperWidth = _ref.tableWrapperWidth;
35
+ var _selectRow = (0, _react.useCallback)(function (row, expand) {
36
+ var state = editorView.state,
37
+ dispatch = editorView.dispatch;
38
+ // fix for issue ED-4665
39
+ if (_utils.browser.ie_version === 11) {
40
+ editorView.dom.blur();
90
41
  }
91
- }, {
92
- key: "componentDidUpdate",
93
- value: function componentDidUpdate() {
94
- // tableRef prop is not guaranteed to be defined after componentDidMount, so retry to init resize observer on update
95
- this.tryInitResizeObserver();
42
+ (0, _commands.selectRow)(row, expand)(state, dispatch);
43
+ }, [editorView]);
44
+ var _selectRows = (0, _react.useCallback)(function (rowIndexes) {
45
+ var state = editorView.state,
46
+ dispatch = editorView.dispatch;
47
+ // fix for issue ED-4665
48
+ if (_utils.browser.ie_version === 11) {
49
+ editorView.dom.blur();
96
50
  }
51
+ (0, _commands.selectRows)(rowIndexes)(state, dispatch);
52
+ }, [editorView]);
53
+ var _hoverRows = (0, _react.useCallback)(function (rows, danger) {
54
+ var state = editorView.state,
55
+ dispatch = editorView.dispatch;
56
+ (0, _commands.hoverRows)(rows, danger)(state, dispatch);
57
+ }, [editorView]);
97
58
 
98
- // tracking the table height changes to update floating controls
99
- }, {
100
- key: "tryInitResizeObserver",
101
- value: function tryInitResizeObserver() {
102
- var _window,
103
- _this2 = this;
104
- var tableRef = this.props.tableRef;
105
- if (tableRef && !this.resizeObserver && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
106
- var tableWrapper = tableRef.closest(".".concat(_types.TableCssClassName.TABLE_NODE_WRAPPER));
107
- this.resizeObserver = new ResizeObserver(function (entries) {
108
- var _iterator = _createForOfIteratorHelper(entries),
109
- _step;
110
- try {
111
- var _loop = function _loop() {
112
- var entry = _step.value;
113
- _this2.setState(function (prev) {
114
- return (prev === null || prev === void 0 ? void 0 : prev.tableWrapperWidth) === entry.contentRect.width && prev.tableWrapperHeight === entry.contentRect.height ? prev : {
115
- tableWrapperWidth: entry.contentRect.width,
116
- tableWrapperHeight: entry.contentRect.height
117
- };
118
- });
119
- };
120
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
121
- _loop();
122
- }
123
- } catch (err) {
124
- _iterator.e(err);
125
- } finally {
126
- _iterator.f();
127
- }
128
- });
129
- this.resizeObserver.observe(tableWrapper);
130
- }
131
- }
132
- }, {
133
- key: "shouldComponentUpdate",
134
- value: function shouldComponentUpdate(nextProps, nextState) {
135
- var _this$props2 = this.props,
136
- tableRef = _this$props2.tableRef,
137
- isInDanger = _this$props2.isInDanger,
138
- isResizing = _this$props2.isResizing,
139
- isHeaderRowEnabled = _this$props2.isHeaderRowEnabled,
140
- isNumberColumnEnabled = _this$props2.isNumberColumnEnabled,
141
- hoveredRows = _this$props2.hoveredRows,
142
- selection = _this$props2.selection,
143
- tableActive = _this$props2.tableActive,
144
- isHeaderColumnEnabled = _this$props2.isHeaderColumnEnabled,
145
- ordering = _this$props2.ordering,
146
- headerRowHeight = _this$props2.headerRowHeight,
147
- stickyHeader = _this$props2.stickyHeader,
148
- hoveredCell = _this$props2.hoveredCell,
149
- isTableHovered = _this$props2.isTableHovered;
150
- return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || (0, _utils2.isSelectionUpdated)(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered;
59
+ // re-use across numbered columns and row controls
60
+ var updateCellHoverLocation = (0, _react.useCallback)(function (rowIndex) {
61
+ var state = editorView.state,
62
+ dispatch = editorView.dispatch;
63
+ if (tableActive) {
64
+ // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
65
+ // of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
66
+ // also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
67
+ // current column index. We can just force it to 0.
68
+ (0, _commands.hoverCell)(rowIndex, 0)(state, dispatch);
151
69
  }
152
- }, {
153
- key: "componentWillUnmount",
154
- value: function componentWillUnmount() {
155
- if (this.resizeObserver) {
156
- this.resizeObserver.disconnect();
157
- }
158
- }
159
- }, {
160
- key: "render",
161
- value: function render() {
162
- var _this$props3 = this.props,
163
- editorView = _this$props3.editorView,
164
- tableRef = _this$props3.tableRef,
165
- tableNode = _this$props3.tableNode,
166
- isInDanger = _this$props3.isInDanger,
167
- isResizing = _this$props3.isResizing,
168
- isNumberColumnEnabled = _this$props3.isNumberColumnEnabled,
169
- isHeaderRowEnabled = _this$props3.isHeaderRowEnabled,
170
- isHeaderColumnEnabled = _this$props3.isHeaderColumnEnabled,
171
- tableActive = _this$props3.tableActive,
172
- hasHeaderRow = _this$props3.hasHeaderRow,
173
- hoveredRows = _this$props3.hoveredRows,
174
- stickyHeader = _this$props3.stickyHeader,
175
- isDragAndDropEnabled = _this$props3.isDragAndDropEnabled,
176
- hoveredCell = _this$props3.hoveredCell,
177
- isTableHovered = _this$props3.isTableHovered;
178
- if (!tableRef) {
179
- return null;
180
- }
181
- var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
182
- var wrapperClassName = isDragAndDropEnabled ? _types.TableCssClassName.DRAG_ROW_CONTROLS_WRAPPER : _types.TableCssClassName.ROW_CONTROLS_WRAPPER;
183
- return /*#__PURE__*/_react.default.createElement("div", {
184
- className: wrapperClassName
185
- }, /*#__PURE__*/_react.default.createElement("div", {
186
- onMouseDown: function onMouseDown(e) {
187
- return !isDragAndDropEnabled && e.preventDefault();
188
- }
189
- }, isNumberColumnEnabled ? /*#__PURE__*/_react.default.createElement(_NumberColumn.default, {
190
- editorView: editorView,
191
- hoverRows: this.hoverRows,
192
- tableRef: tableRef,
193
- tableActive: tableActive,
194
- hoveredRows: hoveredRows,
195
- hasHeaderRow: hasHeaderRow,
196
- isInDanger: isInDanger,
197
- isResizing: isResizing,
198
- selectRow: this.selectRow,
199
- updateCellHoverLocation: this.updateCellHoverLocation,
200
- stickyTop: stickyTop,
201
- isDragAndDropEnabled: isDragAndDropEnabled
202
- }) : null, tableActive && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.DragCornerControls, {
203
- editorView: editorView,
204
- tableRef: tableRef,
205
- isInDanger: isInDanger,
206
- isResizing: isResizing
207
- }), /*#__PURE__*/_react.default.createElement(_RowControls.DragControls, {
208
- tableRef: tableRef,
209
- tableNode: tableNode,
210
- hoveredCell: hoveredCell,
211
- isTableHovered: isTableHovered,
212
- editorView: editorView,
213
- tableActive: tableActive,
214
- isInDanger: isInDanger,
215
- isResizing: isResizing,
216
- tableWidth: this.state.tableWrapperWidth,
217
- hoverRows: this.hoverRows,
218
- selectRow: this.selectRow,
219
- selectRows: this.selectRows,
220
- updateCellHoverLocation: this.updateCellHoverLocation
221
- })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.CornerControls, {
222
- editorView: editorView,
223
- tableRef: tableRef,
224
- isInDanger: isInDanger,
225
- isResizing: isResizing,
226
- isHeaderRowEnabled: isHeaderRowEnabled,
227
- isHeaderColumnEnabled: isHeaderColumnEnabled,
228
- hoveredRows: hoveredRows,
229
- stickyTop: tableActive ? stickyTop : undefined
230
- }), /*#__PURE__*/_react.default.createElement(_RowControls.RowControls, {
231
- editorView: editorView,
232
- tableRef: tableRef,
233
- hoverRows: this.hoverRows,
234
- hoveredRows: hoveredRows,
235
- isInDanger: isInDanger,
236
- isResizing: isResizing,
237
- selectRow: this.selectRow,
238
- stickyTop: tableActive ? stickyTop : undefined
239
- })))));
70
+ }, [editorView, tableActive]);
71
+ if (!tableRef) {
72
+ return null;
73
+ }
74
+ var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
75
+ var wrapperClassName = isDragAndDropEnabled ? _types.TableCssClassName.DRAG_ROW_CONTROLS_WRAPPER : _types.TableCssClassName.ROW_CONTROLS_WRAPPER;
76
+ return /*#__PURE__*/_react.default.createElement("div", {
77
+ className: wrapperClassName
78
+ }, /*#__PURE__*/_react.default.createElement("div", {
79
+ onMouseDown: function onMouseDown(e) {
80
+ return !isDragAndDropEnabled && e.preventDefault();
240
81
  }
241
- }]);
242
- return TableFloatingControls;
243
- }(_react.Component);
244
- (0, _defineProperty2.default)(TableFloatingControls, "displayName", 'TableFloatingControls');
82
+ }, isNumberColumnEnabled ? /*#__PURE__*/_react.default.createElement(_NumberColumn.default, {
83
+ editorView: editorView,
84
+ hoverRows: _hoverRows,
85
+ tableRef: tableRef,
86
+ tableActive: tableActive,
87
+ hoveredRows: hoveredRows,
88
+ hasHeaderRow: hasHeaderRow,
89
+ isInDanger: isInDanger,
90
+ isResizing: isResizing,
91
+ selectRow: _selectRow,
92
+ updateCellHoverLocation: updateCellHoverLocation,
93
+ stickyTop: stickyTop,
94
+ isDragAndDropEnabled: isDragAndDropEnabled
95
+ }) : null, tableActive && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.DragCornerControls, {
96
+ editorView: editorView,
97
+ tableRef: tableRef,
98
+ isInDanger: isInDanger,
99
+ isResizing: isResizing
100
+ }), /*#__PURE__*/_react.default.createElement(_RowControls.DragControls, {
101
+ tableRef: tableRef,
102
+ tableNode: tableNode,
103
+ hoveredCell: hoveredCell,
104
+ isTableHovered: isTableHovered,
105
+ editorView: editorView,
106
+ tableActive: tableActive,
107
+ isInDanger: isInDanger,
108
+ isResizing: isResizing,
109
+ tableWidth: tableWrapperWidth,
110
+ hoverRows: _hoverRows,
111
+ selectRow: _selectRow,
112
+ selectRows: _selectRows,
113
+ updateCellHoverLocation: updateCellHoverLocation
114
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.CornerControls, {
115
+ editorView: editorView,
116
+ tableRef: tableRef,
117
+ isInDanger: isInDanger,
118
+ isResizing: isResizing,
119
+ isHeaderRowEnabled: isHeaderRowEnabled,
120
+ isHeaderColumnEnabled: isHeaderColumnEnabled,
121
+ hoveredRows: hoveredRows,
122
+ stickyTop: tableActive ? stickyTop : undefined
123
+ }), /*#__PURE__*/_react.default.createElement(_RowControls.RowControls, {
124
+ editorView: editorView,
125
+ tableRef: tableRef,
126
+ hoverRows: _hoverRows,
127
+ hoveredRows: hoveredRows,
128
+ isInDanger: isInDanger,
129
+ isResizing: isResizing,
130
+ selectRow: _selectRow,
131
+ stickyTop: tableActive ? stickyTop : undefined
132
+ })))));
133
+ };
134
+ var _default = exports.default = TableFloatingControls;
@@ -26,13 +26,13 @@ var getColumnsWidths = exports.getColumnsWidths = function getColumnsWidths(view
26
26
  length: map.width
27
27
  });
28
28
  for (var i = 0; i < map.width; i++) {
29
- var cells = (0, _utils3.getCellsInColumn)(i)(selection);
30
- var cell = cells[0];
31
- if (cell) {
32
- var cellRef = (0, _utils2.findDomRefAtPos)(cell.pos, domAtPos);
29
+ if (!map.isCellMergedTopLeft(0, i)) {
30
+ var node = table.node.nodeAt(map.map[i]);
31
+ var pos = map.map[i] + table.start;
32
+ var cellRef = (0, _utils2.findDomRefAtPos)(pos, domAtPos);
33
33
  var rect = cellRef.getBoundingClientRect();
34
34
  widths[i] = (rect ? rect.width : cellRef.offsetWidth) + 1;
35
- i += cell.node.attrs.colspan - 1;
35
+ i += node.attrs.colspan - 1;
36
36
  }
37
37
  }
38
38
  }
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isTableControlsButton = exports.isTableContainerOrWrapper = exports.isRowControlsButton = exports.isResizeHandleDecoration = exports.isInsertRowButton = exports.isDragRowFloatingInsertDot = exports.isDragRowControlsButton = exports.isDragCornerButton = exports.isDragColumnFloatingInsertDot = exports.isCornerButton = exports.isColumnControlsDecorations = exports.isCell = exports.hasResizeHandler = exports.getTree = exports.getTop = exports.getMousePositionVerticalRelativeByElement = exports.getMousePositionHorizontalRelativeByElement = exports.getColumnOrRowIndex = exports.findNearestCellIndexToPoint = void 0;
7
7
  var _utils = require("@atlaskit/editor-common/utils");
8
8
  var _types = require("../types");
9
- var SELECTOR_TABLE_LEAFS = ".".concat(_types.TableCssClassName.TABLE_CELL, ", .").concat(_types.TableCssClassName.TABLE_HEADER_CELL);
10
9
  var isCell = exports.isCell = function isCell(node) {
11
10
  return Boolean(node && (['TH', 'TD'].indexOf(node.tagName) > -1 || !!(0, _utils.closestElement)(node, ".".concat(_types.TableCssClassName.TABLE_HEADER_CELL)) || !!(0, _utils.closestElement)(node, ".".concat(_types.TableCssClassName.TABLE_CELL))));
12
11
  };
@@ -102,22 +101,21 @@ var isDragCornerButton = exports.isDragCornerButton = function isDragCornerButto
102
101
  *
103
102
  * the same is valid to the right side.
104
103
  */
105
-
106
- var getMousePositionHorizontalRelativeByElement = exports.getMousePositionHorizontalRelativeByElement = function getMousePositionHorizontalRelativeByElement(mouseEvent, elementContentRects, gapInPixels, isDragAndDropEnabled) {
104
+ /**
105
+ * This can be used with mouse events to determine the left/right side of the target the pointer is closest too.
106
+ *
107
+ * WARNING: This metod reads properties which can trigger a reflow; use this wisely.
108
+ *
109
+ * @param mouseEvent
110
+ * @param gapInPixels
111
+ * @returns
112
+ */
113
+ var getMousePositionHorizontalRelativeByElement = exports.getMousePositionHorizontalRelativeByElement = function getMousePositionHorizontalRelativeByElement(mouseEvent, offsetX, gapInPixels) {
107
114
  var element = mouseEvent.target;
108
115
  if (element instanceof HTMLElement) {
109
- var width, x;
110
- if (isDragAndDropEnabled) {
111
- // mouse event fires for new overlapping column controls, so the cell can not get detected. Get width
112
- // directly from element that will be .pm-table-drag-columns-floating-insert-dot-wrapper
113
- width = element.clientWidth;
114
- } else {
115
- var _closestCell$id, _elementContentRects$, _elementContentRects$2;
116
- var closestCell = element.closest(SELECTOR_TABLE_LEAFS);
117
- var id = (_closestCell$id = closestCell === null || closestCell === void 0 ? void 0 : closestCell.id) !== null && _closestCell$id !== void 0 ? _closestCell$id : '';
118
- width = (_elementContentRects$ = elementContentRects === null || elementContentRects === void 0 || (_elementContentRects$2 = elementContentRects[id]) === null || _elementContentRects$2 === void 0 ? void 0 : _elementContentRects$2.width) !== null && _elementContentRects$ !== void 0 ? _elementContentRects$ : 0;
119
- }
120
- x = mouseEvent.offsetX;
116
+ var width = element.clientWidth; // reflow
117
+ var x = !Number.isNaN(offsetX) ? offsetX : mouseEvent.offsetX; // reflow
118
+
121
119
  if (width <= 0) {
122
120
  return null;
123
121
  }
@@ -372,4 +372,26 @@ export const shiftArrowUpFromTable = editorSelectionAPI => () => (state, dispatc
372
372
  })(state, dispatch);
373
373
  }
374
374
  return false;
375
+ };
376
+ export const modASelectTable = editorSelectionAPI => () => (state, dispatch) => {
377
+ const {
378
+ selection
379
+ } = state;
380
+ const table = findTable(selection);
381
+ if (!table) {
382
+ return false;
383
+ }
384
+ const {
385
+ $from,
386
+ $to
387
+ } = selection;
388
+ const tableSelected = isTableSelected(selection);
389
+ if (!tableSelected && $from.pos > table.start + 1 && $to.pos < table.start + table.node.nodeSize) {
390
+ return selectFullTable(editorSelectionAPI)({
391
+ node: table.node,
392
+ startPos: table.start,
393
+ dir: TableSelectionDirection.BottomToTop
394
+ })(state, dispatch);
395
+ }
396
+ return false;
375
397
  };
@@ -1,3 +1,4 @@
1
+ import rafSchedule from 'raf-schd';
1
2
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
2
3
  import { browser, closestElement, isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils';
3
4
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -261,7 +262,10 @@ export const handleMouseLeave = (view, event) => {
261
262
  }
262
263
  return false;
263
264
  };
264
- export const handleMouseMove = (view, event, elementContentRects) => {
265
+
266
+ // IMPORTANT: The mouse move handler has been setup with RAF schedule to avoid Reflows which will occur as some methods
267
+ // need to access the mouse event offset position and also the target clientWidth vallue.
268
+ const handleMouseMoveDebounce = rafSchedule((view, event, offsetX) => {
265
269
  if (!(event.target instanceof HTMLElement)) {
266
270
  return false;
267
271
  }
@@ -272,11 +276,10 @@ export const handleMouseMove = (view, event, elementContentRects) => {
272
276
  dispatch
273
277
  } = view;
274
278
  const {
275
- insertColumnButtonIndex,
276
- isDragAndDropEnabled
279
+ insertColumnButtonIndex
277
280
  } = getPluginState(state);
278
281
  const [startIndex, endIndex] = getColumnOrRowIndex(element);
279
- const positionColumn = getMousePositionHorizontalRelativeByElement(event, elementContentRects, undefined, isDragAndDropEnabled) === 'right' ? endIndex : startIndex;
282
+ const positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, undefined) === 'right' ? endIndex : startIndex;
280
283
  if (positionColumn !== insertColumnButtonIndex) {
281
284
  return showInsertColumnButton(positionColumn)(state, dispatch);
282
285
  }
@@ -296,7 +299,7 @@ export const handleMouseMove = (view, event, elementContentRects) => {
296
299
  }
297
300
  }
298
301
  if (!isResizeHandleDecoration(element) && isCell(element)) {
299
- const positionColumn = getMousePositionHorizontalRelativeByElement(event, elementContentRects, RESIZE_HANDLE_AREA_DECORATION_GAP);
302
+ const positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, RESIZE_HANDLE_AREA_DECORATION_GAP);
300
303
  if (positionColumn !== null) {
301
304
  const {
302
305
  state,
@@ -324,6 +327,19 @@ export const handleMouseMove = (view, event, elementContentRects) => {
324
327
  }
325
328
  }
326
329
  return false;
330
+ });
331
+ export const handleMouseMove = (view, event) => {
332
+ if (!(event.target instanceof HTMLElement)) {
333
+ return false;
334
+ }
335
+
336
+ // NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
337
+ // within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
338
+ // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
339
+ // in the deferred callback handler.
340
+ // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
341
+ handleMouseMoveDebounce(view, event, browser.gecko ? event.offsetX : NaN);
342
+ return false;
327
343
  };
328
344
  export function handleTripleClick(view, pos) {
329
345
  const {
@@ -406,11 +422,11 @@ export const isTableInFocus = view => {
406
422
  var _getPluginState, _getResizePluginState;
407
423
  return !!((_getPluginState = getPluginState(view.state)) !== null && _getPluginState !== void 0 && _getPluginState.tableNode) && !((_getResizePluginState = getResizePluginState(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
408
424
  };
409
- export const whenTableInFocus = (eventHandler, elementContentRects) => (view, mouseEvent) => {
425
+ export const whenTableInFocus = eventHandler => (view, mouseEvent) => {
410
426
  if (!isTableInFocus(view)) {
411
427
  return false;
412
428
  }
413
- return eventHandler(view, mouseEvent, elementContentRects);
429
+ return eventHandler(view, mouseEvent);
414
430
  };
415
431
  const trackCellLocation = (view, mouseEvent) => {
416
432
  var _tableElement$dataset;
@@ -440,9 +456,9 @@ const trackCellLocation = (view, mouseEvent) => {
440
456
  }
441
457
  hoverCell(htmlRowIndex, colIndex)(view.state, view.dispatch);
442
458
  };
443
- export const withCellTracking = (eventHandler, elementContentRects) => (view, mouseEvent) => {
459
+ export const withCellTracking = eventHandler => (view, mouseEvent) => {
444
460
  if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
445
461
  trackCellLocation(view, mouseEvent);
446
462
  }
447
- return eventHandler(view, mouseEvent, elementContentRects);
463
+ return eventHandler(view, mouseEvent);
448
464
  };
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import rafSchedule from 'raf-schd';
2
3
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
4
5
  import { tableInsertColumnButtonSize } from '../ui/consts';
@@ -36,8 +37,13 @@ export class OverflowShadowsObserver {
36
37
  });
37
38
  _defineProperty(this, "observeShadowSentinels", isSticky => {
38
39
  var _this$table, _this$table2;
40
+ if (this.isSticky === isSticky) {
41
+ return;
42
+ }
39
43
  this.isSticky = !!isSticky;
40
44
 
45
+ // reset height
46
+ this.stickyRowHeight = 0;
41
47
  // update sticky shadows
42
48
  this.updateStickyShadowsHeightIfChanged();
43
49
  this.leftShadowSentinel = (_this$table = this.table) === null || _this$table === void 0 ? void 0 : _this$table.querySelector(`.${ClassName.TABLE_SHADOW_SENTINEL_LEFT}`);
@@ -54,8 +60,8 @@ export class OverflowShadowsObserver {
54
60
  * e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
55
61
  * reading it from sticky cell
56
62
  */
57
- _defineProperty(this, "updateStickyShadows", stickyRowHeight => {
58
- var _this$wrapper, _this$wrapper2, _this$wrapper2$parent, _this$wrapper3, _this$wrapper3$parent;
63
+ _defineProperty(this, "updateStickyShadows", rafSchedule(stickyRowHeight => {
64
+ var _this$wrapper;
59
65
  if (!this.isSticky) {
60
66
  return;
61
67
  }
@@ -63,14 +69,21 @@ export class OverflowShadowsObserver {
63
69
  if (!stickyCell || !((_this$wrapper = this.wrapper) !== null && _this$wrapper !== void 0 && _this$wrapper.parentElement)) {
64
70
  return;
65
71
  }
66
- const heightStyleOrCompute = `${stickyRowHeight || stickyCell.clientHeight + 1}px`;
67
- // Use getElementsByClassName here for a live node list to capture
68
- // sticky shadows
69
- const liveRightShadows = (_this$wrapper2 = this.wrapper) === null || _this$wrapper2 === void 0 ? void 0 : (_this$wrapper2$parent = _this$wrapper2.parentElement) === null || _this$wrapper2$parent === void 0 ? void 0 : _this$wrapper2$parent.getElementsByClassName(`${ClassName.TABLE_RIGHT_SHADOW}`);
70
- const liveLeftShadows = (_this$wrapper3 = this.wrapper) === null || _this$wrapper3 === void 0 ? void 0 : (_this$wrapper3$parent = _this$wrapper3.parentElement) === null || _this$wrapper3$parent === void 0 ? void 0 : _this$wrapper3$parent.getElementsByClassName(`${ClassName.TABLE_LEFT_SHADOW}`);
71
- updateShadowListForStickyStyles(heightStyleOrCompute, liveLeftShadows);
72
- updateShadowListForStickyStyles(heightStyleOrCompute, liveRightShadows);
73
- });
72
+
73
+ // Reflow Warning! - stickyCell.clientHeight
74
+ const newStickyRowHeight = stickyRowHeight || stickyCell.clientHeight + 1;
75
+ if (newStickyRowHeight !== this.stickyRowHeight) {
76
+ var _this$wrapper2, _this$wrapper2$parent, _this$wrapper3, _this$wrapper3$parent;
77
+ this.stickyRowHeight = newStickyRowHeight;
78
+ const heightStyleOrCompute = `${newStickyRowHeight}px`;
79
+ // Use getElementsByClassName here for a live node list to capture
80
+ // sticky shadows
81
+ const liveRightShadows = (_this$wrapper2 = this.wrapper) === null || _this$wrapper2 === void 0 ? void 0 : (_this$wrapper2$parent = _this$wrapper2.parentElement) === null || _this$wrapper2$parent === void 0 ? void 0 : _this$wrapper2$parent.getElementsByClassName(`${ClassName.TABLE_RIGHT_SHADOW}`);
82
+ const liveLeftShadows = (_this$wrapper3 = this.wrapper) === null || _this$wrapper3 === void 0 ? void 0 : (_this$wrapper3$parent = _this$wrapper3.parentElement) === null || _this$wrapper3$parent === void 0 ? void 0 : _this$wrapper3$parent.getElementsByClassName(`${ClassName.TABLE_LEFT_SHADOW}`);
83
+ updateShadowListForStickyStyles(heightStyleOrCompute, liveLeftShadows);
84
+ updateShadowListForStickyStyles(heightStyleOrCompute, liveRightShadows);
85
+ }
86
+ }));
74
87
  this.updateShadowState = updateShadowState;
75
88
  this.table = _table;
76
89
  this.wrapper = wrapper;
@@ -84,11 +97,7 @@ export class OverflowShadowsObserver {
84
97
  if (!stickyCell) {
85
98
  return;
86
99
  }
87
- const newStickyRowHeight = stickyCell.clientHeight + 1;
88
- if (newStickyRowHeight === this.stickyRowHeight) {
89
- this.stickyRowHeight = newStickyRowHeight;
90
- this.updateStickyShadows(this.stickyRowHeight);
91
- }
100
+ this.updateStickyShadows();
92
101
  }
93
102
  getStickyCell() {
94
103
  var _this$wrapper4;
@@ -1,29 +1,11 @@
1
- import uuid from 'uuid';
2
1
  import { getCellAttrs, getCellDomAttrs } from '@atlaskit/adf-schema';
3
- import { getPluginState } from '../pm-plugins/plugin-factory';
4
2
  import TableNodeView from './TableNodeViewBase';
5
3
  const DEFAULT_COL_SPAN = 1;
6
4
  const DEFAULT_ROW_SPAN = 1;
7
5
  export default class TableCell extends TableNodeView {
8
- constructor(node, view, getPos, eventDispatcher, observer) {
6
+ constructor(node, view, getPos, eventDispatcher) {
9
7
  super(node, view, getPos, eventDispatcher);
10
- this.observer = observer;
11
- const {
12
- pluginConfig,
13
- isDragAndDropEnabled
14
- } = getPluginState(view.state);
15
- this.isStickyHeaderEnabled = !!pluginConfig.stickyHeaders;
16
- this.isDragAndDropEnabled = !!isDragAndDropEnabled;
17
- if (observer) {
18
- this.contentDOM.id = uuid();
19
- observer.observe(this.contentDOM);
20
- }
21
8
  }
22
-
23
- // @ts-ignore
24
-
25
- // @ts-ignore
26
-
27
9
  update(node) {
28
10
  const didUpdate = this.updateNodeView(node);
29
11
  if (didUpdate) {
@@ -31,11 +13,6 @@ export default class TableCell extends TableNodeView {
31
13
  }
32
14
  return didUpdate;
33
15
  }
34
- destroy() {
35
- if (this.observer) {
36
- this.observer.unobserve(this.contentDOM);
37
- }
38
- }
39
16
  updateNodeView(node) {
40
17
  if (this.node.type !== node.type) {
41
18
  return false;