@atlaskit/editor-plugin-table 15.4.21 → 15.4.22

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