@atlaskit/editor-plugin-table 7.5.5 → 7.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/commands/selection.js +23 -1
- package/dist/cjs/event-handlers.js +25 -9
- package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/cjs/nodeviews/TableCell.js +5 -30
- package/dist/cjs/nodeviews/TableComponent.js +96 -41
- package/dist/cjs/nodeviews/TableContainer.js +19 -17
- package/dist/cjs/nodeviews/TableResizer.js +1 -1
- package/dist/cjs/plugin.js +2 -3
- package/dist/cjs/pm-plugins/main.js +3 -18
- package/dist/cjs/pm-plugins/sticky-headers/types.js +1 -5
- package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +11 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +22 -23
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/cjs/pm-plugins/table-selection-keymap.js +3 -0
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
- package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
- package/dist/cjs/utils/column-controls.js +5 -5
- package/dist/cjs/utils/dom.js +13 -15
- package/dist/es2019/commands/selection.js +22 -0
- package/dist/es2019/event-handlers.js +25 -9
- package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/es2019/nodeviews/TableCell.js +1 -24
- package/dist/es2019/nodeviews/TableComponent.js +69 -31
- package/dist/es2019/nodeviews/TableContainer.js +16 -18
- package/dist/es2019/nodeviews/TableResizer.js +1 -1
- package/dist/es2019/plugin.js +2 -3
- package/dist/es2019/pm-plugins/main.js +3 -18
- package/dist/es2019/pm-plugins/sticky-headers/types.js +0 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +10 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +21 -22
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/es2019/pm-plugins/table-selection-keymap.js +5 -2
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
- package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
- package/dist/es2019/utils/column-controls.js +6 -6
- package/dist/es2019/utils/dom.js +13 -15
- package/dist/esm/commands/selection.js +22 -0
- package/dist/esm/event-handlers.js +25 -9
- package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/esm/nodeviews/TableCell.js +5 -30
- package/dist/esm/nodeviews/TableComponent.js +96 -41
- package/dist/esm/nodeviews/TableContainer.js +20 -18
- package/dist/esm/nodeviews/TableResizer.js +1 -1
- package/dist/esm/plugin.js +2 -3
- package/dist/esm/pm-plugins/main.js +3 -18
- package/dist/esm/pm-plugins/sticky-headers/types.js +0 -1
- package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +10 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +23 -24
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/esm/pm-plugins/table-selection-keymap.js +5 -2
- package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
- package/dist/esm/ui/TableFloatingControls/index.js +113 -224
- package/dist/esm/utils/column-controls.js +6 -6
- package/dist/esm/utils/dom.js +13 -15
- package/dist/types/commands/selection.d.ts +1 -0
- package/dist/types/event-handlers.d.ts +3 -4
- package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
- package/dist/types/nodeviews/TableCell.d.ts +1 -5
- package/dist/types/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types/types.d.ts +0 -3
- package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types/utils/dom.d.ts +10 -2
- package/dist/types-ts4.5/commands/selection.d.ts +1 -0
- package/dist/types-ts4.5/event-handlers.d.ts +3 -4
- package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
- package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +0 -3
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types-ts4.5/utils/dom.d.ts +10 -2
- package/package.json +8 -6
- package/src/commands/selection.ts +33 -0
- package/src/event-handlers.ts +105 -103
- package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
- package/src/nodeviews/TableCell.ts +0 -26
- package/src/nodeviews/TableComponent.tsx +81 -34
- package/src/nodeviews/TableContainer.tsx +19 -25
- package/src/nodeviews/TableResizer.tsx +1 -4
- package/src/plugin.tsx +5 -4
- package/src/pm-plugins/main.ts +3 -22
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +3 -6
- package/src/pm-plugins/table-resizing/utils/misc.ts +13 -0
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +22 -28
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +3 -10
- package/src/pm-plugins/table-selection-keymap.ts +10 -0
- package/src/types.ts +0 -4
- package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
- package/src/ui/TableFloatingControls/index.tsx +155 -241
- package/src/utils/column-controls.ts +5 -6
- package/src/utils/dom.ts +12 -19
|
@@ -34,6 +34,12 @@ const isIE11 = browser.ie_version === 11;
|
|
|
34
34
|
// componentDidUpdate is called multiple times. The isOverflowing value is correct only on the last update.
|
|
35
35
|
// To make sure we capture the last update, we use setTimeout.
|
|
36
36
|
const initialOverflowCaptureTimeroutDelay = 300;
|
|
37
|
+
|
|
38
|
+
// This is a hard switch for controlling whether the overflow analytics should be dispatched. There has been 6months of data
|
|
39
|
+
// already collected which we could use but have not. This has been disabled rather then removed entirely in the event that
|
|
40
|
+
// the current collected data becomes stale and we want to start collecting fresh data again in future.
|
|
41
|
+
// PLEASE NOTE: that the current way this alaytics has been configured WILL cause reflows to occur. This is why the has been disabled.
|
|
42
|
+
const isOverflowAnalyticsEnabled = false;
|
|
37
43
|
class TableComponent extends React.Component {
|
|
38
44
|
constructor(props) {
|
|
39
45
|
super(props);
|
|
@@ -41,7 +47,9 @@ class TableComponent extends React.Component {
|
|
|
41
47
|
scroll: 0,
|
|
42
48
|
parentWidth: undefined,
|
|
43
49
|
[ShadowEvent.SHOW_BEFORE_SHADOW]: false,
|
|
44
|
-
[ShadowEvent.SHOW_AFTER_SHADOW]: false
|
|
50
|
+
[ShadowEvent.SHOW_AFTER_SHADOW]: false,
|
|
51
|
+
tableWrapperWidth: undefined,
|
|
52
|
+
tableWrapperHeight: undefined
|
|
45
53
|
});
|
|
46
54
|
_defineProperty(this, "updateShadowState", (shadowKey, value) => {
|
|
47
55
|
if (this.state[shadowKey] === value) {
|
|
@@ -293,6 +301,18 @@ class TableComponent extends React.Component {
|
|
|
293
301
|
this.layoutSize = this.tableNodeLayoutSize(this.node, _containerWidth.width, {
|
|
294
302
|
isFullWidthModeEnabled
|
|
295
303
|
});
|
|
304
|
+
this.resizeObserver = new ResizeObserver(entries => {
|
|
305
|
+
for (let entry of entries) {
|
|
306
|
+
this.setState(prev => {
|
|
307
|
+
var _entry$contentRect, _entry$contentRect2;
|
|
308
|
+
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 : {
|
|
309
|
+
...prev,
|
|
310
|
+
tableWrapperWidth: entry.contentRect.width,
|
|
311
|
+
tableWrapperHeight: entry.contentRect.height
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
});
|
|
296
316
|
|
|
297
317
|
// Disable inline table editing and resizing controls in Firefox
|
|
298
318
|
// https://github.com/ProseMirror/prosemirror/issues/432
|
|
@@ -351,10 +371,13 @@ class TableComponent extends React.Component {
|
|
|
351
371
|
this.onStickyState(currentStickyState);
|
|
352
372
|
}
|
|
353
373
|
eventDispatcher.on(stickyHeadersPluginKey.key, this.onStickyState);
|
|
354
|
-
|
|
355
|
-
|
|
374
|
+
if (isOverflowAnalyticsEnabled) {
|
|
375
|
+
const initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
376
|
+
this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
|
|
377
|
+
}
|
|
356
378
|
}
|
|
357
379
|
componentWillUnmount() {
|
|
380
|
+
var _this$resizeObserver;
|
|
358
381
|
const {
|
|
359
382
|
allowColumnResizing,
|
|
360
383
|
eventDispatcher,
|
|
@@ -368,6 +391,7 @@ class TableComponent extends React.Component {
|
|
|
368
391
|
if (isDragAndDropEnabled && this.dragAndDropCleanupFn) {
|
|
369
392
|
this.dragAndDropCleanupFn();
|
|
370
393
|
}
|
|
394
|
+
(_this$resizeObserver = this.resizeObserver) === null || _this$resizeObserver === void 0 ? void 0 : _this$resizeObserver.disconnect();
|
|
371
395
|
const {
|
|
372
396
|
stickyScrollbar
|
|
373
397
|
} = getEditorFeatureFlags();
|
|
@@ -418,9 +442,7 @@ class TableComponent extends React.Component {
|
|
|
418
442
|
if (depth !== 0) {
|
|
419
443
|
return;
|
|
420
444
|
}
|
|
421
|
-
const
|
|
422
|
-
width: tableNodeWidth
|
|
423
|
-
} = tableNode.attrs;
|
|
445
|
+
const tableNodeWidth = getTableContainerWidth(tableNode);
|
|
424
446
|
const shouldTableScale = tableRenderWidth < tableNodeWidth;
|
|
425
447
|
const {
|
|
426
448
|
width: containerWidthValue
|
|
@@ -436,7 +458,11 @@ class TableComponent extends React.Component {
|
|
|
436
458
|
domAtPos: view.domAtPos,
|
|
437
459
|
isTableScalingEnabled: true
|
|
438
460
|
});
|
|
439
|
-
|
|
461
|
+
|
|
462
|
+
// Request animation frame required for Firefox
|
|
463
|
+
requestAnimationFrame(() => {
|
|
464
|
+
updateColgroup(resizeState, this.table, tableNode, true);
|
|
465
|
+
});
|
|
440
466
|
}
|
|
441
467
|
this.containerWidth = containerWidth;
|
|
442
468
|
}
|
|
@@ -500,29 +526,37 @@ class TableComponent extends React.Component {
|
|
|
500
526
|
}
|
|
501
527
|
this.handleTableResizingDebounced();
|
|
502
528
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
this.
|
|
529
|
+
if (isOverflowAnalyticsEnabled) {
|
|
530
|
+
const newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
531
|
+
const prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
|
|
532
|
+
if (this.initialOverflowCaptureTimerId) {
|
|
533
|
+
clearTimeout(this.initialOverflowCaptureTimerId);
|
|
534
|
+
}
|
|
535
|
+
if (!this.isInitialOverflowSent) {
|
|
536
|
+
this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
|
|
537
|
+
}
|
|
538
|
+
if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
|
|
539
|
+
var _this$state2;
|
|
540
|
+
const {
|
|
541
|
+
dispatch,
|
|
542
|
+
state: {
|
|
543
|
+
tr
|
|
544
|
+
}
|
|
545
|
+
} = this.props.view;
|
|
546
|
+
dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
|
|
547
|
+
isOverflowing: newIsOverflowing,
|
|
548
|
+
wasOverflowing: prevIsOverflowing,
|
|
549
|
+
editorWidth: this.props.containerWidth.width || 0,
|
|
550
|
+
width: this.node.attrs.width || 0,
|
|
551
|
+
parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
|
|
552
|
+
}));
|
|
553
|
+
}
|
|
510
554
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
tr
|
|
517
|
-
}
|
|
518
|
-
} = this.props.view;
|
|
519
|
-
dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
|
|
520
|
-
isOverflowing: newIsOverflowing,
|
|
521
|
-
wasOverflowing: prevIsOverflowing,
|
|
522
|
-
editorWidth: this.props.containerWidth.width || 0,
|
|
523
|
-
width: this.node.attrs.width || 0,
|
|
524
|
-
parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
|
|
525
|
-
}));
|
|
555
|
+
}
|
|
556
|
+
observeTable(table) {
|
|
557
|
+
if (table) {
|
|
558
|
+
var _this$resizeObserver2;
|
|
559
|
+
(_this$resizeObserver2 = this.resizeObserver) === null || _this$resizeObserver2 === void 0 ? void 0 : _this$resizeObserver2.observe(table);
|
|
526
560
|
}
|
|
527
561
|
}
|
|
528
562
|
render() {
|
|
@@ -578,7 +612,8 @@ class TableComponent extends React.Component {
|
|
|
578
612
|
,
|
|
579
613
|
selection: view.state.selection,
|
|
580
614
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
581
|
-
stickyHeader: this.state.stickyHeader
|
|
615
|
+
stickyHeader: this.state.stickyHeader,
|
|
616
|
+
tableWrapperWidth: this.state.tableWrapperWidth
|
|
582
617
|
});
|
|
583
618
|
const tableContainerWidth = getTableContainerWidth(node);
|
|
584
619
|
const colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
|
|
@@ -604,7 +639,8 @@ class TableComponent extends React.Component {
|
|
|
604
639
|
getScrollOffset: () => {
|
|
605
640
|
var _this$wrapper2;
|
|
606
641
|
return ((_this$wrapper2 = this.wrapper) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.scrollLeft) || 0;
|
|
607
|
-
}
|
|
642
|
+
},
|
|
643
|
+
tableWrapperHeight: this.state.tableWrapperHeight
|
|
608
644
|
}) : null;
|
|
609
645
|
const shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
|
|
610
646
|
const shadowStyle = memoizeOne(visible => ({
|
|
@@ -642,6 +678,7 @@ class TableComponent extends React.Component {
|
|
|
642
678
|
isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
|
|
643
679
|
isNested: isNested,
|
|
644
680
|
pluginInjectionApi: pluginInjectionApi,
|
|
681
|
+
tableWrapperHeight: this.state.tableWrapperHeight,
|
|
645
682
|
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
|
|
646
683
|
isResizing: isResizing,
|
|
647
684
|
isTableScalingEnabled: isTableScalingEnabled
|
|
@@ -682,6 +719,7 @@ class TableComponent extends React.Component {
|
|
|
682
719
|
if (tableElement !== this.table) {
|
|
683
720
|
this.table = tableElement;
|
|
684
721
|
this.createShadowSentinels(this.table);
|
|
722
|
+
this.observeTable(this.table);
|
|
685
723
|
}
|
|
686
724
|
}
|
|
687
725
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef, useCallback, useRef } from 'react';
|
|
1
|
+
import React, { forwardRef, useCallback, useRef, useState } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
4
4
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
@@ -42,10 +42,12 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
42
42
|
tableRef,
|
|
43
43
|
isResizing,
|
|
44
44
|
pluginInjectionApi,
|
|
45
|
-
isTableScalingEnabled
|
|
45
|
+
isTableScalingEnabled,
|
|
46
|
+
tableWrapperHeight
|
|
46
47
|
}) => {
|
|
47
48
|
const containerRef = useRef(null);
|
|
48
49
|
const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
|
|
50
|
+
const [resizing, setIsResizing] = useState(false);
|
|
49
51
|
const updateContainerHeight = useCallback(height => {
|
|
50
52
|
var _containerRef$current;
|
|
51
53
|
// current StickyHeader State is not stable to be fetch.
|
|
@@ -53,31 +55,24 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
53
55
|
// consistently fetch and refactor below
|
|
54
56
|
const stickyHeaders = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getElementsByClassName('pm-table-sticky');
|
|
55
57
|
if (!stickyHeaders || stickyHeaders.length < 1) {
|
|
56
|
-
var _containerRef$current2;
|
|
57
58
|
// when starting to drag, we need to keep the original space,
|
|
58
59
|
// -- When sticky header not appear, margin top(24px) and margin bottom(16px), should be 40px,
|
|
59
60
|
// 1px is border width but collapse make it 0.5.
|
|
60
61
|
// -- When sticky header appear, we should add first row height but reduce
|
|
61
62
|
// collapsed border
|
|
62
|
-
|
|
63
|
+
return typeof height === 'number' ? `${height + 40.5}px` : 'auto';
|
|
63
64
|
} else {
|
|
64
|
-
var _containerRef$
|
|
65
|
-
const stickyHeaderHeight = ((_containerRef$
|
|
66
|
-
|
|
65
|
+
var _containerRef$current2;
|
|
66
|
+
const stickyHeaderHeight = ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.getElementsByTagName('th')[0].getBoundingClientRect().height) || 0;
|
|
67
|
+
return typeof height === 'number' ? `${height + stickyHeaderHeight + 39.5}px` : 'auto';
|
|
67
68
|
}
|
|
68
69
|
}, []);
|
|
69
|
-
const resizeObserverRef = useRef(new ResizeObserver(entries => {
|
|
70
|
-
updateContainerHeight(entries[entries.length - 1].contentRect.height);
|
|
71
|
-
}));
|
|
72
70
|
const onResizeStart = useCallback(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}, [tableRef]);
|
|
71
|
+
setIsResizing(true);
|
|
72
|
+
}, []);
|
|
77
73
|
const onResizeStop = useCallback(() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}, [updateContainerHeight]);
|
|
74
|
+
setIsResizing(false);
|
|
75
|
+
}, []);
|
|
81
76
|
const updateWidth = useCallback(width => {
|
|
82
77
|
if (!containerRef.current) {
|
|
83
78
|
return;
|
|
@@ -141,7 +136,8 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
|
|
|
141
136
|
}
|
|
142
137
|
}, /*#__PURE__*/React.createElement("div", {
|
|
143
138
|
style: {
|
|
144
|
-
width: tableWidthRef.current
|
|
139
|
+
width: tableWidthRef.current,
|
|
140
|
+
height: resizing ? updateContainerHeight(tableWrapperHeight !== null && tableWrapperHeight !== void 0 ? tableWrapperHeight : 'auto') : 'auto'
|
|
145
141
|
},
|
|
146
142
|
className: ClassName.TABLE_RESIZER_CONTAINER,
|
|
147
143
|
ref: containerRef
|
|
@@ -164,6 +160,7 @@ export const TableContainer = ({
|
|
|
164
160
|
getPos,
|
|
165
161
|
tableRef,
|
|
166
162
|
isNested,
|
|
163
|
+
tableWrapperHeight,
|
|
167
164
|
isResizing,
|
|
168
165
|
pluginInjectionApi,
|
|
169
166
|
isTableScalingEnabled
|
|
@@ -176,6 +173,7 @@ export const TableContainer = ({
|
|
|
176
173
|
editorView: editorView,
|
|
177
174
|
getPos: getPos,
|
|
178
175
|
tableRef: tableRef,
|
|
176
|
+
tableWrapperHeight: tableWrapperHeight,
|
|
179
177
|
isResizing: isResizing,
|
|
180
178
|
pluginInjectionApi: pluginInjectionApi,
|
|
181
179
|
isTableScalingEnabled: isTableScalingEnabled
|
|
@@ -51,7 +51,7 @@ const getResizerHandleHeight = tableRef => {
|
|
|
51
51
|
};
|
|
52
52
|
const getResizerMinWidth = node => {
|
|
53
53
|
const currentColumnCount = getColgroupChildrenLength(node);
|
|
54
|
-
const minColumnWidth =
|
|
54
|
+
const minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
|
|
55
55
|
// add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
|
|
56
56
|
// the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
|
|
57
57
|
return minColumnWidth + 1;
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -49,11 +49,10 @@ const tablesPlugin = ({
|
|
|
49
49
|
current: null
|
|
50
50
|
};
|
|
51
51
|
const defaultGetEditorContainerWidth = () => {
|
|
52
|
-
var
|
|
53
|
-
|
|
52
|
+
var _api$width$sharedStat, _api$width, _document$body$offset, _document, _document$body;
|
|
53
|
+
return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : {
|
|
54
54
|
width: (_document$body$offset = (_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.offsetWidth) !== null && _document$body$offset !== void 0 ? _document$body$offset : 500
|
|
55
55
|
};
|
|
56
|
-
return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
|
|
57
56
|
};
|
|
58
57
|
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
59
58
|
return {
|
|
@@ -23,7 +23,6 @@ import { defaultHoveredCell, defaultTableSelection } from './default-table-selec
|
|
|
23
23
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
24
24
|
import { pluginKey } from './plugin-key';
|
|
25
25
|
export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled) => {
|
|
26
|
-
var _window;
|
|
27
26
|
const state = createPluginState(dispatch, {
|
|
28
27
|
pluginConfig,
|
|
29
28
|
isTableHovered: false,
|
|
@@ -41,15 +40,6 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
41
40
|
...defaultTableSelection,
|
|
42
41
|
getIntl
|
|
43
42
|
});
|
|
44
|
-
let elementContentRects = {};
|
|
45
|
-
const observer = (_window = window) !== null && _window !== void 0 && _window.ResizeObserver ? new ResizeObserver(entries => {
|
|
46
|
-
entries.forEach(entry => {
|
|
47
|
-
if (!entry.target.id) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
elementContentRects[entry.target.id] = entry.contentRect;
|
|
51
|
-
});
|
|
52
|
-
}) : undefined;
|
|
53
43
|
|
|
54
44
|
// Used to prevent invalid table cell spans being reported more than once per editor/document
|
|
55
45
|
const invalidTableIds = [];
|
|
@@ -151,11 +141,6 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
151
141
|
} else if (pluginState.isResizeHandleWidgetAdded) {
|
|
152
142
|
removeResizeHandleDecorations()(state, dispatch);
|
|
153
143
|
}
|
|
154
|
-
},
|
|
155
|
-
destroy: () => {
|
|
156
|
-
if (observer) {
|
|
157
|
-
observer.disconnect();
|
|
158
|
-
}
|
|
159
144
|
}
|
|
160
145
|
};
|
|
161
146
|
},
|
|
@@ -264,8 +249,8 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
264
249
|
nodeViews: {
|
|
265
250
|
table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi),
|
|
266
251
|
tableRow: (node, view, getPos) => new TableRow(node, view, getPos, eventDispatcher),
|
|
267
|
-
tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher
|
|
268
|
-
tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher
|
|
252
|
+
tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher),
|
|
253
|
+
tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher)
|
|
269
254
|
},
|
|
270
255
|
handleDOMEvents: {
|
|
271
256
|
focus: handleFocus,
|
|
@@ -274,7 +259,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
274
259
|
mouseover: withCellTracking(whenTableInFocus(handleMouseOver)),
|
|
275
260
|
mouseleave: handleMouseLeave,
|
|
276
261
|
mouseout: whenTableInFocus(handleMouseOut),
|
|
277
|
-
mousemove: whenTableInFocus(handleMouseMove
|
|
262
|
+
mousemove: whenTableInFocus(handleMouseMove),
|
|
278
263
|
mouseenter: handleMouseEnter,
|
|
279
264
|
mouseup: whenTableInFocus(handleMouseUp),
|
|
280
265
|
click: withCellTracking(whenTableInFocus(handleClick))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -3,7 +3,7 @@ import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
|
3
3
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
5
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import {
|
|
6
|
+
import { getTableScalingPercent } from './misc';
|
|
7
7
|
/**
|
|
8
8
|
* This ensures the combined width of the columns (and tbody) of table is always smaller or equal
|
|
9
9
|
* than the table and table wrapper elements. This is necessary as there is no longer
|
|
@@ -21,14 +21,10 @@ export const generateColgroup = (table, tableRef) => {
|
|
|
21
21
|
// We slice here to guard against our colwidth array having more entries
|
|
22
22
|
// Than the we actually span. We'll patch the document at a later point.
|
|
23
23
|
if (tableRef) {
|
|
24
|
-
|
|
25
|
-
const tableWidth = table.attrs && table.attrs.width;
|
|
26
|
-
let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 760;
|
|
27
|
-
let scalePercent = renderWidth / tableWidth;
|
|
28
|
-
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
24
|
+
const scalePercent = getTableScalingPercent(table, tableRef);
|
|
29
25
|
cell.attrs.colwidth.slice(0, colspan).forEach(width => {
|
|
30
26
|
const fixedColWidth = getColWidthFix(width, map.width);
|
|
31
|
-
const scaledWidth = fixedColWidth *
|
|
27
|
+
const scaledWidth = fixedColWidth * scalePercent;
|
|
32
28
|
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
33
29
|
cols.push(['col', {
|
|
34
30
|
style: `width: ${finalWidth}px;`
|
|
@@ -5,6 +5,7 @@ import { calcTableColumnWidths, containsClassName } from '@atlaskit/editor-commo
|
|
|
5
5
|
import { akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { hasTableBeenResized } from './colgroup';
|
|
8
|
+
import { MAX_SCALING_PERCENT } from './consts';
|
|
8
9
|
|
|
9
10
|
// Translates named layouts in number values.
|
|
10
11
|
export function getLayoutSize(tableLayout, containerWidth = 0, options) {
|
|
@@ -89,4 +90,13 @@ export const getTableElementWidth = table => {
|
|
|
89
90
|
};
|
|
90
91
|
export const getTableContainerElementWidth = table => {
|
|
91
92
|
return getTableContainerWidth(table);
|
|
93
|
+
};
|
|
94
|
+
export const getTableScalingPercent = (table, tableRef) => {
|
|
95
|
+
var _tableRef$parentEleme;
|
|
96
|
+
const tableWidth = getTableContainerElementWidth(table);
|
|
97
|
+
let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || tableWidth;
|
|
98
|
+
// minus 1 here to avoid any 1px scroll in Firefox
|
|
99
|
+
let scalePercent = (renderWidth - 1) / tableWidth;
|
|
100
|
+
scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
|
|
101
|
+
return Math.min(scalePercent, 1);
|
|
92
102
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
1
2
|
import { tableCellMinWidth, tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
3
|
import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -5,8 +6,7 @@ import { getSelectedTableInfo } from '../../../utils';
|
|
|
5
6
|
import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
6
7
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
7
8
|
import { syncStickyRowToTable } from './dom';
|
|
8
|
-
import {
|
|
9
|
-
import { COLUMN_MIN_WIDTH, MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
9
|
+
import { getTableMaxWidth, getTableScalingPercent } from './misc';
|
|
10
10
|
export const getResizeState = ({
|
|
11
11
|
minWidth,
|
|
12
12
|
maxSize,
|
|
@@ -16,6 +16,10 @@ export const getResizeState = ({
|
|
|
16
16
|
domAtPos,
|
|
17
17
|
isTableScalingEnabled = false
|
|
18
18
|
}) => {
|
|
19
|
+
if (isTableScalingEnabled) {
|
|
20
|
+
const scalePercent = getTableScalingPercent(table, tableRef);
|
|
21
|
+
minWidth = Math.ceil(minWidth / scalePercent);
|
|
22
|
+
}
|
|
19
23
|
// If the table has been resized, we can use the column widths from the table node
|
|
20
24
|
if (hasTableBeenResized(table)) {
|
|
21
25
|
const cols = calcTableColumnWidths(table).map((width, index) => ({
|
|
@@ -42,11 +46,12 @@ export const getResizeState = ({
|
|
|
42
46
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
43
47
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
44
48
|
// to calculate the widths of the columns
|
|
45
|
-
if (isTableScalingEnabled
|
|
49
|
+
if (isTableScalingEnabled) {
|
|
50
|
+
const tableNodeWidth = getTableContainerWidth(table);
|
|
46
51
|
return {
|
|
47
52
|
index,
|
|
48
|
-
width:
|
|
49
|
-
minWidth
|
|
53
|
+
width: tableNodeWidth / colgroupChildren.length,
|
|
54
|
+
minWidth
|
|
50
55
|
};
|
|
51
56
|
}
|
|
52
57
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
@@ -70,23 +75,17 @@ export const updateColgroup = (state, tableRef, tableNode, isTableScalingEnabled
|
|
|
70
75
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
71
76
|
const columnsCount = cols.length;
|
|
72
77
|
if (isTableScalingEnabled && tableNode) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
85
|
-
if (cols[i]) {
|
|
86
|
-
cols[i].style.width = `${finalWidth}px`;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
78
|
+
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
79
|
+
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
80
|
+
.forEach((column, i) => {
|
|
81
|
+
const fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
82
|
+
const scaledWidth = fixedColWidth * scalePercent;
|
|
83
|
+
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
84
|
+
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
85
|
+
if (cols[i]) {
|
|
86
|
+
cols[i].style.width = `${finalWidth}px`;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
90
89
|
} else {
|
|
91
90
|
state.cols.filter(column => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
92
91
|
.forEach((column, i) => {
|
|
@@ -126,9 +126,9 @@ export const previewScaleTable = (tableRef, options, domAtPos, isTableScalingEna
|
|
|
126
126
|
syncStickyRowToTable(tableRef);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos,
|
|
129
|
+
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) : scale(tableRef, options, domAtPos, false);
|
|
130
130
|
if (resizeState) {
|
|
131
|
-
updateColgroup(resizeState, tableRef, node,
|
|
131
|
+
updateColgroup(resizeState, tableRef, node, false);
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { bindKeymapArrayWithCommand, bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapArrayWithCommand, bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, selectTable, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
3
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
|
-
import { arrowLeftFromTable, arrowRightFromTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
|
|
4
|
+
import { arrowLeftFromTable, arrowRightFromTable, modASelectTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
|
|
5
5
|
export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
6
6
|
const list = {};
|
|
7
7
|
bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
|
|
@@ -13,6 +13,9 @@ export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
|
13
13
|
if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
|
|
14
14
|
bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
|
|
15
15
|
}
|
|
16
|
+
if (getBooleanFF('platform.editor.table.cmd-a-select-table')) {
|
|
17
|
+
bindKeymapWithCommand(selectTable.common, modASelectTable(editorSelectionAPI)(), list);
|
|
18
|
+
}
|
|
16
19
|
return keymap(list);
|
|
17
20
|
}
|
|
18
21
|
export default tableSelectionKeymapPlugin;
|
|
@@ -18,37 +18,15 @@ export const TableFloatingColumnControls = ({
|
|
|
18
18
|
isTableHovered,
|
|
19
19
|
tableContainerWidth,
|
|
20
20
|
isNumberColumnEnabled,
|
|
21
|
-
getScrollOffset
|
|
21
|
+
getScrollOffset,
|
|
22
|
+
tableWrapperHeight
|
|
22
23
|
}) => {
|
|
23
|
-
const [tableRect, setTableRect] = useState({
|
|
24
|
-
width: 0,
|
|
25
|
-
height: 0
|
|
26
|
-
});
|
|
27
24
|
const [isDragging, setIsDragging] = useState(false);
|
|
28
25
|
const containerRef = useRef(null);
|
|
29
26
|
const node = getNode();
|
|
30
27
|
const currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
|
|
31
28
|
const hasHeaderColumn = containsHeaderColumn(node);
|
|
32
29
|
const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
var _window;
|
|
35
|
-
if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
|
36
|
-
const resizeObserver = new ResizeObserver(entries => {
|
|
37
|
-
for (let entry of entries) {
|
|
38
|
-
setTableRect(prev => {
|
|
39
|
-
if (prev.width !== entry.contentRect.width || prev.height !== entry.contentRect.height) {
|
|
40
|
-
return entry.contentRect;
|
|
41
|
-
}
|
|
42
|
-
return prev;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
resizeObserver.observe(tableRef);
|
|
47
|
-
return () => {
|
|
48
|
-
resizeObserver.disconnect();
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}, [tableRef]);
|
|
52
30
|
useEffect(() => {
|
|
53
31
|
return monitorForElements({
|
|
54
32
|
canMonitor({
|
|
@@ -71,11 +49,11 @@ export const TableFloatingColumnControls = ({
|
|
|
71
49
|
}, [editorView, currentNodeLocalId]);
|
|
72
50
|
const rowHeights = useMemo(() => {
|
|
73
51
|
// NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
|
|
74
|
-
if (tableRef && !!
|
|
52
|
+
if (tableRef && !!tableWrapperHeight) {
|
|
75
53
|
return getRowHeights(tableRef);
|
|
76
54
|
}
|
|
77
55
|
return [0];
|
|
78
|
-
}, [tableRef,
|
|
56
|
+
}, [tableRef, tableWrapperHeight]);
|
|
79
57
|
if (!tableRef || !tableActive || isResizing) {
|
|
80
58
|
return null;
|
|
81
59
|
}
|
|
@@ -112,7 +90,7 @@ export const TableFloatingColumnControls = ({
|
|
|
112
90
|
}), isDragging && /*#__PURE__*/React.createElement(ColumnDropTargets, {
|
|
113
91
|
tableRef: tableRef,
|
|
114
92
|
isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
|
|
115
|
-
tableHeight:
|
|
93
|
+
tableHeight: tableWrapperHeight,
|
|
116
94
|
localId: currentNodeLocalId,
|
|
117
95
|
colWidths: colWidths,
|
|
118
96
|
getScrollOffset: getScrollOffset
|