@atlaskit/editor-plugin-table 1.5.5 → 1.6.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 +10 -0
- package/dist/cjs/plugins/table/index.js +12 -11
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +37 -78
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +131 -0
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +65 -0
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/commands.js +4 -49
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/index.js +0 -7
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/index.js +12 -6
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +3 -11
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/index.js +12 -11
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +17 -64
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +124 -0
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +56 -0
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/commands.js +2 -48
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/index.js +0 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/index.js +12 -11
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +39 -81
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +119 -0
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +57 -0
- package/dist/esm/plugins/table/pm-plugins/table-resizing/commands.js +4 -48
- package/dist/esm/plugins/table/pm-plugins/table-resizing/index.js +0 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +59 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +0 -3
- package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +35 -0
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +13 -0
- package/dist/types/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
- package/dist/types/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -3
- package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +35 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +13 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/package.json +3 -3
- package/src/__tests__/integration/sticky-header.ts +4 -1
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +164 -0
- package/src/plugins/table/index.tsx +21 -18
- package/src/plugins/table/nodeviews/TableComponent.tsx +21 -78
- package/src/plugins/table/nodeviews/TableContainer.tsx +200 -0
- package/src/plugins/table/nodeviews/TableResizer.tsx +88 -0
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +3 -72
- package/src/plugins/table/pm-plugins/table-resizing/index.ts +0 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/index.ts +6 -2
- package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +7 -12
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +79 -0
|
@@ -5,21 +5,16 @@ import { isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
|
5
5
|
import { EditorView } from 'prosemirror-view';
|
|
6
6
|
import rafSchedule from 'raf-schd';
|
|
7
7
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
8
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
9
8
|
|
|
10
|
-
import {
|
|
11
|
-
calcTableWidth,
|
|
12
|
-
tableMarginSides,
|
|
13
|
-
} from '@atlaskit/editor-common/styles';
|
|
9
|
+
import { tableMarginSides } from '@atlaskit/editor-common/styles';
|
|
14
10
|
import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
|
|
15
11
|
import {
|
|
16
12
|
akEditorMobileBreakoutPoint,
|
|
17
13
|
akEditorTableToolbarSize as tableToolbarSize,
|
|
18
14
|
} from '@atlaskit/editor-shared-styles';
|
|
19
15
|
|
|
20
|
-
import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
|
|
21
16
|
import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
22
|
-
import {
|
|
17
|
+
import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
|
|
23
18
|
|
|
24
19
|
import { autoSizeTable, clearHoverSelection } from '../commands';
|
|
25
20
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
@@ -29,10 +24,10 @@ import {
|
|
|
29
24
|
pluginKey as stickyHeadersPluginKey,
|
|
30
25
|
StickyPluginState,
|
|
31
26
|
} from '../pm-plugins/sticky-headers';
|
|
32
|
-
import { scaleTable } from '../pm-plugins/table-resizing';
|
|
33
27
|
import {
|
|
34
28
|
getLayoutSize,
|
|
35
29
|
insertColgroupFromNode as recreateResizeColsByNode,
|
|
30
|
+
scaleTable,
|
|
36
31
|
} from '../pm-plugins/table-resizing/utils';
|
|
37
32
|
import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
|
|
38
33
|
|
|
@@ -56,6 +51,7 @@ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
|
56
51
|
|
|
57
52
|
import memoizeOne from 'memoize-one';
|
|
58
53
|
import { OverflowShadowsObserver } from './OverflowShadowsObserver';
|
|
54
|
+
import { TableContainer } from './TableContainer';
|
|
59
55
|
|
|
60
56
|
const isIE11 = browser.ie_version === 11;
|
|
61
57
|
const NOOP = () => undefined;
|
|
@@ -81,7 +77,6 @@ export interface ComponentProps {
|
|
|
81
77
|
|
|
82
78
|
interface TableState {
|
|
83
79
|
scroll: number;
|
|
84
|
-
tableContainerWidth: string;
|
|
85
80
|
parentWidth?: number;
|
|
86
81
|
isLoading: boolean;
|
|
87
82
|
stickyHeader?: RowStickyState;
|
|
@@ -93,7 +88,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
93
88
|
|
|
94
89
|
state: TableState = {
|
|
95
90
|
scroll: 0,
|
|
96
|
-
tableContainerWidth: 'inherit',
|
|
97
91
|
parentWidth: undefined,
|
|
98
92
|
isLoading: true,
|
|
99
93
|
[ShadowEvent.SHOW_BEFORE_SHADOW]: false,
|
|
@@ -157,7 +151,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
157
151
|
* Instead we use the resize event to only trigger updates when necessary.
|
|
158
152
|
*/
|
|
159
153
|
window.addEventListener('resize', this.handleWindowResizeDebounced);
|
|
160
|
-
this.updateTableContainerWidth();
|
|
161
154
|
this.handleTableResizingDebounced();
|
|
162
155
|
}
|
|
163
156
|
|
|
@@ -324,13 +317,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
324
317
|
isHeaderColumnEnabled,
|
|
325
318
|
tableActive,
|
|
326
319
|
containerWidth,
|
|
320
|
+
options,
|
|
321
|
+
getPos,
|
|
327
322
|
} = this.props;
|
|
328
|
-
const {
|
|
329
|
-
isLoading,
|
|
330
|
-
tableContainerWidth,
|
|
331
|
-
showBeforeShadow,
|
|
332
|
-
showAfterShadow,
|
|
333
|
-
} = this.state;
|
|
323
|
+
const { isLoading, showBeforeShadow, showAfterShadow } = this.state;
|
|
334
324
|
const node = getNode();
|
|
335
325
|
// doesn't work well with WithPluginState
|
|
336
326
|
const { isInDanger, hoveredRows } = getPluginState(view.state);
|
|
@@ -390,17 +380,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
390
380
|
)
|
|
391
381
|
: NOOP;
|
|
392
382
|
|
|
393
|
-
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
394
|
-
// new table experience code goes here
|
|
395
|
-
// return <Resizer>...
|
|
396
|
-
}
|
|
397
|
-
|
|
398
383
|
return (
|
|
399
|
-
<
|
|
400
|
-
style={{
|
|
401
|
-
width: tableContainerWidth,
|
|
402
|
-
marginLeft: this.getMarginLeft(tableContainerWidth),
|
|
403
|
-
}}
|
|
384
|
+
<TableContainer
|
|
404
385
|
className={classnames(ClassName.TABLE_CONTAINER, {
|
|
405
386
|
[ClassName.WITH_CONTROLS]: allowControls && tableActive,
|
|
406
387
|
[ClassName.TABLE_STICKY]: this.state.stickyHeader && hasHeaderRow,
|
|
@@ -408,8 +389,13 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
408
389
|
[ClassName.TABLE_SELECTED]: isTableSelected(view.state.selection),
|
|
409
390
|
'less-padding': containerWidth.width < akEditorMobileBreakoutPoint,
|
|
410
391
|
})}
|
|
411
|
-
|
|
412
|
-
|
|
392
|
+
editorView={view}
|
|
393
|
+
getPos={getPos}
|
|
394
|
+
node={node}
|
|
395
|
+
tableRef={tableRef!}
|
|
396
|
+
containerWidth={containerWidth}
|
|
397
|
+
isFullWidthModeEnabled={options?.isFullWidthModeEnabled}
|
|
398
|
+
isBreakoutEnabled={options?.isBreakoutEnabled}
|
|
413
399
|
>
|
|
414
400
|
{stickyHeadersOptimization && (
|
|
415
401
|
<div
|
|
@@ -492,24 +478,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
492
478
|
data-testid="sticky-sentinel-bottom"
|
|
493
479
|
/>
|
|
494
480
|
)}
|
|
495
|
-
</
|
|
481
|
+
</TableContainer>
|
|
496
482
|
);
|
|
497
483
|
}
|
|
498
484
|
|
|
499
|
-
private getMarginLeft = (tableContainerCssWidth: string) => {
|
|
500
|
-
const { containerWidth } = this.props;
|
|
501
|
-
const { lineLength } = containerWidth;
|
|
502
|
-
let marginLeft;
|
|
503
|
-
if (tableContainerCssWidth !== 'inherit' && lineLength) {
|
|
504
|
-
const containerWidth = parsePx(tableContainerCssWidth);
|
|
505
|
-
|
|
506
|
-
if (containerWidth) {
|
|
507
|
-
marginLeft = (lineLength - containerWidth) / 2;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
return marginLeft;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
485
|
private handleScroll = (event: Event) => {
|
|
514
486
|
if (!this.wrapper || event.target !== this.wrapper) {
|
|
515
487
|
return;
|
|
@@ -584,7 +556,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
584
556
|
this.updateParentWidth(parentWidth);
|
|
585
557
|
}
|
|
586
558
|
|
|
587
|
-
this.updateTableContainerWidth();
|
|
588
559
|
this.node = node;
|
|
589
560
|
this.containerWidth = containerWidth;
|
|
590
561
|
this.layoutSize = layoutSize;
|
|
@@ -598,6 +569,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
598
569
|
const node = getNode();
|
|
599
570
|
const { state, dispatch } = view;
|
|
600
571
|
const pos = getPos();
|
|
572
|
+
|
|
601
573
|
if (!isValidPosition(pos, state)) {
|
|
602
574
|
return;
|
|
603
575
|
}
|
|
@@ -606,7 +578,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
606
578
|
|
|
607
579
|
this.scaleTableDebounced.cancel();
|
|
608
580
|
|
|
609
|
-
scaleTable(
|
|
581
|
+
const tr = scaleTable(
|
|
610
582
|
this.table,
|
|
611
583
|
{
|
|
612
584
|
...scaleOptions,
|
|
@@ -618,7 +590,9 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
618
590
|
...options,
|
|
619
591
|
},
|
|
620
592
|
domAtPos,
|
|
621
|
-
)(state
|
|
593
|
+
)(state.tr);
|
|
594
|
+
|
|
595
|
+
dispatch(tr);
|
|
622
596
|
};
|
|
623
597
|
|
|
624
598
|
private handleAutoSize = () => {
|
|
@@ -656,36 +630,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
656
630
|
});
|
|
657
631
|
};
|
|
658
632
|
|
|
659
|
-
private updateTableContainerWidth = () => {
|
|
660
|
-
const { getNode, containerWidth, options } = this.props;
|
|
661
|
-
const node = getNode();
|
|
662
|
-
if (options && options.isBreakoutEnabled === false) {
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
const tableContainerWidth = calcTableWidth(
|
|
666
|
-
node.attrs.layout,
|
|
667
|
-
containerWidth.width,
|
|
668
|
-
);
|
|
669
|
-
|
|
670
|
-
if (this.state.tableContainerWidth === tableContainerWidth) {
|
|
671
|
-
return null;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
this.setState((prevState: TableState) => {
|
|
675
|
-
if (
|
|
676
|
-
options &&
|
|
677
|
-
options.isBreakoutEnabled === false &&
|
|
678
|
-
prevState.tableContainerWidth !== 'inherit'
|
|
679
|
-
) {
|
|
680
|
-
return { tableContainerWidth: 'inherit' };
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
return {
|
|
684
|
-
tableContainerWidth,
|
|
685
|
-
};
|
|
686
|
-
});
|
|
687
|
-
};
|
|
688
|
-
|
|
689
633
|
private getParentNodeWidth = () => {
|
|
690
634
|
const {
|
|
691
635
|
getPos,
|
|
@@ -697,7 +641,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
697
641
|
if (!isValidPosition(pos, state)) {
|
|
698
642
|
return;
|
|
699
643
|
}
|
|
700
|
-
|
|
701
644
|
const parentNodeWith = getParentNodeWidth(
|
|
702
645
|
pos,
|
|
703
646
|
state,
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
PropsWithChildren,
|
|
3
|
+
useCallback,
|
|
4
|
+
useRef,
|
|
5
|
+
forwardRef,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import { Node as PMNode } from 'prosemirror-model';
|
|
8
|
+
import { EditorView } from 'prosemirror-view';
|
|
9
|
+
|
|
10
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
11
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
12
|
+
import { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
13
|
+
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
14
|
+
|
|
15
|
+
import { TableCssClassName as ClassName } from '../types';
|
|
16
|
+
import { TableResizer } from './TableResizer';
|
|
17
|
+
|
|
18
|
+
interface GetMarginLeftOpts {
|
|
19
|
+
lineLength: number;
|
|
20
|
+
tableWidth: number | 'inherit';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const getMarginLeft = ({ lineLength, tableWidth }: GetMarginLeftOpts) => {
|
|
24
|
+
let marginLeft;
|
|
25
|
+
if (tableWidth !== 'inherit' && lineLength) {
|
|
26
|
+
const containerWidth = tableWidth;
|
|
27
|
+
|
|
28
|
+
if (containerWidth) {
|
|
29
|
+
marginLeft = (lineLength - containerWidth) / 2;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return marginLeft;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type InnerContainerProps = {
|
|
37
|
+
className: string;
|
|
38
|
+
marginLeft: number | undefined;
|
|
39
|
+
width: number | 'inherit';
|
|
40
|
+
node: PMNode;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const InnerContainer = forwardRef<
|
|
44
|
+
HTMLDivElement,
|
|
45
|
+
PropsWithChildren<InnerContainerProps>
|
|
46
|
+
>(({ marginLeft, className, width, node, children }, ref) => {
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
ref={ref}
|
|
50
|
+
style={{
|
|
51
|
+
width,
|
|
52
|
+
marginLeft,
|
|
53
|
+
}}
|
|
54
|
+
className={className}
|
|
55
|
+
data-number-column={node.attrs.isNumberColumnEnabled}
|
|
56
|
+
data-layout={node.attrs.layout}
|
|
57
|
+
data-test-id="table-container"
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
type ResizableTableContainerProps = {
|
|
65
|
+
containerWidth: number;
|
|
66
|
+
lineLength: number;
|
|
67
|
+
node: PMNode;
|
|
68
|
+
className: string;
|
|
69
|
+
editorView: EditorView;
|
|
70
|
+
getPos: () => number;
|
|
71
|
+
tableRef: HTMLTableElement;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const ResizableTableContainer = ({
|
|
75
|
+
children,
|
|
76
|
+
className,
|
|
77
|
+
node,
|
|
78
|
+
lineLength,
|
|
79
|
+
editorView,
|
|
80
|
+
getPos,
|
|
81
|
+
tableRef,
|
|
82
|
+
}: PropsWithChildren<ResizableTableContainerProps>) => {
|
|
83
|
+
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
84
|
+
const innerContainerRef = useRef<HTMLDivElement | null>(null);
|
|
85
|
+
|
|
86
|
+
const updateWidth = useCallback(
|
|
87
|
+
(width: number) => {
|
|
88
|
+
if (!containerRef.current || !innerContainerRef.current) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
innerContainerRef.current.style.width = `${width}px`;
|
|
93
|
+
|
|
94
|
+
const marginLeft = getMarginLeft({
|
|
95
|
+
lineLength,
|
|
96
|
+
tableWidth: width,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
containerRef.current.style.width = `${width}px`;
|
|
100
|
+
containerRef.current.style.marginLeft = `${marginLeft}px`;
|
|
101
|
+
},
|
|
102
|
+
[lineLength],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const width = getTableContainerWidth(node);
|
|
106
|
+
const marginLeft = getMarginLeft({
|
|
107
|
+
lineLength,
|
|
108
|
+
tableWidth: width,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div
|
|
113
|
+
style={{ marginLeft, width }}
|
|
114
|
+
className={ClassName.TABLE_RESIZER_CONTAINER}
|
|
115
|
+
ref={containerRef}
|
|
116
|
+
>
|
|
117
|
+
<TableResizer
|
|
118
|
+
width={width}
|
|
119
|
+
updateWidth={updateWidth}
|
|
120
|
+
editorView={editorView}
|
|
121
|
+
getPos={getPos}
|
|
122
|
+
node={node}
|
|
123
|
+
tableRef={tableRef}
|
|
124
|
+
>
|
|
125
|
+
<InnerContainer
|
|
126
|
+
ref={innerContainerRef}
|
|
127
|
+
className={className}
|
|
128
|
+
node={node}
|
|
129
|
+
width={width}
|
|
130
|
+
marginLeft={0}
|
|
131
|
+
>
|
|
132
|
+
{children}
|
|
133
|
+
</InnerContainer>
|
|
134
|
+
</TableResizer>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
type TableContainerProps = {
|
|
140
|
+
node: PMNode;
|
|
141
|
+
className: string;
|
|
142
|
+
containerWidth: EditorContainerWidth;
|
|
143
|
+
// TODO: passing through both isFullWidthModeEnabled and isBreakoutEnabled to support custom table widths and
|
|
144
|
+
// exiting breakout behaviour. In the future these values will be removed and replaced
|
|
145
|
+
// with a single table plugin option - requires changes to editor-core
|
|
146
|
+
isFullWidthModeEnabled: boolean | undefined;
|
|
147
|
+
isBreakoutEnabled: boolean | undefined;
|
|
148
|
+
editorView: EditorView;
|
|
149
|
+
getPos: () => number;
|
|
150
|
+
tableRef: HTMLTableElement;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const TableContainer = ({
|
|
154
|
+
children,
|
|
155
|
+
node,
|
|
156
|
+
className,
|
|
157
|
+
containerWidth: { lineLength, width: editorWidth },
|
|
158
|
+
isFullWidthModeEnabled,
|
|
159
|
+
isBreakoutEnabled,
|
|
160
|
+
editorView,
|
|
161
|
+
getPos,
|
|
162
|
+
tableRef,
|
|
163
|
+
}: PropsWithChildren<TableContainerProps>) => {
|
|
164
|
+
if (
|
|
165
|
+
(isFullWidthModeEnabled || isBreakoutEnabled) &&
|
|
166
|
+
getBooleanFF('platform.editor.custom-table-width')
|
|
167
|
+
) {
|
|
168
|
+
return (
|
|
169
|
+
<ResizableTableContainer
|
|
170
|
+
className={className}
|
|
171
|
+
node={node}
|
|
172
|
+
lineLength={lineLength!}
|
|
173
|
+
containerWidth={editorWidth!}
|
|
174
|
+
editorView={editorView}
|
|
175
|
+
getPos={getPos}
|
|
176
|
+
tableRef={tableRef}
|
|
177
|
+
>
|
|
178
|
+
{children}
|
|
179
|
+
</ResizableTableContainer>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const tableWidth = isBreakoutEnabled
|
|
184
|
+
? calcTableWidth(node.attrs.layout, editorWidth)
|
|
185
|
+
: 'inherit';
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<InnerContainer
|
|
189
|
+
node={node}
|
|
190
|
+
className={className}
|
|
191
|
+
width={tableWidth}
|
|
192
|
+
marginLeft={getMarginLeft({
|
|
193
|
+
lineLength: lineLength!,
|
|
194
|
+
tableWidth,
|
|
195
|
+
})}
|
|
196
|
+
>
|
|
197
|
+
{children}
|
|
198
|
+
</InnerContainer>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { EditorView } from 'prosemirror-view';
|
|
3
|
+
import { Node as PMNode } from 'prosemirror-model';
|
|
4
|
+
import rafSchd from 'raf-schd';
|
|
5
|
+
|
|
6
|
+
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
scaleTable,
|
|
10
|
+
previewScaleTable,
|
|
11
|
+
} from '../pm-plugins/table-resizing/utils';
|
|
12
|
+
|
|
13
|
+
interface TableResizerProps {
|
|
14
|
+
width: number;
|
|
15
|
+
updateWidth: (width: number) => void;
|
|
16
|
+
editorView: EditorView;
|
|
17
|
+
getPos: () => number;
|
|
18
|
+
node: PMNode;
|
|
19
|
+
tableRef: HTMLTableElement;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const handles = { right: true };
|
|
23
|
+
|
|
24
|
+
export const TableResizer = ({
|
|
25
|
+
children,
|
|
26
|
+
width,
|
|
27
|
+
updateWidth,
|
|
28
|
+
editorView,
|
|
29
|
+
getPos,
|
|
30
|
+
node,
|
|
31
|
+
tableRef,
|
|
32
|
+
}: PropsWithChildren<TableResizerProps>) => {
|
|
33
|
+
return (
|
|
34
|
+
<ResizerNext
|
|
35
|
+
enable={handles}
|
|
36
|
+
width={width}
|
|
37
|
+
handleResizeStart={() => width}
|
|
38
|
+
handleResize={rafSchd((originalState, delta) => {
|
|
39
|
+
const newWidth = originalState.width + delta.width;
|
|
40
|
+
|
|
41
|
+
previewScaleTable(
|
|
42
|
+
tableRef,
|
|
43
|
+
{
|
|
44
|
+
node,
|
|
45
|
+
prevNode: node,
|
|
46
|
+
start: getPos() + 1,
|
|
47
|
+
parentWidth: newWidth,
|
|
48
|
+
},
|
|
49
|
+
editorView.domAtPos.bind(editorView),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
updateWidth(newWidth);
|
|
53
|
+
return newWidth;
|
|
54
|
+
})}
|
|
55
|
+
handleResizeStop={(originalState, delta) => {
|
|
56
|
+
const newWidth = originalState.width + delta.width;
|
|
57
|
+
|
|
58
|
+
const { state, dispatch } = editorView;
|
|
59
|
+
const pos = getPos();
|
|
60
|
+
|
|
61
|
+
let tr = state.tr.setNodeMarkup(pos, undefined, {
|
|
62
|
+
...node.attrs,
|
|
63
|
+
width: newWidth,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const newNode = tr.doc.nodeAt(pos)!;
|
|
67
|
+
tr = scaleTable(
|
|
68
|
+
tableRef,
|
|
69
|
+
{
|
|
70
|
+
node: newNode,
|
|
71
|
+
prevNode: node,
|
|
72
|
+
start: getPos() + 1,
|
|
73
|
+
parentWidth: newWidth,
|
|
74
|
+
},
|
|
75
|
+
editorView.domAtPos.bind(editorView),
|
|
76
|
+
)(tr);
|
|
77
|
+
|
|
78
|
+
dispatch(tr);
|
|
79
|
+
|
|
80
|
+
updateWidth(newWidth);
|
|
81
|
+
return newWidth;
|
|
82
|
+
}}
|
|
83
|
+
resizeRatio={2}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</ResizerNext>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
@@ -1,82 +1,13 @@
|
|
|
1
1
|
import { Node as PMNode } from 'prosemirror-model';
|
|
2
2
|
import { Transaction } from 'prosemirror-state';
|
|
3
|
+
import { ContentNodeWithPos } from 'prosemirror-utils';
|
|
3
4
|
|
|
4
5
|
import { isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
5
|
-
|
|
6
6
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
7
|
-
import type { DomAtPos } from 'prosemirror-utils';
|
|
8
|
-
import { updateColumnWidths } from '../../transforms';
|
|
9
7
|
|
|
10
8
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
hasTableBeenResized,
|
|
14
|
-
isClickNear,
|
|
15
|
-
insertColgroupFromNode as recreateResizeColsByNode,
|
|
16
|
-
ResizeState,
|
|
17
|
-
scale,
|
|
18
|
-
ScaleOptions,
|
|
19
|
-
scaleWithParent,
|
|
20
|
-
} from './utils';
|
|
21
|
-
|
|
22
|
-
import { ContentNodeWithPos } from 'prosemirror-utils';
|
|
23
|
-
|
|
24
|
-
// Scale the table to meet new requirements (col, layout change etc)
|
|
25
|
-
export const scaleTable =
|
|
26
|
-
(
|
|
27
|
-
tableRef: HTMLTableElement | null | undefined,
|
|
28
|
-
options: ScaleOptions,
|
|
29
|
-
domAtPos: DomAtPos,
|
|
30
|
-
): Command =>
|
|
31
|
-
(state, dispatch) => {
|
|
32
|
-
if (!tableRef) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const { node, start, parentWidth, layoutChanged } = options;
|
|
37
|
-
|
|
38
|
-
// If a table has not been resized yet, columns should be auto.
|
|
39
|
-
if (hasTableBeenResized(node) === false) {
|
|
40
|
-
// If its not a re-sized table, we still want to re-create cols
|
|
41
|
-
// To force reflow of columns upon delete.
|
|
42
|
-
recreateResizeColsByNode(tableRef, node);
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let resizeState;
|
|
47
|
-
if (parentWidth) {
|
|
48
|
-
resizeState = scaleWithParent(
|
|
49
|
-
tableRef,
|
|
50
|
-
parentWidth,
|
|
51
|
-
node,
|
|
52
|
-
start,
|
|
53
|
-
domAtPos,
|
|
54
|
-
);
|
|
55
|
-
} else {
|
|
56
|
-
resizeState = scale(tableRef, options, domAtPos);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (resizeState) {
|
|
60
|
-
let { tr } = state;
|
|
61
|
-
tr = updateColumnWidths(resizeState, node, start)(tr);
|
|
62
|
-
|
|
63
|
-
if (tr.docChanged && dispatch) {
|
|
64
|
-
tr.setMeta('scrollIntoView', false);
|
|
65
|
-
// TODO: ED-8995
|
|
66
|
-
// We need to do this check to reduce the number of race conditions when working with tables.
|
|
67
|
-
// This metadata is been used in the sendTransaction function in the Collab plugin
|
|
68
|
-
/* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
|
|
69
|
-
scaleTable is only called once every time a breakout button is clicked, so it is safe not to add the meta 'scaleTable' to the tr.
|
|
70
|
-
Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
|
|
71
|
-
*/
|
|
72
|
-
!layoutChanged && tr.setMeta('scaleTable', true);
|
|
73
|
-
dispatch(tr);
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
};
|
|
9
|
+
import { evenAllColumnsWidths, isClickNear, ResizeState } from './utils';
|
|
10
|
+
import { updateColumnWidths } from '../../transforms';
|
|
80
11
|
|
|
81
12
|
export const evenColumns =
|
|
82
13
|
({
|
|
@@ -23,7 +23,6 @@ export {
|
|
|
23
23
|
adjustColumnsWidths,
|
|
24
24
|
} from './resize-state';
|
|
25
25
|
export {
|
|
26
|
-
tableLayoutToSize,
|
|
27
26
|
getLayoutSize,
|
|
28
27
|
getDefaultLayoutMaxWidth,
|
|
29
28
|
pointsAtCell,
|
|
@@ -31,7 +30,12 @@ export {
|
|
|
31
30
|
domCellAround,
|
|
32
31
|
} from './misc';
|
|
33
32
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
34
|
-
export {
|
|
33
|
+
export {
|
|
34
|
+
scale,
|
|
35
|
+
scaleWithParent,
|
|
36
|
+
scaleTable,
|
|
37
|
+
previewScaleTable,
|
|
38
|
+
} from './scale-table';
|
|
35
39
|
export type { ScaleOptions } from './scale-table';
|
|
36
40
|
export type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
37
41
|
export { resizeColumn } from './resize-column';
|
|
@@ -8,10 +8,8 @@ import {
|
|
|
8
8
|
mapBreakpointToLayoutMaxWidth,
|
|
9
9
|
} from '@atlaskit/editor-common/ui';
|
|
10
10
|
import {
|
|
11
|
-
akEditorDefaultLayoutWidth,
|
|
12
11
|
akEditorFullWidthLayoutWidth,
|
|
13
12
|
akEditorGutterPadding,
|
|
14
|
-
akEditorWideLayoutWidth,
|
|
15
13
|
akEditorTableNumberColumnWidth,
|
|
16
14
|
} from '@atlaskit/editor-shared-styles';
|
|
17
15
|
|
|
@@ -20,13 +18,10 @@ import { TableOptions } from '../../../nodeviews/types';
|
|
|
20
18
|
import { Node as PMNode } from 'prosemirror-model';
|
|
21
19
|
import { EditorState } from 'prosemirror-state';
|
|
22
20
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
wide: akEditorWideLayoutWidth,
|
|
28
|
-
'full-width': akEditorFullWidthLayoutWidth,
|
|
29
|
-
};
|
|
21
|
+
import {
|
|
22
|
+
getParentNodeWidth,
|
|
23
|
+
layoutToWidth,
|
|
24
|
+
} from '@atlaskit/editor-common/node-width';
|
|
30
25
|
|
|
31
26
|
// Translates named layouts in number values.
|
|
32
27
|
export function getLayoutSize(
|
|
@@ -50,11 +45,11 @@ export function getLayoutSize(
|
|
|
50
45
|
containerWidth,
|
|
51
46
|
true,
|
|
52
47
|
);
|
|
53
|
-
if (calculatedTableWidth
|
|
54
|
-
return
|
|
48
|
+
if (calculatedTableWidth !== 'inherit') {
|
|
49
|
+
return calculatedTableWidth;
|
|
55
50
|
}
|
|
56
51
|
|
|
57
|
-
return
|
|
52
|
+
return layoutToWidth[tableLayout] || containerWidth;
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
export function getDefaultLayoutMaxWidth(containerWidth?: number): number {
|