@atlaskit/editor-plugin-table 5.3.39 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/plugins/table/nodeviews/TableRow.js +158 -45
- package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js +0 -6
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowDropTarget/index.js +3 -0
- package/dist/cjs/plugins/table/ui/common-styles.js +18 -7
- package/dist/cjs/plugins/table/ui/ui-styles.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableRow.js +163 -50
- package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js +1 -9
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowDropTarget/index.js +1 -0
- package/dist/es2019/plugins/table/ui/common-styles.js +17 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +25 -15
- package/dist/esm/plugins/table/nodeviews/TableRow.js +158 -46
- package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js +1 -7
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowDropTarget/index.js +3 -0
- package/dist/esm/plugins/table/ui/common-styles.js +18 -7
- package/dist/esm/plugins/table/ui/ui-styles.js +1 -1
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +3 -0
- package/package.json +5 -2
- package/src/plugins/table/nodeviews/TableRow.ts +199 -52
- package/src/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +1 -7
- package/src/plugins/table/ui/TableFloatingControls/RowDropTarget/index.tsx +1 -0
- package/src/plugins/table/ui/common-styles.ts +23 -0
- package/src/plugins/table/ui/ui-styles.ts +28 -15
|
@@ -3,6 +3,7 @@ import debounce from 'lodash/debounce';
|
|
|
3
3
|
import throttle from 'lodash/throttle';
|
|
4
4
|
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
5
5
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
6
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
7
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
7
8
|
import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
|
|
8
9
|
import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
|
|
@@ -12,7 +13,6 @@ import { STICKY_HEADER_TOGGLE_TOLERANCE_MS, stickyHeaderBorderBottomWidth, stick
|
|
|
12
13
|
import { getTop, getTree } from '../utils/dom';
|
|
13
14
|
import { supportedHeaderRow } from '../utils/nodes';
|
|
14
15
|
import TableNodeView from './TableNodeViewBase';
|
|
15
|
-
|
|
16
16
|
// limit scroll event calls
|
|
17
17
|
const HEADER_ROW_SCROLL_THROTTLE_TIMEOUT = 200;
|
|
18
18
|
|
|
@@ -26,6 +26,18 @@ export default class TableRow extends TableNodeView {
|
|
|
26
26
|
_defineProperty(this, "focused", false);
|
|
27
27
|
_defineProperty(this, "topPosEditorElement", 0);
|
|
28
28
|
_defineProperty(this, "sentinels", {});
|
|
29
|
+
_defineProperty(this, "sentinelData", {
|
|
30
|
+
top: {
|
|
31
|
+
isIntersecting: false,
|
|
32
|
+
boundingClientRect: null,
|
|
33
|
+
rootBounds: null
|
|
34
|
+
},
|
|
35
|
+
bottom: {
|
|
36
|
+
isIntersecting: false,
|
|
37
|
+
boundingClientRect: null,
|
|
38
|
+
rootBounds: null
|
|
39
|
+
}
|
|
40
|
+
});
|
|
29
41
|
_defineProperty(this, "listening", false);
|
|
30
42
|
_defineProperty(this, "padding", 0);
|
|
31
43
|
_defineProperty(this, "top", 0);
|
|
@@ -232,62 +244,163 @@ export default class TableRow extends TableNodeView {
|
|
|
232
244
|
});
|
|
233
245
|
}
|
|
234
246
|
createIntersectionObserver() {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
247
|
+
if (getBooleanFF('platform.editor.table.alternative-sticky-header-logic')) {
|
|
248
|
+
this.intersectionObserver = new IntersectionObserver((entries, _) => {
|
|
249
|
+
var _this$editorScrollabl2, _this$editorScrollabl3;
|
|
250
|
+
// IMPORTANT: please try and avoid using entry.rootBounds it's terribly inconsistent. For example; sometimes it may return
|
|
251
|
+
// 0 height. In safari it will multiply all values by the window scale factor, however chrome & firfox won't.
|
|
252
|
+
// This is why i just get the scroll view bounding rect here and use it, and fallback to the entry.rootBounds if needed.
|
|
253
|
+
const rootBounds = (_this$editorScrollabl2 = this.editorScrollableElement) === null || _this$editorScrollabl2 === void 0 ? void 0 : (_this$editorScrollabl3 = _this$editorScrollabl2.getBoundingClientRect) === null || _this$editorScrollabl3 === void 0 ? void 0 : _this$editorScrollabl3.call(_this$editorScrollabl2);
|
|
254
|
+
entries.forEach(entry => {
|
|
255
|
+
const {
|
|
256
|
+
target,
|
|
257
|
+
isIntersecting,
|
|
258
|
+
boundingClientRect
|
|
259
|
+
} = entry;
|
|
260
|
+
// This observer only every looks at the top/bottom sentinels, we can assume if it's not one then it's the other.
|
|
261
|
+
const targetKey = target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_TOP) ? 'top' : 'bottom';
|
|
262
|
+
// Cache the latest sentinel information
|
|
263
|
+
this.sentinelData[targetKey] = {
|
|
264
|
+
isIntersecting,
|
|
265
|
+
boundingClientRect,
|
|
266
|
+
rootBounds: rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds
|
|
267
|
+
};
|
|
268
|
+
// Keep the other sentinels rootBounds in sync with this latest one
|
|
269
|
+
this.sentinelData[targetKey === 'top' ? 'bottom' : targetKey].rootBounds = rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds;
|
|
270
|
+
});
|
|
271
|
+
this.refreshStickyState();
|
|
272
|
+
}, {
|
|
273
|
+
threshold: 0,
|
|
274
|
+
root: this.editorScrollableElement
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
this.intersectionObserver = new IntersectionObserver((entries, _) => {
|
|
278
|
+
const tree = getTree(this.dom);
|
|
279
|
+
if (!tree) {
|
|
254
280
|
return;
|
|
255
281
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
} else {
|
|
264
|
-
table && this.makeRowHeaderNotSticky(table);
|
|
265
|
-
}
|
|
282
|
+
const {
|
|
283
|
+
table
|
|
284
|
+
} = tree;
|
|
285
|
+
if (table.rows.length < 2) {
|
|
286
|
+
// ED-19307 - When there's only one row in a table the top & bottom sentinels become inverted. This creates some nasty visiblity
|
|
287
|
+
// toggling side-effects because the intersection observers gets confused.
|
|
288
|
+
return;
|
|
266
289
|
}
|
|
267
|
-
|
|
268
|
-
var _entry$
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
290
|
+
entries.forEach(entry => {
|
|
291
|
+
var _entry$rootBounds;
|
|
292
|
+
const target = entry.target;
|
|
293
|
+
|
|
294
|
+
// if the rootBounds has 0 height, e.g. confluence preview mode, we do nothing.
|
|
295
|
+
if (((_entry$rootBounds = entry.rootBounds) === null || _entry$rootBounds === void 0 ? void 0 : _entry$rootBounds.height) === 0) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_TOP)) {
|
|
299
|
+
var _entry$rootBounds2;
|
|
300
|
+
const sentinelIsBelowScrollArea = (((_entry$rootBounds2 = entry.rootBounds) === null || _entry$rootBounds2 === void 0 ? void 0 : _entry$rootBounds2.bottom) || 0) < entry.boundingClientRect.bottom;
|
|
301
|
+
if (!entry.isIntersecting && !sentinelIsBelowScrollArea) {
|
|
302
|
+
var _entry$rootBounds3;
|
|
303
|
+
tree && this.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
304
|
+
this.lastStickyTimestamp = Date.now();
|
|
305
|
+
} else {
|
|
306
|
+
table && this.makeRowHeaderNotSticky(table);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_BOTTOM)) {
|
|
310
|
+
var _entry$rootBounds4;
|
|
311
|
+
const sentinelIsAboveScrollArea = entry.boundingClientRect.top - this.dom.offsetHeight < (((_entry$rootBounds4 = entry.rootBounds) === null || _entry$rootBounds4 === void 0 ? void 0 : _entry$rootBounds4.top) || 0);
|
|
312
|
+
if (table && !entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
313
|
+
// Not a perfect solution, but need to this code specific for FireFox ED-19177
|
|
314
|
+
if (browser.gecko) {
|
|
315
|
+
if (this.lastStickyTimestamp && Date.now() - this.lastStickyTimestamp > STICKY_HEADER_TOGGLE_TOLERANCE_MS) {
|
|
316
|
+
this.makeRowHeaderNotSticky(table);
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
274
319
|
this.makeRowHeaderNotSticky(table);
|
|
275
320
|
}
|
|
276
|
-
} else {
|
|
277
|
-
|
|
321
|
+
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
322
|
+
var _entry$rootBounds5;
|
|
323
|
+
tree && this.makeHeaderRowSticky(tree, entry === null || entry === void 0 ? void 0 : (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
324
|
+
this.lastStickyTimestamp = Date.now();
|
|
278
325
|
}
|
|
279
|
-
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
280
|
-
var _entry$rootBounds5;
|
|
281
|
-
tree && this.makeHeaderRowSticky(tree, entry === null || entry === void 0 ? void 0 : (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
282
|
-
this.lastStickyTimestamp = Date.now();
|
|
283
326
|
}
|
|
284
|
-
|
|
285
|
-
|
|
327
|
+
return;
|
|
328
|
+
});
|
|
329
|
+
}, {
|
|
330
|
+
root: this.editorScrollableElement
|
|
286
331
|
});
|
|
287
|
-
}
|
|
288
|
-
root: this.editorScrollableElement
|
|
289
|
-
});
|
|
332
|
+
}
|
|
290
333
|
}
|
|
334
|
+
refreshStickyState() {
|
|
335
|
+
const tree = getTree(this.dom);
|
|
336
|
+
if (!tree) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const {
|
|
340
|
+
table
|
|
341
|
+
} = tree;
|
|
342
|
+
const shouldStick = this.isHeaderSticky();
|
|
343
|
+
if (this.isSticky !== shouldStick) {
|
|
344
|
+
if (shouldStick) {
|
|
345
|
+
var _this$sentinelData$to;
|
|
346
|
+
// The rootRect is kept in sync across sentinels so it doesn't matter which one we use.
|
|
347
|
+
const rootRect = (_this$sentinelData$to = this.sentinelData.top.rootBounds) !== null && _this$sentinelData$to !== void 0 ? _this$sentinelData$to : this.sentinelData.bottom.rootBounds;
|
|
348
|
+
this.makeHeaderRowSticky(tree, rootRect === null || rootRect === void 0 ? void 0 : rootRect.top);
|
|
349
|
+
} else {
|
|
350
|
+
this.makeRowHeaderNotSticky(table);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
isHeaderSticky() {
|
|
355
|
+
var _sentinelTop$rootBoun;
|
|
356
|
+
/*
|
|
357
|
+
# Overview
|
|
358
|
+
I'm going to list all the view states associated with the sentinels and when they should trigger sticky headers.
|
|
359
|
+
The format of the states are; {top|bottom}:{in|above|below}
|
|
360
|
+
ie sentinel:view-position -- both "above" and "below" are equal to out of the viewport
|
|
361
|
+
For example; "top:in" means top sentinel is within the viewport. "bottom:above" means the bottom sentinel is
|
|
362
|
+
above and out of the viewport
|
|
363
|
+
This will hopefully simplify things and make it easier to determine when sticky should/shouldn't be triggered.
|
|
364
|
+
# States
|
|
365
|
+
top:in / bottom:in - NOT sticky
|
|
366
|
+
top:in / bottom:above - NOT sticky - NOTE: This is an inversion clause
|
|
367
|
+
top:in / bottom:below - NOT sticky
|
|
368
|
+
top:above / bottom:in - STICKY
|
|
369
|
+
top:above / bottom:above - NOT sticky
|
|
370
|
+
top:above / bottom:below - STICKY
|
|
371
|
+
top:below / bottom:in - NOT sticky - NOTE: This is an inversion clause
|
|
372
|
+
top:below / bottom:above - NOT sticky - NOTE: This is an inversion clause
|
|
373
|
+
top:below / bottom:below - NOT sticky
|
|
374
|
+
# Summary
|
|
375
|
+
The only time the header should be sticky is when the top sentinel is above the view and the bottom sentinel
|
|
376
|
+
is in or below it.
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
const {
|
|
380
|
+
top: sentinelTop,
|
|
381
|
+
bottom: sentinelBottom
|
|
382
|
+
} = this.sentinelData;
|
|
383
|
+
// The rootRect is kept in sync across sentinels so it doesn't matter which one we use.
|
|
384
|
+
const rootBounds = (_sentinelTop$rootBoun = sentinelTop.rootBounds) !== null && _sentinelTop$rootBoun !== void 0 ? _sentinelTop$rootBoun : sentinelBottom.rootBounds;
|
|
385
|
+
if (!rootBounds || !sentinelTop.boundingClientRect || !sentinelBottom.boundingClientRect) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Normalize the sentinels to y points
|
|
390
|
+
// Since the sentinels are actually rects 1px high we want make sure we normalise the inner most values closest to the table.
|
|
391
|
+
const sentinelTopY = sentinelTop.boundingClientRect.bottom;
|
|
392
|
+
const sentinelBottomY = sentinelBottom.boundingClientRect.top;
|
|
393
|
+
|
|
394
|
+
// If header row height is more than 50% of viewport height don't do this
|
|
395
|
+
const isRowHeaderTooLarge = this.stickyRowHeight && this.stickyRowHeight > window.innerHeight * 0.5;
|
|
396
|
+
const isTopSentinelAboveScrollArea = !sentinelTop.isIntersecting && sentinelTopY <= rootBounds.top;
|
|
397
|
+
const isBottomSentinelInOrBelowScrollArea = sentinelBottom.isIntersecting || sentinelBottomY > rootBounds.bottom;
|
|
398
|
+
|
|
399
|
+
// This makes sure that the top sentinel is actually above the bottom sentinel, and that they havn't inverted.
|
|
400
|
+
const isTopSentinelAboveBottomSentinel = sentinelTopY < sentinelBottomY;
|
|
401
|
+
return isTopSentinelAboveScrollArea && isBottomSentinelInOrBelowScrollArea && isTopSentinelAboveBottomSentinel && !isRowHeaderTooLarge;
|
|
402
|
+
}
|
|
403
|
+
|
|
291
404
|
/* receive external events */
|
|
292
405
|
|
|
293
406
|
onTablePluginState(state) {
|
|
@@ -383,7 +496,7 @@ export default class TableRow extends TableNodeView {
|
|
|
383
496
|
}
|
|
384
497
|
const domTop = currentTableTop > 0 ? scrollTop : scrollTop + currentTableTop;
|
|
385
498
|
if (!this.isSticky) {
|
|
386
|
-
var _this$
|
|
499
|
+
var _this$editorScrollabl4;
|
|
387
500
|
syncStickyRowToTable(table);
|
|
388
501
|
this.dom.classList.add('sticky');
|
|
389
502
|
table.classList.add(ClassName.TABLE_STICKY);
|
|
@@ -394,7 +507,7 @@ export default class TableRow extends TableNodeView {
|
|
|
394
507
|
* detaches from the table. This typically happens during a fast scroll by the user which causes
|
|
395
508
|
* the intersection observer logic to not fire as expected.
|
|
396
509
|
*/
|
|
397
|
-
(_this$
|
|
510
|
+
(_this$editorScrollabl4 = this.editorScrollableElement) === null || _this$editorScrollabl4 === void 0 ? void 0 : _this$editorScrollabl4.addEventListener('scrollend', this.refireIntersectionObservers, {
|
|
398
511
|
passive: true,
|
|
399
512
|
once: true
|
|
400
513
|
});
|
package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js
CHANGED
|
@@ -3,7 +3,7 @@ import classnames from 'classnames';
|
|
|
3
3
|
import { injectIntl } from 'react-intl-next';
|
|
4
4
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
5
|
import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
|
|
6
|
-
import { clearHoverSelection
|
|
6
|
+
import { clearHoverSelection } from '../../../commands';
|
|
7
7
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
8
8
|
const DragCornerControlsComponent = ({
|
|
9
9
|
editorView,
|
|
@@ -19,13 +19,6 @@ const DragCornerControlsComponent = ({
|
|
|
19
19
|
} = editorView;
|
|
20
20
|
dispatch(selectTable(state.tr).setMeta('addToHistory', false));
|
|
21
21
|
};
|
|
22
|
-
const handleMouseOver = () => {
|
|
23
|
-
const {
|
|
24
|
-
state,
|
|
25
|
-
dispatch
|
|
26
|
-
} = editorView;
|
|
27
|
-
hoverTable()(state, dispatch);
|
|
28
|
-
};
|
|
29
22
|
const handleMouseOut = () => {
|
|
30
23
|
const {
|
|
31
24
|
state,
|
|
@@ -51,7 +44,6 @@ const DragCornerControlsComponent = ({
|
|
|
51
44
|
"aria-label": formatMessage(messages.cornerControl),
|
|
52
45
|
type: "button",
|
|
53
46
|
onClick: handleOnClick,
|
|
54
|
-
onMouseOver: handleMouseOver,
|
|
55
47
|
onMouseOut: handleMouseOut,
|
|
56
48
|
contentEditable: false
|
|
57
49
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -27,6 +27,7 @@ const RowDropTarget = ({
|
|
|
27
27
|
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
|
|
28
28
|
);
|
|
29
29
|
},
|
|
30
|
+
getIsSticky: () => true,
|
|
30
31
|
getData({
|
|
31
32
|
input,
|
|
32
33
|
element
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { css } from '@emotion/react';
|
|
2
2
|
import { tableMarginTop, tableSharedStyle } from '@atlaskit/editor-common/styles';
|
|
3
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { akEditorSelectedNodeClassName, akEditorSmallZIndex, akEditorStickyHeaderZIndex, akEditorTableCellOnStickyHeaderZIndex, akEditorTableNumberColumnWidth, akEditorTableToolbarSize, akEditorUnitZIndex, getSelectionStyles, MAX_BROWSER_SCROLLBAR_HEIGHT, relativeFontSizeToBase16, SelectionStyle } from '@atlaskit/editor-shared-styles';
|
|
4
5
|
import { scrollbarStyles } from '@atlaskit/editor-shared-styles/scrollbar';
|
|
5
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -158,6 +159,20 @@ const tableStickyHeaderColumnControlsDecorationsStyle = props => {
|
|
|
158
159
|
`;
|
|
159
160
|
}
|
|
160
161
|
};
|
|
162
|
+
const tableStickyHeaderFirefoxFixStyle = props => {
|
|
163
|
+
/*
|
|
164
|
+
This is MAGIC!
|
|
165
|
+
This fixes a bug which occurs in firefox when the first row becomes sticky.
|
|
166
|
+
see https://product-fabric.atlassian.net/browse/ED-19177
|
|
167
|
+
*/
|
|
168
|
+
if (browser.gecko && getBooleanFF('platform.editor.table.alternative-sticky-header-logic')) {
|
|
169
|
+
return css`
|
|
170
|
+
.${ClassName.TABLE_STICKY} > tbody::before {
|
|
171
|
+
content: '';
|
|
172
|
+
}
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
161
176
|
const tableRowControlStyles = () => {
|
|
162
177
|
return getBooleanFF('platform.editor.table.drag-and-drop') ? css`
|
|
163
178
|
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
@@ -311,6 +326,8 @@ export const tableStyles = props => {
|
|
|
311
326
|
|
|
312
327
|
${tableStickyHeaderColumnControlsDecorationsStyle(props)}
|
|
313
328
|
|
|
329
|
+
${tableStickyHeaderFirefoxFixStyle(props)}
|
|
330
|
+
|
|
314
331
|
.${ClassName.TABLE_STICKY}
|
|
315
332
|
.${ClassName.ROW_CONTROLS}
|
|
316
333
|
.${ClassName.ROW_CONTROLS_BUTTON_WRAP}.sticky {
|
|
@@ -165,16 +165,15 @@ export const dragInsertButtonWrapper = props => css`
|
|
|
165
165
|
`;
|
|
166
166
|
export const dragCornerControlButton = props => css`
|
|
167
167
|
.${ClassName.DRAG_CORNER_BUTTON} {
|
|
168
|
-
width:
|
|
169
|
-
height:
|
|
168
|
+
width: 24px;
|
|
169
|
+
height: 24px;
|
|
170
170
|
display: flex;
|
|
171
|
-
justify-content:
|
|
172
|
-
align-items:
|
|
171
|
+
justify-content: flex-end;
|
|
172
|
+
align-items: flex-end;
|
|
173
173
|
position: absolute;
|
|
174
|
-
top: ${"var(--ds-space-negative-
|
|
175
|
-
left: ${"var(--ds-space-
|
|
176
|
-
background-color:
|
|
177
|
-
border-radius: 50%;
|
|
174
|
+
top: ${"var(--ds-space-negative-250, -20px)"};
|
|
175
|
+
left: ${"var(--ds-space-negative-100, -8px)"};
|
|
176
|
+
background-color: transparent;
|
|
178
177
|
border: none;
|
|
179
178
|
padding: 0;
|
|
180
179
|
outline: none;
|
|
@@ -182,24 +181,35 @@ export const dragCornerControlButton = props => css`
|
|
|
182
181
|
|
|
183
182
|
&.active .${ClassName.DRAG_CORNER_BUTTON_INNER} {
|
|
184
183
|
background-color: ${"var(--ds-border-selected, #0C66E4)"};
|
|
185
|
-
|
|
184
|
+
width: 10px;
|
|
185
|
+
height: 10px;
|
|
186
|
+
border-width: 2px;
|
|
187
|
+
border-radius: 4px;
|
|
188
|
+
top: ${"var(--ds-space-075, 6px)"};
|
|
189
|
+
left: ${"var(--ds-space-075, 6px)"};
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
&:hover {
|
|
189
193
|
cursor: pointer;
|
|
190
194
|
|
|
191
195
|
.${ClassName.DRAG_CORNER_BUTTON_INNER} {
|
|
192
|
-
|
|
196
|
+
width: 10px;
|
|
197
|
+
height: 10px;
|
|
198
|
+
border-width: 2px;
|
|
199
|
+
border-radius: 4px;
|
|
200
|
+
top: ${"var(--ds-space-075, 6px)"};
|
|
201
|
+
left: ${"var(--ds-space-075, 6px)"};
|
|
193
202
|
}
|
|
194
203
|
}
|
|
195
204
|
}
|
|
196
205
|
|
|
197
206
|
.${ClassName.DRAG_CORNER_BUTTON_INNER} {
|
|
198
|
-
border: 1px solid
|
|
199
|
-
|
|
200
|
-
border-radius:
|
|
201
|
-
width:
|
|
202
|
-
height:
|
|
207
|
+
border: 1px solid ${"var(--ds-border-inverse, #FFF)"};
|
|
208
|
+
background-color: ${"var(--ds-background-accent-gray-subtler, #DCDFE4)"};
|
|
209
|
+
border-radius: 2px;
|
|
210
|
+
width: 5px;
|
|
211
|
+
height: 5px;
|
|
212
|
+
position: relative;
|
|
203
213
|
}
|
|
204
214
|
`;
|
|
205
215
|
export const insertColumnButtonWrapper = props => css`
|
|
@@ -11,6 +11,7 @@ import debounce from 'lodash/debounce';
|
|
|
11
11
|
import throttle from 'lodash/throttle';
|
|
12
12
|
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
13
13
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
14
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
15
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
15
16
|
import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
|
|
16
17
|
import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
|
|
@@ -20,7 +21,6 @@ import { STICKY_HEADER_TOGGLE_TOLERANCE_MS, stickyHeaderBorderBottomWidth, stick
|
|
|
20
21
|
import { getTop, getTree } from '../utils/dom';
|
|
21
22
|
import { supportedHeaderRow } from '../utils/nodes';
|
|
22
23
|
import TableNodeView from './TableNodeViewBase';
|
|
23
|
-
|
|
24
24
|
// limit scroll event calls
|
|
25
25
|
var HEADER_ROW_SCROLL_THROTTLE_TIMEOUT = 200;
|
|
26
26
|
|
|
@@ -38,6 +38,18 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
38
38
|
_defineProperty(_assertThisInitialized(_this), "focused", false);
|
|
39
39
|
_defineProperty(_assertThisInitialized(_this), "topPosEditorElement", 0);
|
|
40
40
|
_defineProperty(_assertThisInitialized(_this), "sentinels", {});
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "sentinelData", {
|
|
42
|
+
top: {
|
|
43
|
+
isIntersecting: false,
|
|
44
|
+
boundingClientRect: null,
|
|
45
|
+
rootBounds: null
|
|
46
|
+
},
|
|
47
|
+
bottom: {
|
|
48
|
+
isIntersecting: false,
|
|
49
|
+
boundingClientRect: null,
|
|
50
|
+
rootBounds: null
|
|
51
|
+
}
|
|
52
|
+
});
|
|
41
53
|
_defineProperty(_assertThisInitialized(_this), "listening", false);
|
|
42
54
|
_defineProperty(_assertThisInitialized(_this), "padding", 0);
|
|
43
55
|
_defineProperty(_assertThisInitialized(_this), "top", 0);
|
|
@@ -261,60 +273,160 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
261
273
|
key: "createIntersectionObserver",
|
|
262
274
|
value: function createIntersectionObserver() {
|
|
263
275
|
var _this4 = this;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
if (getBooleanFF('platform.editor.table.alternative-sticky-header-logic')) {
|
|
277
|
+
this.intersectionObserver = new IntersectionObserver(function (entries, _) {
|
|
278
|
+
var _this4$editorScrollab, _this4$editorScrollab2;
|
|
279
|
+
// IMPORTANT: please try and avoid using entry.rootBounds it's terribly inconsistent. For example; sometimes it may return
|
|
280
|
+
// 0 height. In safari it will multiply all values by the window scale factor, however chrome & firfox won't.
|
|
281
|
+
// This is why i just get the scroll view bounding rect here and use it, and fallback to the entry.rootBounds if needed.
|
|
282
|
+
var rootBounds = (_this4$editorScrollab = _this4.editorScrollableElement) === null || _this4$editorScrollab === void 0 || (_this4$editorScrollab2 = _this4$editorScrollab.getBoundingClientRect) === null || _this4$editorScrollab2 === void 0 ? void 0 : _this4$editorScrollab2.call(_this4$editorScrollab);
|
|
283
|
+
entries.forEach(function (entry) {
|
|
284
|
+
var target = entry.target,
|
|
285
|
+
isIntersecting = entry.isIntersecting,
|
|
286
|
+
boundingClientRect = entry.boundingClientRect;
|
|
287
|
+
// This observer only every looks at the top/bottom sentinels, we can assume if it's not one then it's the other.
|
|
288
|
+
var targetKey = target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_TOP) ? 'top' : 'bottom';
|
|
289
|
+
// Cache the latest sentinel information
|
|
290
|
+
_this4.sentinelData[targetKey] = {
|
|
291
|
+
isIntersecting: isIntersecting,
|
|
292
|
+
boundingClientRect: boundingClientRect,
|
|
293
|
+
rootBounds: rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds
|
|
294
|
+
};
|
|
295
|
+
// Keep the other sentinels rootBounds in sync with this latest one
|
|
296
|
+
_this4.sentinelData[targetKey === 'top' ? 'bottom' : targetKey].rootBounds = rootBounds !== null && rootBounds !== void 0 ? rootBounds : entry.rootBounds;
|
|
297
|
+
});
|
|
298
|
+
_this4.refreshStickyState();
|
|
299
|
+
}, {
|
|
300
|
+
threshold: 0,
|
|
301
|
+
root: this.editorScrollableElement
|
|
302
|
+
});
|
|
303
|
+
} else {
|
|
304
|
+
this.intersectionObserver = new IntersectionObserver(function (entries, _) {
|
|
305
|
+
var tree = getTree(_this4.dom);
|
|
306
|
+
if (!tree) {
|
|
281
307
|
return;
|
|
282
308
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
tree && _this4.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
289
|
-
_this4.lastStickyTimestamp = Date.now();
|
|
290
|
-
} else {
|
|
291
|
-
table && _this4.makeRowHeaderNotSticky(table);
|
|
292
|
-
}
|
|
309
|
+
var table = tree.table;
|
|
310
|
+
if (table.rows.length < 2) {
|
|
311
|
+
// ED-19307 - When there's only one row in a table the top & bottom sentinels become inverted. This creates some nasty visiblity
|
|
312
|
+
// toggling side-effects because the intersection observers gets confused.
|
|
313
|
+
return;
|
|
293
314
|
}
|
|
294
|
-
|
|
295
|
-
var _entry$
|
|
296
|
-
var
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
315
|
+
entries.forEach(function (entry) {
|
|
316
|
+
var _entry$rootBounds;
|
|
317
|
+
var target = entry.target;
|
|
318
|
+
|
|
319
|
+
// if the rootBounds has 0 height, e.g. confluence preview mode, we do nothing.
|
|
320
|
+
if (((_entry$rootBounds = entry.rootBounds) === null || _entry$rootBounds === void 0 ? void 0 : _entry$rootBounds.height) === 0) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_TOP)) {
|
|
324
|
+
var _entry$rootBounds2;
|
|
325
|
+
var sentinelIsBelowScrollArea = (((_entry$rootBounds2 = entry.rootBounds) === null || _entry$rootBounds2 === void 0 ? void 0 : _entry$rootBounds2.bottom) || 0) < entry.boundingClientRect.bottom;
|
|
326
|
+
if (!entry.isIntersecting && !sentinelIsBelowScrollArea) {
|
|
327
|
+
var _entry$rootBounds3;
|
|
328
|
+
tree && _this4.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
329
|
+
_this4.lastStickyTimestamp = Date.now();
|
|
330
|
+
} else {
|
|
331
|
+
table && _this4.makeRowHeaderNotSticky(table);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_BOTTOM)) {
|
|
335
|
+
var _entry$rootBounds4;
|
|
336
|
+
var sentinelIsAboveScrollArea = entry.boundingClientRect.top - _this4.dom.offsetHeight < (((_entry$rootBounds4 = entry.rootBounds) === null || _entry$rootBounds4 === void 0 ? void 0 : _entry$rootBounds4.top) || 0);
|
|
337
|
+
if (table && !entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
338
|
+
// Not a perfect solution, but need to this code specific for FireFox ED-19177
|
|
339
|
+
if (browser.gecko) {
|
|
340
|
+
if (_this4.lastStickyTimestamp && Date.now() - _this4.lastStickyTimestamp > STICKY_HEADER_TOGGLE_TOLERANCE_MS) {
|
|
341
|
+
_this4.makeRowHeaderNotSticky(table);
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
301
344
|
_this4.makeRowHeaderNotSticky(table);
|
|
302
345
|
}
|
|
303
|
-
} else {
|
|
304
|
-
|
|
346
|
+
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
347
|
+
var _entry$rootBounds5;
|
|
348
|
+
tree && _this4.makeHeaderRowSticky(tree, entry === null || entry === void 0 || (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
349
|
+
_this4.lastStickyTimestamp = Date.now();
|
|
305
350
|
}
|
|
306
|
-
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
307
|
-
var _entry$rootBounds5;
|
|
308
|
-
tree && _this4.makeHeaderRowSticky(tree, entry === null || entry === void 0 || (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
309
|
-
_this4.lastStickyTimestamp = Date.now();
|
|
310
351
|
}
|
|
311
|
-
|
|
312
|
-
|
|
352
|
+
return;
|
|
353
|
+
});
|
|
354
|
+
}, {
|
|
355
|
+
root: this.editorScrollableElement
|
|
313
356
|
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}, {
|
|
360
|
+
key: "refreshStickyState",
|
|
361
|
+
value: function refreshStickyState() {
|
|
362
|
+
var tree = getTree(this.dom);
|
|
363
|
+
if (!tree) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
var table = tree.table;
|
|
367
|
+
var shouldStick = this.isHeaderSticky();
|
|
368
|
+
if (this.isSticky !== shouldStick) {
|
|
369
|
+
if (shouldStick) {
|
|
370
|
+
var _this$sentinelData$to;
|
|
371
|
+
// The rootRect is kept in sync across sentinels so it doesn't matter which one we use.
|
|
372
|
+
var rootRect = (_this$sentinelData$to = this.sentinelData.top.rootBounds) !== null && _this$sentinelData$to !== void 0 ? _this$sentinelData$to : this.sentinelData.bottom.rootBounds;
|
|
373
|
+
this.makeHeaderRowSticky(tree, rootRect === null || rootRect === void 0 ? void 0 : rootRect.top);
|
|
374
|
+
} else {
|
|
375
|
+
this.makeRowHeaderNotSticky(table);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
317
378
|
}
|
|
379
|
+
}, {
|
|
380
|
+
key: "isHeaderSticky",
|
|
381
|
+
value: function isHeaderSticky() {
|
|
382
|
+
var _sentinelTop$rootBoun;
|
|
383
|
+
/*
|
|
384
|
+
# Overview
|
|
385
|
+
I'm going to list all the view states associated with the sentinels and when they should trigger sticky headers.
|
|
386
|
+
The format of the states are; {top|bottom}:{in|above|below}
|
|
387
|
+
ie sentinel:view-position -- both "above" and "below" are equal to out of the viewport
|
|
388
|
+
For example; "top:in" means top sentinel is within the viewport. "bottom:above" means the bottom sentinel is
|
|
389
|
+
above and out of the viewport
|
|
390
|
+
This will hopefully simplify things and make it easier to determine when sticky should/shouldn't be triggered.
|
|
391
|
+
# States
|
|
392
|
+
top:in / bottom:in - NOT sticky
|
|
393
|
+
top:in / bottom:above - NOT sticky - NOTE: This is an inversion clause
|
|
394
|
+
top:in / bottom:below - NOT sticky
|
|
395
|
+
top:above / bottom:in - STICKY
|
|
396
|
+
top:above / bottom:above - NOT sticky
|
|
397
|
+
top:above / bottom:below - STICKY
|
|
398
|
+
top:below / bottom:in - NOT sticky - NOTE: This is an inversion clause
|
|
399
|
+
top:below / bottom:above - NOT sticky - NOTE: This is an inversion clause
|
|
400
|
+
top:below / bottom:below - NOT sticky
|
|
401
|
+
# Summary
|
|
402
|
+
The only time the header should be sticky is when the top sentinel is above the view and the bottom sentinel
|
|
403
|
+
is in or below it.
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
var _this$sentinelData = this.sentinelData,
|
|
407
|
+
sentinelTop = _this$sentinelData.top,
|
|
408
|
+
sentinelBottom = _this$sentinelData.bottom;
|
|
409
|
+
// The rootRect is kept in sync across sentinels so it doesn't matter which one we use.
|
|
410
|
+
var rootBounds = (_sentinelTop$rootBoun = sentinelTop.rootBounds) !== null && _sentinelTop$rootBoun !== void 0 ? _sentinelTop$rootBoun : sentinelBottom.rootBounds;
|
|
411
|
+
if (!rootBounds || !sentinelTop.boundingClientRect || !sentinelBottom.boundingClientRect) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Normalize the sentinels to y points
|
|
416
|
+
// Since the sentinels are actually rects 1px high we want make sure we normalise the inner most values closest to the table.
|
|
417
|
+
var sentinelTopY = sentinelTop.boundingClientRect.bottom;
|
|
418
|
+
var sentinelBottomY = sentinelBottom.boundingClientRect.top;
|
|
419
|
+
|
|
420
|
+
// If header row height is more than 50% of viewport height don't do this
|
|
421
|
+
var isRowHeaderTooLarge = this.stickyRowHeight && this.stickyRowHeight > window.innerHeight * 0.5;
|
|
422
|
+
var isTopSentinelAboveScrollArea = !sentinelTop.isIntersecting && sentinelTopY <= rootBounds.top;
|
|
423
|
+
var isBottomSentinelInOrBelowScrollArea = sentinelBottom.isIntersecting || sentinelBottomY > rootBounds.bottom;
|
|
424
|
+
|
|
425
|
+
// This makes sure that the top sentinel is actually above the bottom sentinel, and that they havn't inverted.
|
|
426
|
+
var isTopSentinelAboveBottomSentinel = sentinelTopY < sentinelBottomY;
|
|
427
|
+
return isTopSentinelAboveScrollArea && isBottomSentinelInOrBelowScrollArea && isTopSentinelAboveBottomSentinel && !isRowHeaderTooLarge;
|
|
428
|
+
}
|
|
429
|
+
|
|
318
430
|
/* receive external events */
|
|
319
431
|
}, {
|
|
320
432
|
key: "onTablePluginState",
|