@atlaskit/editor-plugin-table 15.6.6 → 15.6.8

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.
@@ -15,6 +15,7 @@ import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
15
15
  import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
16
16
  import { fg } from '@atlaskit/platform-feature-flags';
17
17
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
18
+ import { INITIAL_STATIC_VIEWPORT_HEIGHT } from '../pm-plugins/editor-content-area-height';
18
19
  import { getPluginState } from '../pm-plugins/plugin-factory';
19
20
  import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
20
21
  import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
@@ -37,6 +38,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
37
38
  _classCallCheck(this, TableRowNativeStickyWithFallback);
38
39
  _this = _callSuper(this, TableRowNativeStickyWithFallback, [node, view, getPos, eventDispatcher]);
39
40
  _defineProperty(_this, "cleanup", function () {
41
+ var _this$onEditorContent, _this2;
40
42
  if (_this.isStickyHeaderEnabled) {
41
43
  _this.unsubscribe();
42
44
  _this.nodeVisibilityObserverCleanupFn && _this.nodeVisibilityObserverCleanupFn();
@@ -49,6 +51,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
49
51
  if (_this.tableContainerObserver) {
50
52
  _this.tableContainerObserver.disconnect();
51
53
  }
54
+ (_this$onEditorContent = (_this2 = _this).onEditorContentAreaHeightChange) === null || _this$onEditorContent === void 0 || _this$onEditorContent.call(_this2);
52
55
  });
53
56
  _defineProperty(_this, "colControlsOffset", 0);
54
57
  _defineProperty(_this, "focused", false);
@@ -69,7 +72,8 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
69
72
  _defineProperty(_this, "listening", false);
70
73
  _defineProperty(_this, "padding", 0);
71
74
  _defineProperty(_this, "top", 0);
72
- _defineProperty(_this, "isNativeSticky", false);
75
+ _defineProperty(_this, "hasScrolledSinceLoad", false);
76
+ _defineProperty(_this, "disableNativeSticky", false);
73
77
  /**
74
78
  * Methods
75
79
  */
@@ -85,6 +89,17 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
85
89
  _this.headerRowMouseScrollEnd();
86
90
  }
87
91
  }, HEADER_ROW_SCROLL_THROTTLE_TIMEOUT));
92
+ _defineProperty(_this, "toggleDisableNativeSticky", function (headerHeight, viewportHeight) {
93
+ if (!_this.disableNativeSticky && headerHeight > viewportHeight * 0.5) {
94
+ _this.disableNativeSticky = true;
95
+ if (_this.isNativeSticky === undefined) {
96
+ _this.dom.classList.remove(ClassName.NATIVE_STICKY);
97
+ }
98
+ }
99
+ if (_this.disableNativeSticky && headerHeight <= viewportHeight * 0.5) {
100
+ _this.disableNativeSticky = false;
101
+ }
102
+ });
88
103
  _this.isHeaderRow = supportedHeaderRow(node);
89
104
  _this.isLegacySticky = false;
90
105
  var _getPluginState = getPluginState(view.state),
@@ -111,6 +126,17 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
111
126
  }
112
127
  });
113
128
  }
129
+ if (_this.isHeaderRow && _this.isStickyHeaderEnabled && fg('platform_editor_table_sticky_header_patch_4')) {
130
+ var _api$table;
131
+ _this.onEditorContentAreaHeightChange = api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.onChange(function (_ref2) {
132
+ var nextSharedState = _ref2.nextSharedState;
133
+ if (nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.editorContentAreaHeight && (nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.editorContentAreaHeight) !== _this.editorContentAreaHeight) {
134
+ var _this$stickyRowHeight;
135
+ _this.editorContentAreaHeight = nextSharedState.editorContentAreaHeight;
136
+ _this.toggleDisableNativeSticky((_this$stickyRowHeight = _this.stickyRowHeight) !== null && _this$stickyRowHeight !== void 0 ? _this$stickyRowHeight : 0, nextSharedState.editorContentAreaHeight);
137
+ }
138
+ });
139
+ }
114
140
  return _this;
115
141
  }
116
142
  _inherits(TableRowNativeStickyWithFallback, _ref);
