@atlaskit/editor-plugin-table 15.0.12 → 15.1.0

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 (28) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/nodeviews/{TableComponent.js → TableComponentLegacy.js} +2 -0
  3. package/dist/cjs/nodeviews/TableComponentNext.js +1011 -0
  4. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +9 -2
  5. package/dist/cjs/nodeviews/toDOM.js +20 -1
  6. package/dist/cjs/ui/common-styles.js +14 -5
  7. package/dist/cjs/ui/ui-styles.js +15 -12
  8. package/dist/es2019/nodeviews/{TableComponent.js → TableComponentLegacy.js} +2 -0
  9. package/dist/es2019/nodeviews/TableComponentNext.js +975 -0
  10. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +6 -1
  11. package/dist/es2019/nodeviews/toDOM.js +20 -1
  12. package/dist/es2019/ui/common-styles.js +46 -1
  13. package/dist/es2019/ui/ui-styles.js +19 -0
  14. package/dist/esm/nodeviews/{TableComponent.js → TableComponentLegacy.js} +2 -0
  15. package/dist/esm/nodeviews/TableComponentNext.js +1005 -0
  16. package/dist/esm/nodeviews/TableComponentWithSharedState.js +8 -1
  17. package/dist/esm/nodeviews/toDOM.js +20 -1
  18. package/dist/esm/ui/common-styles.js +14 -5
  19. package/dist/esm/ui/ui-styles.js +14 -11
  20. package/dist/types/nodeviews/TableComponentLegacy.d.ts +47 -0
  21. package/dist/types/nodeviews/TableComponentNext.d.ts +47 -0
  22. package/dist/types/types/index.d.ts +3 -0
  23. package/dist/types/ui/ui-styles.d.ts +1 -0
  24. package/dist/types-ts4.5/types/index.d.ts +3 -0
  25. package/dist/types-ts4.5/ui/ui-styles.d.ts +1 -0
  26. package/package.json +6 -6
  27. /package/dist/types-ts4.5/nodeviews/{TableComponent.d.ts → TableComponentLegacy.d.ts} +0 -0
  28. /package/dist/{types/nodeviews/TableComponent.d.ts → types-ts4.5/nodeviews/TableComponentNext.d.ts} +0 -0
@@ -0,0 +1,1011 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+ var _react = _interopRequireDefault(require("react"));
16
+ var _classnames2 = _interopRequireDefault(require("classnames"));
17
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
18
+ var _reactIntlNext = require("react-intl-next");
19
+ var _collab = require("@atlaskit/editor-common/collab");
20
+ var _nesting = require("@atlaskit/editor-common/nesting");
21
+ var _nodeVisibility = require("@atlaskit/editor-common/node-visibility");
22
+ var _nodeWidth = require("@atlaskit/editor-common/node-width");
23
+ var _utils = require("@atlaskit/editor-common/utils");
24
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
25
+ var _utils2 = require("@atlaskit/editor-tables/utils");
26
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
27
+ var _combine = require("@atlaskit/pragmatic-drag-and-drop/combine");
28
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
29
+ var _commands = require("../pm-plugins/commands");
30
+ var _autoscrollers = require("../pm-plugins/drag-and-drop/utils/autoscrollers");
31
+ var _pluginKey = require("../pm-plugins/sticky-headers/plugin-key");
32
+ var _util = require("../pm-plugins/sticky-headers/util");
33
+ var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
34
+ var _consts = require("../pm-plugins/table-resizing/utils/consts");
35
+ var _dom = require("../pm-plugins/table-resizing/utils/dom");
36
+ var _misc = require("../pm-plugins/table-resizing/utils/misc");
37
+ var _resizeState = require("../pm-plugins/table-resizing/utils/resize-state");
38
+ var _scaleTable = require("../pm-plugins/table-resizing/utils/scale-table");
39
+ var _nodes = require("../pm-plugins/utils/nodes");
40
+ var _table = require("../pm-plugins/utils/table");
41
+ var _types = require("../types");
42
+ var _eventHandlers = require("../ui/event-handlers");
43
+ var _TableFloatingColumnControls = _interopRequireDefault(require("../ui/TableFloatingColumnControls"));
44
+ var _TableFloatingControls = _interopRequireDefault(require("../ui/TableFloatingControls"));
45
+ var _ExternalDropTargets = require("./ExternalDropTargets");
46
+ var _TableContainer = require("./TableContainer");
47
+ var _TableStickyScrollbar = require("./TableStickyScrollbar");
48
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
49
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
50
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
51
+ 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; }
52
+ 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; }
53
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
54
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } // Ignored via go/ees005
55
+ // eslint-disable-next-line import/no-named-as-default
56
+ var isIE11 = _utils.browser.ie_version === 11;
57
+
58
+ // Prevent unnecessary parentWidth updates when table is nested inside of a node that is nested itself.
59
+ var NESTED_TABLE_IN_NESTED_PARENT_WIDTH_DIFF_MIN_THRESHOLD = 2;
60
+ var NESTED_TABLE_IN_NESTED_PARENT_WIDTH_DIFF_MAX_THRESHOLD = 20;
61
+ // eslint-disable-next-line @repo/internal/react/no-class-components
62
+ var TableComponent = /*#__PURE__*/function (_React$Component) {
63
+ function TableComponent(props) {
64
+ var _this;
65
+ (0, _classCallCheck2.default)(this, TableComponent);
66
+ _this = _callSuper(this, TableComponent, [props]);
67
+ (0, _defineProperty2.default)(_this, "state", {
68
+ parentWidth: undefined,
69
+ tableWrapperWidth: undefined,
70
+ tableWrapperHeight: undefined,
71
+ windowResized: false
72
+ });
73
+ (0, _defineProperty2.default)(_this, "handleMouseOut", function (event) {
74
+ if (!(0, _eventHandlers.isTableInFocus)(_this.props.view)) {
75
+ return false;
76
+ }
77
+ return (0, _eventHandlers.handleMouseOut)(_this.props.view, event);
78
+ });
79
+ (0, _defineProperty2.default)(_this, "handleMouseOver", function (event) {
80
+ if (!(0, _eventHandlers.isTableInFocus)(_this.props.view)) {
81
+ return false;
82
+ }
83
+ return (0, _eventHandlers.withCellTracking)(_eventHandlers.handleMouseOver)(_this.props.view, event);
84
+ });
85
+ (0, _defineProperty2.default)(_this, "handleMouseEnter", function () {
86
+ var node = _this.props.getNode();
87
+ var pos = _this.props.getPos();
88
+ var tr = _this.props.view.state.tr;
89
+ var tableId = node.attrs.localId;
90
+ tr.setMeta('mouseEnterTable', [tableId, node, pos]);
91
+ _this.props.view.dispatch(tr);
92
+ });
93
+ (0, _defineProperty2.default)(_this, "onStickyState", function (state) {
94
+ var pos = _this.props.getPos();
95
+ if (!(0, _utils.isValidPosition)(pos, _this.props.view.state)) {
96
+ return;
97
+ }
98
+ var stickyHeader = (0, _util.findStickyHeaderForTable)(state, pos);
99
+ if (stickyHeader !== _this.state.stickyHeader) {
100
+ _this.setState({
101
+ stickyHeader: stickyHeader
102
+ });
103
+ }
104
+ });
105
+ // Ignored via go/ees005
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
+ (0, _defineProperty2.default)(_this, "prevTableState", null);
108
+ (0, _defineProperty2.default)(_this, "handleScroll", function (event) {
109
+ if (!_this.wrapper || event.target !== _this.wrapper) {
110
+ return;
111
+ }
112
+ if (_this.stickyScrollbar) {
113
+ _this.stickyScrollbar.scrollLeft(_this.wrapper.scrollLeft);
114
+ }
115
+ if (_this.table) {
116
+ // sync sticky header row to table scroll
117
+ var headers = _this.table.querySelectorAll('tr[data-header-row]');
118
+ for (var i = 0; i < headers.length; i++) {
119
+ // Ignored via go/ees005
120
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
121
+ var header = headers[i];
122
+ header.scrollLeft = _this.wrapper.scrollLeft;
123
+ header.style.marginRight = '2px';
124
+ }
125
+ }
126
+
127
+ // force update to for table controls to re-align
128
+ _this.forceUpdate();
129
+ });
130
+ (0, _defineProperty2.default)(_this, "handleTableResizing", function () {
131
+ var _this$props = _this.props,
132
+ getNode = _this$props.getNode,
133
+ containerWidth = _this$props.containerWidth,
134
+ options = _this$props.options,
135
+ allowTableResizing = _this$props.allowTableResizing;
136
+ // Ignored via go/ees005
137
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
138
+ var prevNode = _this.node;
139
+ var node = getNode();
140
+ var prevAttrs = prevNode.attrs;
141
+ var isNested = (0, _nodes.isTableNested)(_this.props.view.state, _this.props.getPos());
142
+ var parentWidth = _this.getParentNodeWidth();
143
+ if (isNested && (0, _nodes.isTableNestedInMoreThanOneNode)(_this.props.view.state, _this.props.getPos())) {
144
+ var resizeObsWrapperWidth = _this.wrapperWidth || 0;
145
+ var wrapperWidthDiffBetweenRerenders = Math.abs(resizeObsWrapperWidth - (_this.state.parentWidth || 0));
146
+ var isOusideOfThreshold = wrapperWidthDiffBetweenRerenders <= NESTED_TABLE_IN_NESTED_PARENT_WIDTH_DIFF_MIN_THRESHOLD || wrapperWidthDiffBetweenRerenders > NESTED_TABLE_IN_NESTED_PARENT_WIDTH_DIFF_MAX_THRESHOLD;
147
+ // 1. Check isOusideOfThreshold is added to prevent undersired state update.
148
+ // When table is nested in the extenstion and the table column is being resized,
149
+ // space available within extension can change and cause undesirable state update.
150
+ // MIN_THRESNESTED_TABLE_IN_NESTED_PARENT_WIDTH_DIFF_MIN_THRESHOLDHOLD value is required
151
+ // as the resizeObsWrapperWidth can differ between page reloads by 2px.
152
+
153
+ // 2. Check resizeObsWrapperWidth > 1 is added to prevent parentWidth update when table unmounts.
154
+ // When a is nested table in a nested expand and the expand collabses, the table unmounts and
155
+ // resizeObsWrapperWidth becomes 1.
156
+ parentWidth = isOusideOfThreshold && resizeObsWrapperWidth > 1 ? resizeObsWrapperWidth : _this.state.parentWidth;
157
+ }
158
+ var parentWidthChanged = parentWidth && parentWidth !== _this.state.parentWidth;
159
+ var layoutSize = _this.tableNodeLayoutSize(node, containerWidth.width, options);
160
+ var hasNumberedColumnChanged = prevAttrs.isNumberColumnEnabled !== node.attrs.isNumberColumnEnabled;
161
+ var noOfColumnsChanged = (0, _nodes.tablesHaveDifferentNoOfColumns)(node, prevNode);
162
+ if (
163
+ // We need to react if our parent changes
164
+ // Scales the cols widths relative to the new parent width.
165
+ parentWidthChanged ||
166
+ // Enabling / disabling this feature reduces or adds size to the table.
167
+ hasNumberedColumnChanged ||
168
+ // This last check is also to cater for dynamic text sizing changing the 'default' layout width
169
+ // Usually happens on window resize.
170
+ layoutSize !== _this.layoutSize || noOfColumnsChanged) {
171
+ var shouldScaleTable = (!allowTableResizing || allowTableResizing && isNested) && !hasNumberedColumnChanged && !noOfColumnsChanged;
172
+
173
+ // If column has been inserted/deleted avoid multi dispatch
174
+ if (shouldScaleTable) {
175
+ _this.scaleTable({
176
+ parentWidth: parentWidth
177
+ }, hasNumberedColumnChanged);
178
+ }
179
+
180
+ // only when table resizing is enabled and toggle numbered column to run scaleTable
181
+ if (allowTableResizing && hasNumberedColumnChanged) {
182
+ if (!(0, _colgroup.hasTableBeenResized)(prevNode)) {
183
+ _this.scaleTable({
184
+ parentWidth: node.attrs.width
185
+ }, true);
186
+ }
187
+ }
188
+ _this.updateParentWidth(parentWidth);
189
+ }
190
+ _this.node = node;
191
+ _this.containerWidth = containerWidth;
192
+ _this.layoutSize = layoutSize;
193
+ });
194
+ // Function gets called when table is nested.
195
+ (0, _defineProperty2.default)(_this, "scaleTable", function (scaleOptions) {
196
+ var isUserTriggered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
197
+ var _this$props2 = _this.props,
198
+ view = _this$props2.view,
199
+ getNode = _this$props2.getNode,
200
+ getPos = _this$props2.getPos,
201
+ containerWidth = _this$props2.containerWidth,
202
+ options = _this$props2.options;
203
+ var node = getNode();
204
+ var state = view.state,
205
+ dispatch = view.dispatch;
206
+ var pos = getPos();
207
+ if (typeof pos !== 'number' || !(0, _utils.isValidPosition)(pos, state)) {
208
+ return;
209
+ }
210
+ var domAtPos = view.domAtPos.bind(view);
211
+ var width = containerWidth.width;
212
+ _this.scaleTableDebounced.cancel();
213
+ var tr = (0, _scaleTable.scaleTable)(_this.table, _objectSpread(_objectSpread({}, scaleOptions), {}, {
214
+ node: node,
215
+ prevNode: _this.node || node,
216
+ start: pos + 1,
217
+ containerWidth: width,
218
+ // Ignored via go/ees005
219
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
220
+ previousContainerWidth: _this.containerWidth.width || width
221
+ }, options), domAtPos, _this.props.pluginInjectionApi, false,
222
+ // isTableScalingEnabled doesn't change the behavior of nested tables
223
+ false // shouldUseIncreasedScalingPercent set to false for nested tables
224
+ )(state.tr);
225
+ if (!isUserTriggered) {
226
+ (0, _collab.tintDirtyTransaction)(tr);
227
+ if ((0, _platformFeatureFlags.fg)('platform_editor_fix_table_resizing_undo')) {
228
+ // Avoid adding this transaction separately to the history as these are automatic updates
229
+ // as a consequence of another action
230
+ tr.setMeta('addToHistory', false);
231
+ }
232
+ }
233
+ dispatch(tr);
234
+ });
235
+ (0, _defineProperty2.default)(_this, "handleAutoSize", function () {
236
+ if (_this.table) {
237
+ var _this$props3 = _this.props,
238
+ view = _this$props3.view,
239
+ getNode = _this$props3.getNode,
240
+ getPos = _this$props3.getPos,
241
+ containerWidth = _this$props3.containerWidth;
242
+ var node = getNode();
243
+ var pos = getPos();
244
+ if (!(0, _utils.isValidPosition)(pos, view.state)) {
245
+ return;
246
+ }
247
+ (0, _commands.autoSizeTable)(view, node, _this.table, pos, {
248
+ containerWidth: containerWidth.width
249
+ });
250
+ }
251
+ });
252
+ (0, _defineProperty2.default)(_this, "handleWindowResize", function () {
253
+ var _this$props4 = _this.props,
254
+ getNode = _this$props4.getNode,
255
+ containerWidth = _this$props4.containerWidth;
256
+ var node = getNode();
257
+ var layoutSize = _this.tableNodeLayoutSize(node);
258
+ if (containerWidth.width > layoutSize) {
259
+ return;
260
+ }
261
+ var parentWidth = _this.getParentNodeWidth();
262
+ _this.scaleTableDebounced({
263
+ parentWidth: parentWidth
264
+ });
265
+ });
266
+ // This is a new handler for window resize events that sets the windowResized state immediately
267
+ // This is needed to update colgroup on window resize, to enforce the table scaling
268
+ (0, _defineProperty2.default)(_this, "handleWindowResizeNew", function () {
269
+ // Set resizing to true immediately
270
+ if (!_this.state.windowResized) {
271
+ _this.setState({
272
+ windowResized: true
273
+ });
274
+ }
275
+ });
276
+ (0, _defineProperty2.default)(_this, "getParentNodeWidth", function () {
277
+ var _this$props5 = _this.props,
278
+ getPos = _this$props5.getPos,
279
+ containerWidth = _this$props5.containerWidth,
280
+ options = _this$props5.options,
281
+ state = _this$props5.view.state;
282
+ var pos = getPos();
283
+ if (!(0, _utils.isValidPosition)(pos, state)) {
284
+ return;
285
+ }
286
+ var parentNodeWith = (0, _nodeWidth.getParentNodeWidth)(pos, state, containerWidth, options && options.isFullWidthModeEnabled);
287
+ return parentNodeWith;
288
+ });
289
+ (0, _defineProperty2.default)(_this, "updateParentWidth", function (width) {
290
+ _this.setState({
291
+ parentWidth: width
292
+ });
293
+ });
294
+ (0, _defineProperty2.default)(_this, "tableNodeLayoutSize", function (node, containerWidth, options) {
295
+ return (0, _misc.getLayoutSize)(node.attrs.layout, containerWidth || _this.props.containerWidth.width, options || _this.props.options || {});
296
+ });
297
+ (0, _defineProperty2.default)(_this, "shouldUpdateColgroup", function (params) {
298
+ var _this$props$options, _this$props$options2;
299
+ var isWindowResized = params.isWindowResized,
300
+ isWidthChanged = params.isWidthChanged,
301
+ isTableWidthChanged = params.isTableWidthChanged,
302
+ isColumnsDistributed = params.isColumnsDistributed,
303
+ isTableResizedFullWidth = params.isTableResizedFullWidth,
304
+ isTableDisplayModeChanged = params.isTableDisplayModeChanged,
305
+ isNumberColumnChanged = params.isNumberColumnChanged,
306
+ isNumberOfColumnsChanged = params.isNumberOfColumnsChanged,
307
+ isFullWidthModeAndLineLengthChanged = params.isFullWidthModeAndLineLengthChanged;
308
+ var isFullPageEditor = !((_this$props$options = _this.props.options) !== null && _this$props$options !== void 0 && _this$props$options.isCommentEditor) && !((_this$props$options2 = _this.props.options) !== null && _this$props$options2 !== void 0 && _this$props$options2.isChromelessEditor);
309
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) && isFullPageEditor) {
310
+ return !!isWindowResized || isColumnsDistributed || !!isTableResizedFullWidth || isTableDisplayModeChanged || isNumberColumnChanged || isNumberOfColumnsChanged || !!isFullWidthModeAndLineLengthChanged;
311
+ }
312
+ return isWidthChanged || isTableWidthChanged || isColumnsDistributed || !!isTableResizedFullWidth || isTableDisplayModeChanged || isNumberColumnChanged || isNumberOfColumnsChanged || !!isFullWidthModeAndLineLengthChanged;
313
+ });
314
+ (0, _defineProperty2.default)(_this, "scaleTableDebounced", (0, _rafSchd.default)(_this.scaleTable));
315
+ (0, _defineProperty2.default)(_this, "handleTableResizingDebounced", (0, _rafSchd.default)(_this.handleTableResizing));
316
+ (0, _defineProperty2.default)(_this, "handleScrollDebounced", (0, _rafSchd.default)(_this.handleScroll));
317
+ (0, _defineProperty2.default)(_this, "handleAutoSizeDebounced", (0, _rafSchd.default)(_this.handleAutoSize));
318
+ (0, _defineProperty2.default)(_this, "handleWindowResizeDebounced", (0, _rafSchd.default)(_this.handleWindowResize));
319
+ (0, _defineProperty2.default)(_this, "handleWindowResizeNewDebounced", (0, _rafSchd.default)(_this.handleWindowResizeNew));
320
+ var _options = props.options,
321
+ _containerWidth = props.containerWidth,
322
+ _getNode = props.getNode;
323
+ _this.node = _getNode();
324
+ _this.containerWidth = _containerWidth;
325
+ var tablePos = props.getPos();
326
+ _this.isNestedInTable = tablePos ? (0, _nesting.getParentOfTypeCount)(props.view.state.schema.nodes.table)(props.view.state.doc.resolve(tablePos)) > 0 : false;
327
+ if (!_this.updateColGroupFromFullWidthChange) {
328
+ _this.updateColGroupFromFullWidthChange = (_options === null || _options === void 0 ? void 0 : _options.isFullWidthModeEnabled) && !(_options !== null && _options !== void 0 && _options.wasFullWidthModeEnabled);
329
+ }
330
+
331
+ // store table size using previous full-width mode so can detect if it has changed.
332
+ var isFullWidthModeEnabled = _options ? _options.wasFullWidthModeEnabled : false;
333
+ _this.layoutSize = _this.tableNodeLayoutSize(_this.node, _containerWidth.width, {
334
+ isFullWidthModeEnabled: isFullWidthModeEnabled
335
+ });
336
+ _this.resizeObserver = new ResizeObserver(function (entries) {
337
+ var _iterator = _createForOfIteratorHelper(entries),
338
+ _step;
339
+ try {
340
+ var _loop = function _loop() {
341
+ var entry = _step.value;
342
+ _this.setState(function (prev) {
343
+ var _entry$contentRect, _entry$contentRect2;
344
+ 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), {}, {
345
+ tableWrapperWidth: entry.contentRect.width,
346
+ tableWrapperHeight: entry.contentRect.height
347
+ });
348
+ });
349
+ };
350
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
351
+ _loop();
352
+ }
353
+ } catch (err) {
354
+ _iterator.e(err);
355
+ } finally {
356
+ _iterator.f();
357
+ }
358
+ });
359
+
360
+ // Disable inline table editing and resizing controls in Firefox
361
+ // https://github.com/ProseMirror/prosemirror/issues/432
362
+ if ('execCommand' in document) {
363
+ ['enableObjectResizing', 'enableInlineTableEditing'].forEach(function (cmd) {
364
+ if (document.queryCommandSupported(cmd)) {
365
+ document.execCommand(cmd, false, 'false');
366
+ }
367
+ });
368
+ }
369
+ return _this;
370
+ }
371
+ (0, _inherits2.default)(TableComponent, _React$Component);
372
+ return (0, _createClass2.default)(TableComponent, [{
373
+ key: "componentDidMount",
374
+ value: function componentDidMount() {
375
+ var _this2 = this;
376
+ var _nodeVisibilityManage = (0, _nodeVisibility.nodeVisibilityManager)(this.props.view.dom),
377
+ observe = _nodeVisibilityManage.observe;
378
+ if (this.table) {
379
+ this.nodeVisibilityObserverCleanupFn = observe({
380
+ element: this.table,
381
+ onFirstVisible: function onFirstVisible() {
382
+ _this2.initialiseEventListenersAfterMount();
383
+ // force width calculation - missed resize event under firefox when
384
+ // table is nested within bodied extension
385
+ if (_this2.wrapper) {
386
+ var _this2$wrapper;
387
+ _this2.wrapperWidth = (_this2$wrapper = _this2.wrapper) === null || _this2$wrapper === void 0 ? void 0 : _this2$wrapper.clientWidth;
388
+ }
389
+ }
390
+ });
391
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true)) {
392
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
393
+ window.addEventListener('resize', this.handleWindowResizeNewDebounced);
394
+ }
395
+ }
396
+ }
397
+ }, {
398
+ key: "initialiseEventListenersAfterMount",
399
+ value: function initialiseEventListenersAfterMount() {
400
+ var _this$table,
401
+ _this$table2,
402
+ _this$table3,
403
+ _this3 = this;
404
+ var _this$props6 = this.props,
405
+ allowColumnResizing = _this$props6.allowColumnResizing,
406
+ allowTableResizing = _this$props6.allowTableResizing,
407
+ eventDispatcher = _this$props6.eventDispatcher,
408
+ isDragAndDropEnabled = _this$props6.isDragAndDropEnabled,
409
+ getNode = _this$props6.getNode,
410
+ getEditorFeatureFlags = _this$props6.getEditorFeatureFlags,
411
+ isTableScalingEnabled = _this$props6.isTableScalingEnabled;
412
+
413
+ // Ignored via go/ees005
414
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
415
+ this === null || this === void 0 || (_this$table = this.table) === null || _this$table === void 0 || _this$table.addEventListener('mouseenter', this.handleMouseEnter);
416
+
417
+ // Ignored via go/ees005
418
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
419
+ this === null || this === void 0 || (_this$table2 = this.table) === null || _this$table2 === void 0 || _this$table2.addEventListener('mouseout', this.handleMouseOut);
420
+
421
+ // Ignored via go/ees005
422
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
423
+ this === null || this === void 0 || (_this$table3 = this.table) === null || _this$table3 === void 0 || _this$table3.addEventListener('mouseover', this.handleMouseOver);
424
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
425
+ _getEditorFeatureFlag2 = _getEditorFeatureFlag.tableWithFixedColumnWidthsOption,
426
+ tableWithFixedColumnWidthsOption = _getEditorFeatureFlag2 === void 0 ? false : _getEditorFeatureFlag2;
427
+ if (!(0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true)) {
428
+ if (isTableScalingEnabled && !tableWithFixedColumnWidthsOption) {
429
+ this.handleColgroupUpdates(true);
430
+ }
431
+ if (isTableScalingEnabled && tableWithFixedColumnWidthsOption && getNode().attrs.displayMode !== 'fixed') {
432
+ this.handleColgroupUpdates(true);
433
+ }
434
+ }
435
+ if (this.wrapper) {
436
+ this.wrapperReisizeObserver = new ResizeObserver(function (entries) {
437
+ var _iterator2 = _createForOfIteratorHelper(entries),
438
+ _step2;
439
+ try {
440
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
441
+ var _entry$contentRect3;
442
+ var entry = _step2.value;
443
+ _this3.wrapperWidth = (_entry$contentRect3 = entry.contentRect) === null || _entry$contentRect3 === void 0 ? void 0 : _entry$contentRect3.width;
444
+ }
445
+ } catch (err) {
446
+ _iterator2.e(err);
447
+ } finally {
448
+ _iterator2.f();
449
+ }
450
+ });
451
+ this.wrapperReisizeObserver.observe(this.wrapper);
452
+ }
453
+ if (allowColumnResizing && this.wrapper && !isIE11) {
454
+ // Ignored via go/ees005
455
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
456
+ this.wrapper.addEventListener('scroll', this.handleScrollDebounced, {
457
+ passive: true
458
+ });
459
+ if (this.table && !this.isNestedInTable) {
460
+ this.stickyScrollbar = new _TableStickyScrollbar.TableStickyScrollbar(this.wrapper, this.props.view);
461
+ }
462
+ if (isDragAndDropEnabled) {
463
+ this.dragAndDropCleanupFn = _combine.combine.apply(void 0, (0, _toConsumableArray2.default)((0, _autoscrollers.autoScrollerFactory)({
464
+ tableWrapper: this.wrapper,
465
+ getNode: getNode
466
+ })));
467
+ }
468
+ }
469
+ if (allowColumnResizing) {
470
+ /**
471
+ * We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
472
+ * Instead we use the resize event to only trigger updates when necessary.
473
+ */
474
+ if (!allowTableResizing) {
475
+ // Ignored via go/ees005
476
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
477
+ window.addEventListener('resize', this.handleWindowResizeDebounced);
478
+ }
479
+ this.handleTableResizingDebounced();
480
+ }
481
+ var currentStickyState = _pluginKey.pluginKey.getState(this.props.view.state);
482
+ if (currentStickyState) {
483
+ this.onStickyState(currentStickyState);
484
+ }
485
+
486
+ // Ignored via go/ees005
487
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
488
+ eventDispatcher.on(_pluginKey.pluginKey.key, this.onStickyState);
489
+ }
490
+ }, {
491
+ key: "componentWillUnmount",
492
+ value: function componentWillUnmount() {
493
+ var _this$resizeObserver, _this$wrapperReisizeO, _this$table4, _this$table5, _this$table6;
494
+ var _this$props7 = this.props,
495
+ allowColumnResizing = _this$props7.allowColumnResizing,
496
+ allowTableResizing = _this$props7.allowTableResizing,
497
+ eventDispatcher = _this$props7.eventDispatcher,
498
+ isDragAndDropEnabled = _this$props7.isDragAndDropEnabled,
499
+ view = _this$props7.view,
500
+ isInDanger = _this$props7.isInDanger;
501
+ if (this.wrapper && !isIE11) {
502
+ // Ignored via go/ees005
503
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
504
+ this.wrapper.removeEventListener('scroll', this.handleScrollDebounced);
505
+ }
506
+ if (isDragAndDropEnabled && this.dragAndDropCleanupFn) {
507
+ this.dragAndDropCleanupFn();
508
+ }
509
+ if (this.nodeVisibilityObserverCleanupFn) {
510
+ this.nodeVisibilityObserverCleanupFn();
511
+ }
512
+ (_this$resizeObserver = this.resizeObserver) === null || _this$resizeObserver === void 0 || _this$resizeObserver.disconnect();
513
+ (_this$wrapperReisizeO = this.wrapperReisizeObserver) === null || _this$wrapperReisizeO === void 0 || _this$wrapperReisizeO.disconnect();
514
+ if (this.stickyScrollbar) {
515
+ this.stickyScrollbar.dispose();
516
+ }
517
+ this.handleScrollDebounced.cancel();
518
+ this.scaleTableDebounced.cancel();
519
+ this.handleTableResizingDebounced.cancel();
520
+ this.handleAutoSizeDebounced.cancel();
521
+ if (!allowTableResizing) {
522
+ this.handleWindowResizeDebounced.cancel();
523
+ }
524
+ this.handleWindowResizeNewDebounced.cancel();
525
+ if ((0, _expValEquals.expValEquals)('platform_editor_table_drag_handle_hover', 'isEnabled', true)) {
526
+ if (isInDanger) {
527
+ (0, _commands.clearHoverSelection)()(view.state, view.dispatch);
528
+ }
529
+ }
530
+ if (!allowTableResizing && allowColumnResizing) {
531
+ // Ignored via go/ees005
532
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
533
+ window.removeEventListener('resize', this.handleWindowResizeDebounced);
534
+ }
535
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true)) {
536
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
537
+ window.removeEventListener('resize', this.handleWindowResizeNewDebounced);
538
+ }
539
+
540
+ // Ignored via go/ees005
541
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
542
+ this === null || this === void 0 || (_this$table4 = this.table) === null || _this$table4 === void 0 || _this$table4.removeEventListener('mouseenter', this.handleMouseEnter);
543
+
544
+ // Ignored via go/ees005
545
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
546
+ this === null || this === void 0 || (_this$table5 = this.table) === null || _this$table5 === void 0 || _this$table5.removeEventListener('mouseout', this.handleMouseOut);
547
+
548
+ // Ignored via go/ees005
549
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
550
+ this === null || this === void 0 || (_this$table6 = this.table) === null || _this$table6 === void 0 || _this$table6.removeEventListener('mouseover', this.handleMouseOver);
551
+
552
+ // Ignored via go/ees005
553
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
554
+ eventDispatcher.off(_pluginKey.pluginKey.key, this.onStickyState);
555
+ if (this.initialOverflowCaptureTimerId) {
556
+ clearTimeout(this.initialOverflowCaptureTimerId);
557
+ }
558
+ }
559
+ }, {
560
+ key: "removeInlineTableWidth",
561
+ value:
562
+ // Should be called only when table node width is reset to undefined in Comment Editor
563
+ // Maybe replaced by handleColgroupUpdates as we implement new table's support in Comment Editor.
564
+ function removeInlineTableWidth() {
565
+ var _this$props8 = this.props,
566
+ isResizing = _this$props8.isResizing,
567
+ getNode = _this$props8.getNode,
568
+ view = _this$props8.view,
569
+ getPos = _this$props8.getPos;
570
+ if (!this.table) {
571
+ return;
572
+ }
573
+ var tableNode = getNode();
574
+ var newTableWidth = tableNode.attrs.width;
575
+ var start = getPos() || 0;
576
+ var depth = view.state.doc.resolve(start).depth;
577
+ if (depth !== 0) {
578
+ return;
579
+ }
580
+ if (!isResizing && newTableWidth === null) {
581
+ this.table.style.width = '';
582
+ }
583
+ }
584
+ }, {
585
+ key: "handleColgroupUpdates",
586
+ value: function handleColgroupUpdates() {
587
+ var _this$containerWidth,
588
+ _this4 = this;
589
+ var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
590
+ var _this$props9 = this.props,
591
+ getNode = _this$props9.getNode,
592
+ containerWidth = _this$props9.containerWidth,
593
+ isResizing = _this$props9.isResizing,
594
+ view = _this$props9.view,
595
+ getPos = _this$props9.getPos,
596
+ getEditorFeatureFlags = _this$props9.getEditorFeatureFlags,
597
+ options = _this$props9.options;
598
+ if (!this.table) {
599
+ return;
600
+ }
601
+
602
+ // Remove any widths styles after resizing preview is completed
603
+ this.table.style.width = '';
604
+ var tableNode = getNode();
605
+ var start = getPos() || 0;
606
+ var depth = view.state.doc.resolve(start).depth;
607
+ if (depth !== 0) {
608
+ return;
609
+ }
610
+ var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(tableNode);
611
+ var isTableResizedFullWidth = tableNodeWidth === 1800 && this.wasResizing && !isResizing;
612
+
613
+ // Needed for undo / redo
614
+ var isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
615
+ var tableRenderWidth = options !== null && options !== void 0 && options.isCommentEditor ? containerWidth.width - (_consts.TABLE_OFFSET_IN_COMMENT_EDITOR + 1) // should be the same as this.table.parentElement?.clientWidth - 1, subtract 1 to avoid overflow
616
+ : containerWidth.width - _consts.TABLE_EDITOR_MARGIN;
617
+ tableNodeWidth = options !== null && options !== void 0 && options.isCommentEditor && !tableNode.attrs.width ? tableRenderWidth : tableNodeWidth;
618
+ var isTableSquashed = tableRenderWidth < tableNodeWidth;
619
+ var isNumberColumnChanged = tableNode.attrs.isNumberColumnEnabled !== this.node.attrs.isNumberColumnEnabled;
620
+ var isNumberOfColumnsChanged = (0, _nodes.tablesHaveDifferentNoOfColumns)(tableNode, this.node);
621
+ var containerWidthValue = containerWidth.width,
622
+ containerLineLength = containerWidth.lineLength;
623
+ var isLineLengthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.lineLength) !== containerLineLength;
624
+ var isFullWidthModeAndLineLengthChanged = this.updateColGroupFromFullWidthChange && isLineLengthChanged && (0, _platformFeatureFlags.fg)('platform_editor_table_overflow_in_full_width_fix');
625
+ var maybeScale = isTableSquashed || isTableWidthChanged || isTableResizedFullWidth && !(options !== null && options !== void 0 && options.isCommentEditor) || isNumberColumnChanged || isNumberOfColumnsChanged || (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) && this.state.windowResized;
626
+ if (force || maybeScale || isFullWidthModeAndLineLengthChanged) {
627
+ var _this$containerWidth2, _this$props$options3, _this$props$options4, _this$props$options5;
628
+ var isWidthChanged = ((_this$containerWidth2 = this.containerWidth) === null || _this$containerWidth2 === void 0 ? void 0 : _this$containerWidth2.width) !== containerWidthValue;
629
+ var wasTableResized = (0, _colgroup.hasTableBeenResized)(this.node);
630
+ var isTableResized = (0, _colgroup.hasTableBeenResized)(tableNode);
631
+ var isColumnsDistributed = wasTableResized && !isTableResized;
632
+ var isTableDisplayModeChanged = this.node.attrs.displayMode !== tableNode.attrs.displayMode;
633
+ var shouldUpdateColgroup = this.shouldUpdateColgroup({
634
+ isWindowResized: this.state.windowResized,
635
+ isWidthChanged: isWidthChanged,
636
+ isTableWidthChanged: isTableWidthChanged,
637
+ isColumnsDistributed: isColumnsDistributed,
638
+ isTableResizedFullWidth: isTableResizedFullWidth,
639
+ isTableDisplayModeChanged: isTableDisplayModeChanged,
640
+ isNumberColumnChanged: isNumberColumnChanged,
641
+ isNumberOfColumnsChanged: isNumberOfColumnsChanged,
642
+ isFullWidthModeAndLineLengthChanged: isFullWidthModeAndLineLengthChanged
643
+ });
644
+ var _getEditorFeatureFlag3 = getEditorFeatureFlags(),
645
+ _getEditorFeatureFlag4 = _getEditorFeatureFlag3.tableWithFixedColumnWidthsOption,
646
+ tableWithFixedColumnWidthsOption = _getEditorFeatureFlag4 === void 0 ? false : _getEditorFeatureFlag4;
647
+ var isTableScalingWithFixedColumnWidthsOptionEnabled = !!((_this$props$options3 = this.props.options) !== null && _this$props$options3 !== void 0 && _this$props$options3.isTableScalingEnabled) && tableWithFixedColumnWidthsOption;
648
+ var shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled || !!((_this$props$options4 = this.props.options) !== null && _this$props$options4 !== void 0 && _this$props$options4.isTableScalingEnabled) && !!((_this$props$options5 = this.props.options) !== null && _this$props$options5 !== void 0 && _this$props$options5.isCommentEditor);
649
+ if (force || !isResizing && shouldUpdateColgroup) {
650
+ var _this$props$options6, _this$props$options7, _this$props$options8, _this$props$options9;
651
+ var resizeState = (0, _resizeState.getResizeState)({
652
+ minWidth: _consts.COLUMN_MIN_WIDTH,
653
+ // When numbered column enabled, we need to subtract the width of the numbered column
654
+ maxSize: tableNode.attrs.isNumberColumnEnabled ? tableRenderWidth - _editorSharedStyles.akEditorTableNumberColumnWidth : tableRenderWidth,
655
+ table: tableNode,
656
+ tableRef: this.table,
657
+ start: start,
658
+ domAtPos: view.domAtPos.bind(view),
659
+ isTableScalingEnabled: true,
660
+ shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
661
+ isCommentEditor: !!((_this$props$options6 = this.props.options) !== null && _this$props$options6 !== void 0 && _this$props$options6.isCommentEditor)
662
+ });
663
+ var shouldScaleOnColgroupUpdate = false;
664
+ if ((_this$props$options7 = this.props.options) !== null && _this$props$options7 !== void 0 && _this$props$options7.isTableScalingEnabled && !tableWithFixedColumnWidthsOption) {
665
+ shouldScaleOnColgroupUpdate = true;
666
+ }
667
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled && tableNode.attrs.displayMode !== 'fixed') {
668
+ shouldScaleOnColgroupUpdate = true;
669
+ }
670
+ if ((_this$props$options8 = this.props.options) !== null && _this$props$options8 !== void 0 && _this$props$options8.isTableScalingEnabled && (_this$props$options9 = this.props.options) !== null && _this$props$options9 !== void 0 && _this$props$options9.isCommentEditor) {
671
+ shouldScaleOnColgroupUpdate = true;
672
+ }
673
+ var scalePercent = 1;
674
+ requestAnimationFrame(function () {
675
+ var _this4$props$options, _this4$props$options2;
676
+ // Scaling percent has to be calculated inside requestAnimationFrame, otherwise
677
+ // renderWidth calculated as `tableRef?.parentElement?.clientWidth`
678
+ // inside of getTableScalingPercent returns 0.
679
+ if (!((_this4$props$options = _this4.props.options) !== null && _this4$props$options !== void 0 && _this4$props$options.isCommentEditor) || (_this4$props$options2 = _this4.props.options) !== null && _this4$props$options2 !== void 0 && _this4$props$options2.isCommentEditor && tableNode.attrs.width) {
680
+ scalePercent = (0, _misc.getTableScalingPercent)(tableNode,
681
+ // Ignored via go/ees005
682
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
683
+ _this4.table, shouldUseIncreasedScalingPercent);
684
+ } else {
685
+ // Ignored via go/ees005
686
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
687
+ scalePercent = (0, _misc.getScalingPercentForTableWithoutWidth)(tableNode, _this4.table);
688
+ }
689
+
690
+ // Request animation frame required for Firefox
691
+ (0, _resizeState.updateColgroup)(resizeState,
692
+ // Ignored via go/ees005
693
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
694
+ _this4.table, tableNode, shouldScaleOnColgroupUpdate, scalePercent);
695
+ });
696
+ }
697
+ }
698
+ if (isFullWidthModeAndLineLengthChanged) {
699
+ this.updateColGroupFromFullWidthChange = false;
700
+ }
701
+ this.tableNodeWidth = tableNodeWidth;
702
+ this.wasResizing = isResizing;
703
+ this.containerWidth = containerWidth;
704
+ }
705
+
706
+ // Ignored via go/ees005
707
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
708
+ }, {
709
+ key: "componentDidUpdate",
710
+ value: function componentDidUpdate(_, prevState) {
711
+ var _this$props$options0, _this$props$options1;
712
+ var _this$props0 = this.props,
713
+ view = _this$props0.view,
714
+ getNode = _this$props0.getNode,
715
+ isMediaFullscreen = _this$props0.isMediaFullscreen,
716
+ allowColumnResizing = _this$props0.allowColumnResizing,
717
+ allowTableResizing = _this$props0.allowTableResizing,
718
+ isResizing = _this$props0.isResizing,
719
+ options = _this$props0.options,
720
+ isTableScalingEnabled = _this$props0.isTableScalingEnabled,
721
+ getPos = _this$props0.getPos,
722
+ getEditorFeatureFlags = _this$props0.getEditorFeatureFlags,
723
+ isInDanger = _this$props0.isInDanger;
724
+ var table = (0, _utils2.findTable)(view.state.selection);
725
+ var shouldScale = false;
726
+ var shouldHandleColgroupUpdates = false;
727
+ var _getEditorFeatureFlag5 = getEditorFeatureFlags(),
728
+ _getEditorFeatureFlag6 = _getEditorFeatureFlag5.tableWithFixedColumnWidthsOption,
729
+ tableWithFixedColumnWidthsOption = _getEditorFeatureFlag6 === void 0 ? false : _getEditorFeatureFlag6;
730
+ if (isTableScalingEnabled && !tableWithFixedColumnWidthsOption) {
731
+ shouldScale = true;
732
+ shouldHandleColgroupUpdates = true;
733
+ }
734
+ var isTableScalingWithFixedColumnWidthsOptionEnabled = !!isTableScalingEnabled && tableWithFixedColumnWidthsOption;
735
+ var shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled || !!isTableScalingEnabled && !!((_this$props$options0 = this.props.options) !== null && _this$props$options0 !== void 0 && _this$props$options0.isCommentEditor);
736
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled && getNode().attrs.displayMode !== 'fixed') {
737
+ shouldScale = true;
738
+ shouldHandleColgroupUpdates = true;
739
+ }
740
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) && this.state.windowResized) {
741
+ shouldHandleColgroupUpdates = true;
742
+ }
743
+ if (shouldHandleColgroupUpdates) {
744
+ this.handleColgroupUpdates();
745
+ }
746
+
747
+ // table is always defined so this never runs
748
+ if (!(0, _expValEquals.expValEquals)('platform_editor_table_drag_handle_hover', 'isEnabled', true)) {
749
+ if (isInDanger && !table) {
750
+ (0, _commands.clearHoverSelection)()(view.state, view.dispatch);
751
+ }
752
+ }
753
+ if ((_this$props$options1 = this.props.options) !== null && _this$props$options1 !== void 0 && _this$props$options1.isCommentEditor && allowTableResizing && !(options !== null && options !== void 0 && options.isTableScalingEnabled)) {
754
+ this.removeInlineTableWidth();
755
+ }
756
+ var currentTable = getNode();
757
+ var previousTable = this.node;
758
+ var isNoOfColumnsChanged = (0, _nodes.tablesHaveDifferentNoOfColumns)(currentTable, previousTable);
759
+ var isNoOfRowsChanged = (0, _nodes.tablesHaveDifferentNoOfRows)(currentTable, previousTable);
760
+ if (isNoOfColumnsChanged || isNoOfRowsChanged) {
761
+ var _this$props$pluginInj;
762
+ (_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 || (_this$props$pluginInj = _this$props$pluginInj.accessibilityUtils) === null || _this$props$pluginInj === void 0 || _this$props$pluginInj.actions.ariaNotify((0, _table.getAssistiveMessage)(previousTable, currentTable, this.props.intl), {
763
+ priority: 'important'
764
+ });
765
+ }
766
+ if (currentTable.attrs.__autoSize) {
767
+ // Wait for next tick to handle auto sizing, gives the browser time to do layout calc etc.
768
+ this.handleAutoSizeDebounced();
769
+ }
770
+ // re-drawing will cause media component get unmounted that will exit fullscreen mode if media is in fullscreen mode
771
+ // see https://product-fabric.atlassian.net/browse/MEX-1290
772
+ else if (allowColumnResizing && this.table && !isMediaFullscreen) {
773
+ // If col widths (e.g. via collab) or number of columns (e.g. delete a column) have changed,
774
+ // re-draw colgroup.
775
+ if ((0, _nodes.tablesHaveDifferentColumnWidths)(currentTable, previousTable) || isNoOfColumnsChanged) {
776
+ var _view = this.props.view;
777
+ var shouldRecreateResizeCols = !allowTableResizing || !isResizing || isNoOfColumnsChanged && isResizing;
778
+ if (shouldRecreateResizeCols) {
779
+ var start = getPos() || 0;
780
+ var depth = _view.state.doc.resolve(start).depth;
781
+ shouldScale = depth === 0 && shouldScale;
782
+ (0, _colgroup.insertColgroupFromNode)(this.table, currentTable, shouldScale, undefined, shouldUseIncreasedScalingPercent, options === null || options === void 0 ? void 0 : options.isCommentEditor);
783
+ }
784
+ (0, _dom.updateControls)()(_view.state);
785
+ }
786
+ this.handleTableResizingDebounced();
787
+ }
788
+ }
789
+ }, {
790
+ key: "observeTable",
791
+ value: function observeTable(table) {
792
+ if (table) {
793
+ var _this$resizeObserver2;
794
+ (_this$resizeObserver2 = this.resizeObserver) === null || _this$resizeObserver2 === void 0 || _this$resizeObserver2.observe(table);
795
+ }
796
+ }
797
+ }, {
798
+ key: "render",
799
+ value: function render() {
800
+ var _this5 = this,
801
+ _this$props$options10;
802
+ var _this$props1 = this.props,
803
+ view = _this$props1.view,
804
+ getNode = _this$props1.getNode,
805
+ isResizing = _this$props1.isResizing,
806
+ _this$props1$allowCon = _this$props1.allowControls,
807
+ allowControls = _this$props1$allowCon === void 0 ? true : _this$props1$allowCon,
808
+ isHeaderRowEnabled = _this$props1.isHeaderRowEnabled,
809
+ ordering = _this$props1.ordering,
810
+ isHeaderColumnEnabled = _this$props1.isHeaderColumnEnabled,
811
+ tableActive = _this$props1.tableActive,
812
+ containerWidth = _this$props1.containerWidth,
813
+ options = _this$props1.options,
814
+ getPos = _this$props1.getPos,
815
+ pluginInjectionApi = _this$props1.pluginInjectionApi,
816
+ isDragAndDropEnabled = _this$props1.isDragAndDropEnabled,
817
+ getEditorFeatureFlags = _this$props1.getEditorFeatureFlags,
818
+ isTableScalingEnabled = _this$props1.isTableScalingEnabled,
819
+ allowTableResizing = _this$props1.allowTableResizing,
820
+ allowTableAlignment = _this$props1.allowTableAlignment,
821
+ selection = _this$props1.selection,
822
+ isInDanger = _this$props1.isInDanger,
823
+ hoveredRows = _this$props1.hoveredRows,
824
+ hoveredCell = _this$props1.hoveredCell,
825
+ isTableHovered = _this$props1.isTableHovered,
826
+ isWholeTableInDanger = _this$props1.isWholeTableInDanger;
827
+ var node = getNode();
828
+ var tableRef = this.table || undefined;
829
+ var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
830
+ var hasHeaderRow = (0, _nodes.containsHeaderRow)(node);
831
+ var rowControls = /*#__PURE__*/_react.default.createElement(_TableFloatingControls.default, {
832
+ editorView: view,
833
+ tableRef: tableRef,
834
+ tableNode: node,
835
+ tableActive: tableActive,
836
+ hoveredRows: hoveredRows,
837
+ hoveredCell: hoveredCell,
838
+ isTableHovered: isTableHovered,
839
+ isInDanger: isInDanger,
840
+ isResizing: isResizing,
841
+ isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
842
+ isHeaderRowEnabled: isHeaderRowEnabled,
843
+ isDragAndDropEnabled: isDragAndDropEnabled,
844
+ ordering: ordering,
845
+ isHeaderColumnEnabled: isHeaderColumnEnabled,
846
+ hasHeaderRow: hasHeaderRow
847
+ // pass `selection` and `tableHeight` to control re-render
848
+ ,
849
+ selection: view.state.selection,
850
+ headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
851
+ stickyHeader: !this.props.limitedMode ? this.state.stickyHeader : undefined,
852
+ tableWrapperWidth: this.state.tableWrapperWidth,
853
+ api: pluginInjectionApi,
854
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor
855
+ });
856
+ var tableContainerWidth = (0, _nodeWidth.getTableContainerWidth)(node);
857
+ var colControls = isDragAndDropEnabled ? /*#__PURE__*/_react.default.createElement(_TableFloatingColumnControls.default, {
858
+ editorView: view,
859
+ tableRef: tableRef,
860
+ getNode: getNode,
861
+ tableActive: tableActive,
862
+ isInDanger: isInDanger,
863
+ hoveredRows: hoveredRows,
864
+ hoveredCell: hoveredCell,
865
+ isTableHovered: isTableHovered,
866
+ isResizing: isResizing,
867
+ ordering: ordering,
868
+ hasHeaderRow: hasHeaderRow
869
+ // pass `selection` to control re-render
870
+ ,
871
+ selection: view.state.selection,
872
+ headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
873
+ stickyHeader: !this.props.limitedMode ? this.state.stickyHeader : undefined,
874
+ getEditorFeatureFlags: getEditorFeatureFlags,
875
+ tableContainerWidth: tableContainerWidth,
876
+ isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
877
+ getScrollOffset: function getScrollOffset() {
878
+ var _this5$wrapper;
879
+ return ((_this5$wrapper = _this5.wrapper) === null || _this5$wrapper === void 0 ? void 0 : _this5$wrapper.scrollLeft) || 0;
880
+ },
881
+ tableWrapperHeight: this.state.tableWrapperHeight,
882
+ api: pluginInjectionApi,
883
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor
884
+ }) : null;
885
+
886
+ /**
887
+ * ED-19838
888
+ * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
889
+ * before CR6 lands in production
890
+ */
891
+ var tablePos;
892
+ try {
893
+ tablePos = getPos ? getPos() : undefined;
894
+ } catch (e) {
895
+ tablePos = undefined;
896
+ }
897
+ var isNested = (0, _nodes.isTableNested)(view.state, tablePos);
898
+ var _getEditorFeatureFlag7 = getEditorFeatureFlags(),
899
+ _getEditorFeatureFlag8 = _getEditorFeatureFlag7.tableWithFixedColumnWidthsOption,
900
+ tableWithFixedColumnWidthsOption = _getEditorFeatureFlag8 === void 0 ? false : _getEditorFeatureFlag8;
901
+ var shouldUseIncreasedScalingPercent = !!isTableScalingEnabled && (tableWithFixedColumnWidthsOption || !!((_this$props$options10 = this.props.options) !== null && _this$props$options10 !== void 0 && _this$props$options10.isCommentEditor));
902
+ return /*#__PURE__*/_react.default.createElement(_TableContainer.TableContainer
903
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
904
+ , {
905
+ className: (0, _classnames2.default)(_types.TableCssClassName.TABLE_CONTAINER, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.TableCssClassName.WITH_CONTROLS, allowControls && tableActive), _types.TableCssClassName.TABLE_STICKY, !this.props.limitedMode && this.state.stickyHeader && hasHeaderRow), _types.TableCssClassName.HOVERED_DELETE_BUTTON, isInDanger), _types.TableCssClassName.TABLE_SELECTED, (0, _utils2.isTableSelected)(selection !== null && selection !== void 0 ? selection : view.state.selection)), _types.TableCssClassName.NESTED_TABLE_WITH_CONTROLS, tableActive && allowControls && this.isNestedInTable)),
906
+ editorView: view,
907
+ getPos: getPos,
908
+ node: node
909
+ // Ignored via go/ees005
910
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
911
+ ,
912
+ tableRef: tableRef,
913
+ containerWidth: containerWidth,
914
+ isNested: isNested,
915
+ pluginInjectionApi: pluginInjectionApi,
916
+ tableWrapperHeight: this.state.tableWrapperHeight,
917
+ isTableResizingEnabled: allowTableResizing,
918
+ isResizing: isResizing,
919
+ isTableScalingEnabled: isTableScalingEnabled,
920
+ isTableWithFixedColumnWidthsOptionEnabled: tableWithFixedColumnWidthsOption,
921
+ isWholeTableInDanger: isWholeTableInDanger,
922
+ isTableAlignmentEnabled: allowTableAlignment,
923
+ shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
924
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
925
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor
926
+ }, /*#__PURE__*/_react.default.createElement("div", {
927
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
928
+ className: _types.TableCssClassName.TABLE_STICKY_SENTINEL_TOP,
929
+ "data-testid": "sticky-sentinel-top"
930
+ }), !this.isNestedInTable && /*#__PURE__*/_react.default.createElement("div", {
931
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
932
+ className: _types.TableCssClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_TOP,
933
+ "data-testid": "sticky-scrollbar-sentinel-top"
934
+ }), allowControls && rowControls, isDragAndDropEnabled && /*#__PURE__*/_react.default.createElement(_ExternalDropTargets.ExternalDropTargets, {
935
+ editorView: view,
936
+ node: node,
937
+ getScrollOffset: function getScrollOffset() {
938
+ var _this5$wrapper2;
939
+ return ((_this5$wrapper2 = _this5.wrapper) === null || _this5$wrapper2 === void 0 ? void 0 : _this5$wrapper2.scrollLeft) || 0;
940
+ },
941
+ getTableWrapperWidth: function getTableWrapperWidth() {
942
+ var _this5$wrapper3;
943
+ return ((_this5$wrapper3 = _this5.wrapper) === null || _this5$wrapper3 === void 0 ? void 0 : _this5$wrapper3.clientWidth) || 760;
944
+ }
945
+ }), /*#__PURE__*/_react.default.createElement("div", {
946
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
947
+ className: (0, _classnames2.default)(_types.TableCssClassName.TABLE_NODE_WRAPPER, (0, _expValEquals.expValEquals)('platform_editor_disable_table_overflow_shadows', 'cohort', 'variant3') && _types.TableCssClassName.TABLE_SCROLL_INLINE_SHADOW),
948
+ ref: function ref(elem) {
949
+ _this5.wrapper = elem;
950
+ if (elem) {
951
+ _this5.props.contentDOM(elem);
952
+ var tableElement = elem.querySelector('table');
953
+ if (tableElement !== _this5.table) {
954
+ _this5.table = tableElement;
955
+ _this5.observeTable(_this5.table);
956
+ }
957
+ }
958
+ }
959
+ }, allowControls && colControls), !this.isNestedInTable ? /*#__PURE__*/_react.default.createElement("div", {
960
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
961
+ className: _types.TableCssClassName.TABLE_STICKY_SCROLLBAR_CONTAINER,
962
+ "data-vc-nvs": "true",
963
+ style: {
964
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
965
+ height: "var(--ds-space-250, 20px)",
966
+ // MAX_BROWSER_SCROLLBAR_HEIGHT
967
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
968
+ display: 'none',
969
+ // prevent unwanted scroll during table resize without removing scrollbar container from the dom
970
+ width: isResizing ? "var(--ds-space-0, 0px)" : '100%'
971
+ }
972
+ }, /*#__PURE__*/_react.default.createElement("div", {
973
+ style: {
974
+ width: tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth,
975
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
976
+ height: '100%'
977
+ },
978
+ "data-vc-nvs": "true"
979
+ })) : /*#__PURE__*/_react.default.createElement("div", {
980
+ style: {
981
+ width: tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientWidth,
982
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
983
+ height: '100%'
984
+ },
985
+ "data-vc-nvs": "true"
986
+ }), /*#__PURE__*/_react.default.createElement("div", {
987
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
988
+ className: _types.TableCssClassName.TABLE_STICKY_SENTINEL_BOTTOM,
989
+ "data-testid": "sticky-sentinel-bottom"
990
+ }), !this.isNestedInTable && /*#__PURE__*/_react.default.createElement("div", {
991
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
992
+ className: _types.TableCssClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_BOTTOM,
993
+ "data-testid": "sticky-scrollbar-sentinel-bottom"
994
+ }), (0, _expValEquals.expValEquals)('platform_editor_disable_table_overflow_shadows', 'cohort', 'variant2') && /*#__PURE__*/_react.default.createElement("div", {
995
+ contentEditable: false
996
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
997
+ ,
998
+ className: _types.TableCssClassName.TABLE_LEFT_BORDER,
999
+ "data-testid": "table-left-border"
1000
+ }), (0, _expValEquals.expValEquals)('platform_editor_disable_table_overflow_shadows', 'cohort', 'variant2') && /*#__PURE__*/_react.default.createElement("div", {
1001
+ contentEditable: false
1002
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1003
+ ,
1004
+ className: _types.TableCssClassName.TABLE_RIGHT_BORDER,
1005
+ "data-testid": "table-right-border"
1006
+ }));
1007
+ }
1008
+ }]);
1009
+ }(_react.default.Component);
1010
+ (0, _defineProperty2.default)(TableComponent, "displayName", 'TableComponent');
1011
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(TableComponent);