@@ -174,10 +200,12 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
174
200
  key: "destroy",
175
201
  value: function destroy() {
176
202
  if (this.isStickyHeaderEnabled) {
203
+ var _this$nodeVisibilityO;
177
204
  this.unsubscribe();
178
205
  this.overflowObserver && this.overflowObserver.disconnect();
179
206
  this.overflowObserverEntries = undefined;
180
207
  this.stickyStateObserver && this.stickyStateObserver.disconnect();
208
+ (_this$nodeVisibilityO = this.nodeVisibilityObserver) === null || _this$nodeVisibilityO === void 0 || _this$nodeVisibilityO.disconnect();
181
209
  this.nodeVisibilityObserverCleanupFn && this.nodeVisibilityObserverCleanupFn();
182
210
  var tree = getTree(this.dom);
183
211
  if (tree) {
@@ -220,52 +248,50 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
220
248
  }, {
221
249
  key: "subscribe",
222
250
  value: function subscribe() {
223
- var _this2 = this;
251
+ var _this3 = this;
224
252
  // Ignored via go/ees005
225
253
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
226
254
  this.editorScrollableElement = findOverflowScrollParent(this.view.dom) || window;
227
255
  if (this.editorScrollableElement) {
228
256
  this.initObservers();
229
257
  this.topPosEditorElement = getTop(this.editorScrollableElement);
230
- if (!TableRowNativeStickyWithFallback.scrollListener && fg('platform_editor_table_sticky_header_patch_5')) {
231
- TableRowNativeStickyWithFallback.scrollListener = function () {
232
- if (TableRowNativeStickyWithFallback.hasScrolledSinceLoad) {
258
+ if (fg('platform_editor_table_sticky_header_patch_5')) {
259
+ this.scrollListener = function () {
260
+ var _this3$overflowObserv;
261
+ if (_this3.hasScrolledSinceLoad) {
233
262
  return;
234
263
  }
235
- TableRowNativeStickyWithFallback.hasScrolledSinceLoad = true;
236
- if (!_this2.overflowObserver) {
264
+ _this3.hasScrolledSinceLoad = true;
265
+ if (!_this3.overflowObserver) {
237
266
  return;
238
267
  }
239
268
 
240
269
  // Re-check intersection state now that scrolling has occurred
241
- if (_this2.overflowObserver) {
242
- var _this2$overflowObserv;
243
- var entries = (_this2$overflowObserv = _this2.overflowObserverEntries) !== null && _this2$overflowObserv !== void 0 ? _this2$overflowObserv : _this2.overflowObserver.takeRecords();
244
- _this2.overflowObserverEntries = undefined;
245
-
246
- /** NOTE: This logic is duplicated in the overflowObserver callback
247
- * to avoid conflicting with a follow up refactor where this will
248
- * be cleaned up.
249
- */
250
- entries.forEach(function (entry) {
251
- var tableWrapper = _this2.dom.closest(".".concat(ClassName.TABLE_NODE_WRAPPER));
252
- if (tableWrapper && tableWrapper instanceof HTMLElement) {
253
- if (entry.isIntersecting) {
254
- tableWrapper.classList.add(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
255
- _this2.dom.classList.add(ClassName.NATIVE_STICKY);
256
- _this2.isNativeSticky = true;
257
- } else {
258
- tableWrapper.classList.remove(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
259
- _this2.dom.classList.remove(ClassName.NATIVE_STICKY);
260
- _this2.isNativeSticky = false;
261
- }
262
- _this2.refreshLegacyStickyState();
270
+ var entries = (_this3$overflowObserv = _this3.overflowObserverEntries) !== null && _this3$overflowObserv !== void 0 ? _this3$overflowObserv : _this3.overflowObserver.takeRecords();
271
+ _this3.overflowObserverEntries = undefined;
272
+
273
+ /** NOTE: This logic is duplicated in the overflowObserver callback
274
+ * to avoid conflicting with a follow up refactor where this will
275
+ * be cleaned up.
276
+ */
277
+ entries.forEach(function (entry) {
278
+ var tableWrapper = _this3.dom.closest(".".concat(ClassName.TABLE_NODE_WRAPPER));
279
+ if (tableWrapper && tableWrapper instanceof HTMLElement) {
280
+ if (entry.isIntersecting) {
281
+ tableWrapper.classList.add(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
282
+ _this3.dom.classList.add(ClassName.NATIVE_STICKY);
283
+ _this3.isNativeSticky = true;
284
+ } else {
285
+ tableWrapper.classList.remove(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
286
+ _this3.dom.classList.remove(ClassName.NATIVE_STICKY);
287
+ _this3.isNativeSticky = false;
263
288
  }
264
- });
265
- }
289
+ _this3.refreshLegacyStickyState();
290
+ }
291
+ });
266
292
  };
267
293
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
268
- this.editorScrollableElement.addEventListener('scroll', TableRowNativeStickyWithFallback.scrollListener, {
294
+ this.editorScrollableElement.addEventListener('scroll', this.scrollListener, {
269
295
  passive: true,
270
296
  once: true
271
297
  });
@@ -308,10 +334,10 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
308
334
  if (this.resizeObserver) {
309
335
  this.resizeObserver.disconnect();
310
336
  }
311
- if (TableRowNativeStickyWithFallback.scrollListener && this.editorScrollableElement) {
337
+ if (this.scrollListener && this.editorScrollableElement) {
312
338
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
313
- this.editorScrollableElement.removeEventListener('scroll', TableRowNativeStickyWithFallback.scrollListener);
314
- TableRowNativeStickyWithFallback.scrollListener = undefined;
339
+ this.editorScrollableElement.removeEventListener('scroll', this.scrollListener);
340
+ this.scrollListener = undefined;
315
341
  }
316
342
  this.eventDispatcher.off('widthPlugin', this.updateStickyHeaderWidth);
317
343
  // Ignored via go/ees005
@@ -329,7 +355,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
329
355
  }, {
330
356
  key: "initOverflowObserver",
331
357
  value: function initOverflowObserver() {
332
- var _this3 = this;
358
+ var _this4 = this;
333
359
  var tableWrapper = this.dom.closest(".".concat(ClassName.TABLE_NODE_WRAPPER));
334
360
  if (!tableWrapper) {
335
361
  return;
@@ -344,20 +370,32 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
344
370
  return;
345
371
  }
346
372
  // Only apply classes if page has scrolled since load
347
- if (!TableRowNativeStickyWithFallback.hasScrolledSinceLoad && fg('platform_editor_table_sticky_header_patch_5')) {
348
- _this3.overflowObserverEntries = entries;
373
+ if (!_this4.hasScrolledSinceLoad && fg('platform_editor_table_sticky_header_patch_5')) {
374
+ _this4.overflowObserverEntries = entries;
349
375
  return;
350
376
  }
351
377
  if (entry.isIntersecting) {
352
- observer.root.classList.add(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
353
- _this3.dom.classList.add(ClassName.NATIVE_STICKY);
354
- _this3.isNativeSticky = true;
378
+ if (fg('platform_editor_table_sticky_header_patch_4')) {
379
+ observer.root.classList.add(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
380
+ if (!_this4.disableNativeSticky) {
381
+ _this4.dom.classList.add(ClassName.NATIVE_STICKY);
382
+ }
383
+ } else {
384
+ observer.root.classList.add(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
385
+ _this4.dom.classList.add(ClassName.NATIVE_STICKY);
386
+ }
387
+ _this4.isNativeSticky = true;
355
388
  } else {
356
- observer.root.classList.remove(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
357
- _this3.dom.classList.remove(ClassName.NATIVE_STICKY);
358
- _this3.isNativeSticky = false;
389
+ if (fg('platform_editor_table_sticky_header_patch_4')) {
390
+ observer.root.classList.remove(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
391
+ _this4.dom.classList.remove(ClassName.NATIVE_STICKY);
392
+ } else {
393
+ observer.root.classList.remove(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW);
394
+ _this4.dom.classList.remove(ClassName.NATIVE_STICKY);
395
+ }
396
+ _this4.isNativeSticky = false;
359
397
  }
360
- _this3.refreshLegacyStickyState();
398
+ _this4.refreshLegacyStickyState();
361
399
  });
362
400
  }, options);
363
401
  }
@@ -370,7 +408,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
370
408
  }, {
371
409
  key: "initStickyStateObserver",
372
410
  value: function initStickyStateObserver() {
373
- var _this4 = this;
411
+ var _this5 = this;
374
412
  if (!this.editorScrollableElement || !(this.editorScrollableElement instanceof Element)) {
375
413
  return;
376
414
  }
@@ -382,14 +420,14 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
382
420
  this.stickyStateObserver = new IntersectionObserver(function (entries) {
383
421
  entries.forEach(function (entry) {
384
422
  var _entry$rootBounds;
385
- var tableContainer = _this4.dom.closest(".".concat(ClassName.TABLE_CONTAINER));
386
- if (entry.intersectionRect.top === ((_entry$rootBounds = entry.rootBounds) === null || _entry$rootBounds === void 0 ? void 0 : _entry$rootBounds.top)) {
387
- _this4.dom.classList.add(ClassName.NATIVE_STICKY_ACTIVE);
423
+ var tableContainer = _this5.dom.closest(".".concat(ClassName.TABLE_CONTAINER));
424
+ if (entry.intersectionRect.top === ((_entry$rootBounds = entry.rootBounds) === null || _entry$rootBounds === void 0 ? void 0 : _entry$rootBounds.top) && (!_this5.disableNativeSticky || !fg('platform_editor_table_sticky_header_patch_4'))) {
425
+ _this5.dom.classList.add(ClassName.NATIVE_STICKY_ACTIVE);
388
426
  if (tableContainer && tableContainer instanceof HTMLElement) {
389
427
  tableContainer.dataset.tableHeaderIsStuck = 'true';
390
428
  }
391
429
  } else {
392
- _this4.dom.classList.remove(ClassName.NATIVE_STICKY_ACTIVE);
430
+ _this5.dom.classList.remove(ClassName.NATIVE_STICKY_ACTIVE);
393
431
  if (tableContainer && tableContainer instanceof HTMLElement) {
394
432
  if (fg('platform_editor_table_sticky_header_patch_3')) {
395
433
  delete tableContainer.dataset.tableHeaderIsStuck;
@@ -406,7 +444,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
406
444
  }, {
407
445
  key: "initObservers",
408
446
  value: function initObservers() {
409
- var _this5 = this;
447
+ var _this6 = this;
410
448
  if (!this.dom || this.dom.dataset.isObserved) {
411
449
  return;
412
450
  }
@@ -423,10 +461,17 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
423
461
  this.dom.style.setProperty('anchor-name', (_this$dom$getAttribut = this.dom.getAttribute('data-node-anchor')) !== null && _this$dom$getAttribut !== void 0 ? _this$dom$getAttribut : '');
424
462
  }
425
463
  this.initOverflowObserver();
464
+ if (fg('platform_editor_table_sticky_header_patch_4')) {
465
+ this.initNodeVisibilityObserver();
466
+ }
426
467
  var closestTable = this.dom.closest('table');
427
468
  if (closestTable) {
428
469
  var _this$overflowObserve;
429
470
  (_this$overflowObserve = this.overflowObserver) === null || _this$overflowObserve === void 0 || _this$overflowObserve.observe(closestTable);
471
+ if (fg('platform_editor_table_sticky_header_patch_4')) {
472
+ var _this$nodeVisibilityO2;
473
+ (_this$nodeVisibilityO2 = this.nodeVisibilityObserver) === null || _this$nodeVisibilityO2 === void 0 || _this$nodeVisibilityO2.observe(closestTable);
474
+ }
430
475
  }
431
476
  this.initStickyStateObserver();
432
477
  (_this$stickyStateObse = this.stickyStateObserver) === null || _this$stickyStateObse === void 0 || _this$stickyStateObse.observe(this.dom);
@@ -440,7 +485,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
440
485
  window.requestAnimationFrame(function () {
441
486
  var getTableContainer = function getTableContainer() {
442
487
  var _getTree;
443
- return (_getTree = getTree(_this5.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(TableCssClassName.NODEVIEW_WRAPPER));
488
+ return (_getTree = getTree(_this6.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(TableCssClassName.NODEVIEW_WRAPPER));
444
489
  };
445
490
 
446
491
  // we expect tree to be defined after animation frame
@@ -466,16 +511,16 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
466
511
  return getSentinelTop() !== null && getSentinelBottom() !== null;
467
512
  };
468
513
  var observeStickySentinels = function observeStickySentinels() {
469
- _this5.sentinels.top = getSentinelTop();
470
- _this5.sentinels.bottom = getSentinelBottom();
471
- [_this5.sentinels.top, _this5.sentinels.bottom].forEach(function (el) {
514
+ _this6.sentinels.top = getSentinelTop();
515
+ _this6.sentinels.bottom = getSentinelBottom();
516
+ [_this6.sentinels.top, _this6.sentinels.bottom].forEach(function (el) {
472
517
  // skip if already observed for another row on this table
473
518
  if (el && !el.dataset.isObserved) {
474
519
  el.dataset.isObserved = 'true';
475
520
 
476
521
  // Ignored via go/ees005
477
522
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
478
- _this5.intersectionObserver.observe(el);
523
+ _this6.intersectionObserver.observe(el);
479
524
  }
480
525
  });
481
526
  };
@@ -490,7 +535,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
490
535
  // observe sentinels before they are in the DOM, use MutationObserver
491
536
  // to wait for sentinels to be added to the parent Table node DOM
492
537
  // then attach the IntersectionObserver
493
- _this5.tableContainerObserver = new MutationObserver(function () {
538
+ _this6.tableContainerObserver = new MutationObserver(function () {
494
539
  // Check if the tableContainer is still connected to the DOM. It can become disconnected when the placholder
495
540
  // prosemirror node is replaced with the fully rendered React node (see _handleTableRef).
496
541
 
@@ -498,14 +543,14 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
498
543
  tableContainer = getTableContainer();
499
544
  }
500
545
  if (sentinelsInDom()) {
501
- var _this5$tableContainer;
546
+ var _this6$tableContainer;
502
547
  observeStickySentinels();
503
- (_this5$tableContainer = _this5.tableContainerObserver) === null || _this5$tableContainer === void 0 || _this5$tableContainer.disconnect();
548
+ (_this6$tableContainer = _this6.tableContainerObserver) === null || _this6$tableContainer === void 0 || _this6$tableContainer.disconnect();
504
549
  }
505
550
  });
506
551
  var mutatingNode = tableContainer;
507
- if (mutatingNode && _this5.tableContainerObserver) {
508
- _this5.tableContainerObserver.observe(mutatingNode, {
552
+ if (mutatingNode && _this6.tableContainerObserver) {
553
+ _this6.tableContainerObserver.observe(mutatingNode, {
509
554
  subtree: true,
510
555
  childList: true
511
556
  });
@@ -515,39 +560,69 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
515
560
  });
516
561
  }
517
562
 
563
+ // initialise intersection observer to track whether table is in scroll area
564
+ }, {
565
+ key: "initNodeVisibilityObserver",
566
+ value: function initNodeVisibilityObserver() {
567
+ var _this7 = this;
568
+ this.nodeVisibilityObserver = new IntersectionObserver(function (entries) {
569
+ entries.forEach(function (entry) {
570
+ if (!_this7.isNativeSticky) {
571
+ return;
572
+ }
573
+ if (entry.intersectionRatio !== 0 && entry.intersectionRatio !== 1) {
574
+ return;
575
+ }
576
+ if (_this7.disableNativeSticky === true) {
577
+ _this7.dom.classList.remove(ClassName.NATIVE_STICKY);
578
+ }
579
+ if (_this7.disableNativeSticky === false) {
580
+ _this7.dom.classList.add(ClassName.NATIVE_STICKY);
581
+ }
582
+ });
583
+ }, {
584
+ threshold: [0, 0.05, 0.95, 1]
585
+ });
586
+ }
587
+
518
588
  // updating bottom sentinel position if sticky header height changes
519
589
  // to allocate for new header height
520
590
  }, {
521
591
  key: "createResizeObserver",
522
592
  value: function createResizeObserver() {
523
- var _this6 = this;
593
+ var _this8 = this;
524
594
  this.resizeObserver = new ResizeObserver(function (entries) {
525
- var tree = getTree(_this6.dom);
595
+ var tree = getTree(_this8.dom);
526
596
  if (!tree) {
527
597
  return;
528
598
  }
529
599
  var table = tree.table;
530
600
  entries.forEach(function (entry) {
531
- var _this6$editorScrollab;
601
+ var _this8$editorScrollab;
532
602
  // On resize of the parent scroll element we need to adjust the width
533
603
  // of the sticky header
534
604
  // Ignored via go/ees005
535
605
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
536
- if (entry.target.className === ((_this6$editorScrollab = _this6.editorScrollableElement) === null || _this6$editorScrollab === void 0 ? void 0 : _this6$editorScrollab.className)) {
537
- _this6.updateStickyHeaderWidth();
606
+ if (entry.target.className === ((_this8$editorScrollab = _this8.editorScrollableElement) === null || _this8$editorScrollab === void 0 ? void 0 : _this8$editorScrollab.className)) {
607
+ _this8.updateStickyHeaderWidth();
538
608
  } else {
539
609
  var newHeight = entry.contentRect ? entry.contentRect.height :
540
610
  // Ignored via go/ees005
541
611
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
542
612
  entry.target.offsetHeight;
543
- if (_this6.sentinels.bottom &&
613
+ if (_this8.sentinels.bottom &&
544
614
  // When the table header is sticky, it would be taller by a 1px (border-bottom),
545
615
  // So we adding this check to allow a 1px difference.
546
- Math.abs(newHeight - (_this6.stickyRowHeight || 0)) > stickyHeaderBorderBottomWidth) {
547
- _this6.stickyRowHeight = newHeight;
548
- _this6.sentinels.bottom.style.bottom = "".concat(tableScrollbarOffset + stickyRowOffsetTop + newHeight, "px");
616
+ Math.abs(newHeight - (_this8.stickyRowHeight || 0)) > stickyHeaderBorderBottomWidth) {
617
+ _this8.stickyRowHeight = newHeight;
618
+ _this8.sentinels.bottom.style.bottom = "".concat(tableScrollbarOffset + stickyRowOffsetTop + newHeight, "px");
549
619
  updateTableMargin(table);
550
620
  }
621
+ if (fg('platform_editor_table_sticky_header_patch_4')) {
622
+ var _this8$editorContentA;
623
+ var viewportHeight = (_this8$editorContentA = _this8.editorContentAreaHeight) !== null && _this8$editorContentA !== void 0 ? _this8$editorContentA : INITIAL_STATIC_VIEWPORT_HEIGHT;
624
+ _this8.toggleDisableNativeSticky(newHeight, viewportHeight);
625
+ }
551
626
  }
552
627
  });
553
628
  });
@@ -555,13 +630,13 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
555
630
  }, {
556
631
  key: "createIntersectionObserver",
557
632
  value: function createIntersectionObserver() {
558
- var _this7 = this;
633
+ var _this9 = this;
559
634
  this.intersectionObserver = new IntersectionObserver(function (entries, _) {
560
- var _this7$editorScrollab, _this7$editorScrollab2;
635
+ var _this9$editorScrollab, _this9$editorScrollab2;
561
636
  // IMPORTANT: please try and avoid using entry.rootBounds it's terribly inconsistent. For example; sometimes it may return
562
637
  // 0 height. In safari it will multiply all values by the window scale factor, however chrome & firfox won't.
563
638
  // This is why i just get the scroll view bounding rect here and use it, and fallback to the entry.rootBounds if needed.
564
- var rootBounds = (_this7$editorScrollab = _this7.editorScrollableElement) === null || _this7$editorScrollab === void 0 || (_this7$editorScrollab2 = _this7$editorScrollab.getBoundingClientRect) === null || _this7$editorScrollab2 === void 0 ? void 0 : _this7$editorScrollab2.call(_this7$editorScrollab);
639
+ var rootBounds = (_this9$editorScrollab = _this9.editorScrollableElement) === null || _this9$editorScrollab === void 0 || (_this9$editorScrollab2 = _this9$editorScrollab.getBoundingClientRect) === null || _this9$editorScrollab2 === void 0 ? void 0 : _this9$editorScrollab2.call(_this9$editorScrollab);
565
640
  entries.forEach(function (entry) {
566
641
  var target = entry.target,
567
642
  isIntersecting = entry.isIntersecting,
@@ -569,15 +644,15 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
569
644
  // This observer only every looks at the top/bottom sentinels, we can assume if it's not one then it's the other.
570
645
  var targetKey = target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_TOP) ? 'top' : 'bottom';
571
646
  // Cache the latest sentinel information
572
- _this7.sentinelData[targetKey] = {
647
+ _this9.sentinelData[targetKey] = {
573
648
  isIntersecting: isIntersecting,
574
649
  boundingClientRect: boundingClientRect,
575
650
  rootBounds: rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds
576
651
  };
577
652
  // Keep the other sentinels rootBounds in sync with this latest one
578
- _this7.sentinelData[targetKey === 'top' ? 'bottom' : targetKey].rootBounds = rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds;
653
+ _this9.sentinelData[targetKey === 'top' ? 'bottom' : targetKey].rootBounds = rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds;
579
654
  });
580
- _this7.refreshLegacyStickyState();
655
+ _this9.refreshLegacyStickyState();
581
656
  }, {
582
657
  threshold: 0,
583
658
  root: this.editorScrollableElement
@@ -636,27 +711,27 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
636
711
  value: function isHeaderSticky() {
637
712
  var _sentinelTop$rootBoun;
638
713
  /*
639
- # Overview
640
- I'm going to list all the view states associated with the sentinels and when they should trigger sticky headers.
641
- The format of the states are; {top|bottom}:{in|above|below}
642
- ie sentinel:view-position -- both "above" and "below" are equal to out of the viewport
643
- For example; "top:in" means top sentinel is within the viewport. "bottom:above" means the bottom sentinel is
644
- above and out of the viewport
645
- This will hopefully simplify things and make it easier to determine when sticky should/shouldn't be triggered.
646
- # States
647
- top:in / bottom:in - NOT sticky
648
- top:in / bottom:above - NOT sticky - NOTE: This is an inversion clause
649
- top:in / bottom:below - NOT sticky
650
- top:above / bottom:in - STICKY
651
- top:above / bottom:above - NOT sticky
652
- top:above / bottom:below - STICKY
653
- top:below / bottom:in - NOT sticky - NOTE: This is an inversion clause
654
- top:below / bottom:above - NOT sticky - NOTE: This is an inversion clause
655
- top:below / bottom:below - NOT sticky
656
- # Summary
657
- The only time the header should be sticky is when the top sentinel is above the view and the bottom sentinel
658
- is in or below it.
659
- */
714
+ # Overview
715
+ I'm going to list all the view states associated with the sentinels and when they should trigger sticky headers.
716
+ The format of the states are; {top|bottom}:{in|above|below}
717
+ ie sentinel:view-position -- both "above" and "below" are equal to out of the viewport
718
+ For example; "top:in" means top sentinel is within the viewport. "bottom:above" means the bottom sentinel is
719
+ above and out of the viewport
720
+ This will hopefully simplify things and make it easier to determine when sticky should/shouldn't be triggered.
721
+ # States
722
+ top:in / bottom:in - NOT sticky
723
+ top:in / bottom:above - NOT sticky - NOTE: This is an inversion clause
724
+ top:in / bottom:below - NOT sticky
725
+ top:above / bottom:in - STICKY
726
+ top:above / bottom:above - NOT sticky
727
+ top:above / bottom:below - STICKY
728
+ top:below / bottom:in - NOT sticky - NOTE: This is an inversion clause
729
+ top:below / bottom:above - NOT sticky - NOTE: This is an inversion clause
730
+ top:below / bottom:below - NOT sticky
731
+ # Summary
732
+ The only time the header should be sticky is when the top sentinel is above the view and the bottom sentinel
733
+ is in or below it.
734
+ */
660
735
 
661
736
  var _this$sentinelData = this.sentinelData,
662
737
  sentinelTop = _this$sentinelData.top,
@@ -752,12 +827,12 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
752
827
  }, {
753
828
  key: "refireIntersectionObservers",
754
829
  value: function refireIntersectionObservers() {
755
- var _this8 = this;
830
+ var _this0 = this;
756
831
  if (this.isLegacySticky) {
757
832
  [this.sentinels.top, this.sentinels.bottom].forEach(function (el) {
758
- if (el && _this8.intersectionObserver) {
759
- _this8.intersectionObserver.unobserve(el);
760
- _this8.intersectionObserver.observe(el);
833
+ if (el && _this0.intersectionObserver) {
834
+ _this0.intersectionObserver.unobserve(el);
835
+ _this0.intersectionObserver.observe(el);
761
836
  }
762
837
  });
763
838
  }
@@ -766,7 +841,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
766
841
  key: "makeHeaderRowLegacySticky",
767
842
  value: function makeHeaderRowLegacySticky(tree, scrollTop) {
768
843
  var _tbody$firstChild,
769
- _this9 = this;
844
+ _this1 = this;
770
845
  // If header row height is more than 50% of viewport height don't do this
771
846
  if (this.isLegacySticky || this.stickyRowHeight && this.stickyRowHeight > window.innerHeight / 2 || this.isInNestedTable) {
772
847
  return;
@@ -805,7 +880,7 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
805
880
  });
806
881
  var fastScrollThresholdMs = 500;
807
882
  setTimeout(function () {
808
- _this9.refireIntersectionObservers();
883
+ _this1.refireIntersectionObservers();
809
884
  }, fastScrollThresholdMs);
810
885
  }
811
886
  this.dom.style.top = "0px";
@@ -894,5 +969,4 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_ref) {
894
969
  }
895
970
  }]);
896
971
  }(TableNodeView);
897
- _defineProperty(TableRowNativeStickyWithFallback, "hasScrolledSinceLoad", false);
898
972
  export { TableRowNativeStickyWithFallback as default };
@@ -0,0 +1,63 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; } } }; }
3
+ 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; } }
4
+ 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; }
5
+ 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; }
6
+ 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; }
7
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
9
+ export var pluginKey = new PluginKey('editorContentAreaHeightPlugin');
10
+ export var INITIAL_STATIC_VIEWPORT_HEIGHT = 1200;
11
+ export var EDITOR_CONTENT_AREA_REGION_CLASSNAME = '.ak-editor-content-area-region';
12
+ var createPlugin = function createPlugin() {
13
+ return new SafePlugin({
14
+ key: pluginKey,
15
+ state: {
16
+ init: function init() {
17
+ return {
18
+ height: INITIAL_STATIC_VIEWPORT_HEIGHT
19
+ };
20
+ },
21
+ apply: function apply(tr, pluginState) {
22
+ var meta = tr.getMeta(pluginKey);
23
+ if (meta) {
24
+ return _objectSpread(_objectSpread({}, pluginState), meta);
25
+ }
26
+ return pluginState;
27
+ }
28
+ },
29
+ view: function view(_view) {
30
+ var editorContentAreaEl = _view.dom.closest(EDITOR_CONTENT_AREA_REGION_CLASSNAME);
31
+ var resizeObserver;
32
+ if (editorContentAreaEl) {
33
+ resizeObserver = new ResizeObserver(function (entries) {
34
+ var _iterator = _createForOfIteratorHelper(entries),
35
+ _step;
36
+ try {
37
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
38
+ var entry = _step.value;
39
+ var height = entry.contentRect.height;
40
+ var tr = _view.state.tr.setMeta(pluginKey, {
41
+ height: height,
42
+ isObserved: true
43
+ });
44
+ _view.dispatch(tr);
45
+ }
46
+ } catch (err) {
47
+ _iterator.e(err);
48
+ } finally {
49
+ _iterator.f();
50
+ }
51
+ });
52
+ resizeObserver.observe(editorContentAreaEl);
53
+ }
54
+ return {
55
+ destroy: function destroy() {
56
+ var _resizeObserver;
57
+ (_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 || _resizeObserver.disconnect();
58
+ }
59
+ };
60
+ }
61
+ });
62
+ };
63
+ export { createPlugin };