@atlaskit/editor-plugin-table 1.1.2 → 1.1.4
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 +19 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +13 -3
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/commands.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +17 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +38 -6
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +2 -2
- package/dist/cjs/plugins/table/transforms/column-width.js +47 -5
- package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +6 -3
- package/dist/cjs/plugins/table/ui/common-styles.js +4 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +13 -3
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/commands.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +15 -0
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +37 -4
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +2 -2
- package/dist/es2019/plugins/table/transforms/column-width.js +45 -5
- package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +4 -1
- package/dist/es2019/plugins/table/ui/common-styles.js +5 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +13 -3
- package/dist/esm/plugins/table/pm-plugins/table-resizing/commands.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +15 -0
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +35 -4
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +2 -2
- package/dist/esm/plugins/table/transforms/column-width.js +47 -5
- package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +4 -1
- package/dist/esm/plugins/table/ui/common-styles.js +3 -3
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +7 -0
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +2 -1
- package/dist/types/plugins/table/ui/common-styles.d.ts +1 -0
- package/package.json +11 -9
- package/src/__tests__/integration/__fixtures__/empty-layout.ts +35 -0
- package/src/__tests__/integration/__fixtures__/nested-in-expand.ts +129 -0
- package/src/__tests__/integration/horizontal-scroll.ts +489 -0
- package/src/__tests__/unit/commands/insert.ts +3 -3
- package/src/__tests__/unit/keymap.ts +3 -1
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +38 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +5 -2
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +2 -2
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +2 -2
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +2 -2
- package/src/__tests__/visual-regression/sticky-header.ts +2 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +16 -3
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +6 -2
- package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +9 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/colgroup.ts +19 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +57 -5
- package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +2 -2
- package/src/plugins/table/transforms/column-width.ts +60 -6
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +2 -1
- package/src/plugins/table/ui/common-styles.ts +5 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DOMSerializer } from 'prosemirror-model';
|
|
2
2
|
import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
4
|
export const generateColgroup = table => {
|
|
4
5
|
const cols = [];
|
|
5
6
|
table.content.firstChild.content.forEach(cell => {
|
|
@@ -35,6 +36,20 @@ export const insertColgroupFromNode = (tableRef, table) => {
|
|
|
35
36
|
export const hasTableBeenResized = table => {
|
|
36
37
|
return !!getFragmentBackingArray(table.content.firstChild.content).find(cell => cell.attrs.colwidth);
|
|
37
38
|
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if a table has all the column width set to tableCellMinWidth(48px) or null
|
|
42
|
+
*
|
|
43
|
+
* @param table
|
|
44
|
+
* @returns true if all column width is equal to tableCellMinWidth or null, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
export const isMinCellWidthTable = table => {
|
|
47
|
+
const cellArray = getFragmentBackingArray(table.content.firstChild.content);
|
|
48
|
+
const isTableMinCellWidth = cellArray.every(cell => {
|
|
49
|
+
return cell.attrs.colwidth && cell.attrs.colwidth[0] === tableCellMinWidth || cell.attrs.colwidth === null;
|
|
50
|
+
});
|
|
51
|
+
return isTableMinCellWidth;
|
|
52
|
+
};
|
|
38
53
|
function renderColgroupFromNode(table) {
|
|
39
54
|
const rendered = DOMSerializer.renderSpec(document, ['colgroup', {}, ...generateColgroup(table)]);
|
|
40
55
|
return rendered.dom;
|
|
@@ -3,6 +3,8 @@ import { getBreakpoint, mapBreakpointToLayoutMaxWidth } from '@atlaskit/editor-c
|
|
|
3
3
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorWideLayoutWidth, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
4
4
|
import { containsClassName } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
|
|
6
|
+
import { gridSize } from '@atlaskit/theme/constants';
|
|
7
|
+
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
6
8
|
export const tableLayoutToSize = {
|
|
7
9
|
default: akEditorDefaultLayoutWidth,
|
|
8
10
|
wide: akEditorWideLayoutWidth,
|
|
@@ -21,9 +23,6 @@ export function getLayoutSize(tableLayout, containerWidth = 0, options) {
|
|
|
21
23
|
if (calculatedTableWidth.endsWith('px')) {
|
|
22
24
|
return parseInt(calculatedTableWidth, 10);
|
|
23
25
|
}
|
|
24
|
-
if (tableLayout === 'default') {
|
|
25
|
-
return getDefaultLayoutMaxWidth(containerWidth);
|
|
26
|
-
}
|
|
27
26
|
return tableLayoutToSize[tableLayout] || containerWidth;
|
|
28
27
|
}
|
|
29
28
|
export function getDefaultLayoutMaxWidth(containerWidth) {
|
|
@@ -74,9 +73,43 @@ export const getTableMaxWidth = ({
|
|
|
74
73
|
}) => {
|
|
75
74
|
const containerWidth = getEditorContainerWidth();
|
|
76
75
|
const parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
|
|
77
|
-
|
|
76
|
+
|
|
77
|
+
// TODO - refactor this logic into getParentNodeWidth() in editor-common [ED-16718]
|
|
78
|
+
const parentActualWidth = getParentWidthWithoutPadding(parentWidth, tableStart, state);
|
|
79
|
+
let maxWidth = parentActualWidth || getLayoutSize(layout, containerWidth.width, {});
|
|
78
80
|
if (table.attrs.isNumberColumnEnabled) {
|
|
79
81
|
maxWidth -= akEditorTableNumberColumnWidth;
|
|
80
82
|
}
|
|
81
83
|
return maxWidth;
|
|
84
|
+
};
|
|
85
|
+
export const getParentWidthWithoutPadding = (parentWidth, tableStartPos, state) => {
|
|
86
|
+
const node = getNestedParentNode(tableStartPos, state);
|
|
87
|
+
if (!node) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const {
|
|
91
|
+
schema
|
|
92
|
+
} = state;
|
|
93
|
+
if (node.type === schema.nodes.expand) {
|
|
94
|
+
// padding
|
|
95
|
+
parentWidth -= gridSize() * 2;
|
|
96
|
+
// gutter offset
|
|
97
|
+
parentWidth += gridSize() * 1.5 * 2;
|
|
98
|
+
// padding right
|
|
99
|
+
parentWidth -= gridSize();
|
|
100
|
+
// padding left
|
|
101
|
+
parentWidth -= gridSize() * 4 - gridSize() / 2;
|
|
102
|
+
}
|
|
103
|
+
return parentWidth;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// copy of getNestedParentNode() from packages/editor/editor-common/src/node-width/index.ts
|
|
107
|
+
// to be removed later when we will move getParentWidthWithoutPadding() logic to editor-common
|
|
108
|
+
const getNestedParentNode = (tablePos, state) => {
|
|
109
|
+
if (tablePos === undefined) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const $pos = state.doc.resolve(tablePos);
|
|
113
|
+
const parent = findParentNodeOfTypeClosestToPos($pos, [state.schema.nodes.bodiedExtension, state.schema.nodes.layoutSection, state.schema.nodes.expand]);
|
|
114
|
+
return parent ? parent.node : null;
|
|
82
115
|
};
|
|
@@ -11,7 +11,7 @@ export const growColumn = (state, colIndex, amount, selectedColumns) => {
|
|
|
11
11
|
if (remaining > 0) {
|
|
12
12
|
newState = stackSpace(newState, colIndex, remaining).state;
|
|
13
13
|
}
|
|
14
|
-
if (selectedColumns) {
|
|
14
|
+
if (selectedColumns && selectedColumns.length > 1) {
|
|
15
15
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
16
16
|
}
|
|
17
17
|
return newState;
|
|
@@ -34,7 +34,7 @@ export const shrinkColumn = (state, colIndex, amount, selectedColumns) => {
|
|
|
34
34
|
if (remaining < 0) {
|
|
35
35
|
newState = stackSpace(newState, colIndex + 1, remaining).state;
|
|
36
36
|
}
|
|
37
|
-
if (selectedColumns) {
|
|
37
|
+
if (selectedColumns && selectedColumns.length > 1) {
|
|
38
38
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
39
39
|
}
|
|
40
40
|
return newState;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
2
2
|
import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
3
4
|
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
4
5
|
import { setMeta } from './metadata';
|
|
5
6
|
import { getResizeState, normaliseTableLayout } from '../pm-plugins/table-resizing/utils/resize-state';
|
|
6
7
|
import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
|
|
7
8
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
8
9
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
10
|
+
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
11
|
+
import { insertColumnButtonOffset } from '../ui/common-styles';
|
|
9
12
|
export const updateColumnWidths = (resizeState, table, start) => tr => {
|
|
10
13
|
const map = TableMap.get(table);
|
|
11
14
|
const updatedCellsAttrs = {};
|
|
@@ -108,18 +111,19 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
|
|
|
108
111
|
* @returns Updated transaction with rescaled columns for a given table
|
|
109
112
|
*/
|
|
110
113
|
export const rescaleColumns = getEditorContainerWidth => (table, view) => tr => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (!view || !hasTableBeenResized(table.node)) {
|
|
114
|
+
var _tableRef$parentEleme;
|
|
115
|
+
if (!view) {
|
|
114
116
|
return tr;
|
|
115
117
|
}
|
|
118
|
+
const pos = table.pos;
|
|
119
|
+
const newTable = tr.doc.nodeAt(pos);
|
|
116
120
|
const {
|
|
117
121
|
state
|
|
118
122
|
} = view;
|
|
119
123
|
const domAtPos = view.domAtPos.bind(view);
|
|
120
124
|
const maybeTable = domAtPos(table.start).node;
|
|
121
125
|
const tableRef = maybeTable.closest('table');
|
|
122
|
-
if (!tableRef) {
|
|
126
|
+
if (!tableRef || !newTable) {
|
|
123
127
|
return tr;
|
|
124
128
|
}
|
|
125
129
|
const layout = normaliseTableLayout(tableRef === null || tableRef === void 0 ? void 0 : tableRef.dataset.layout);
|
|
@@ -131,6 +135,42 @@ export const rescaleColumns = getEditorContainerWidth => (table, view) => tr =>
|
|
|
131
135
|
layout,
|
|
132
136
|
getEditorContainerWidth
|
|
133
137
|
});
|
|
138
|
+
const tableWidth = tableRef.clientWidth || akEditorDefaultLayoutWidth;
|
|
139
|
+
let tableMaxWidth = (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0;
|
|
140
|
+
tableMaxWidth -= insertColumnButtonOffset;
|
|
141
|
+
const newTableMap = TableMap.get(newTable);
|
|
142
|
+
const noOfColumns = newTableMap.width;
|
|
143
|
+
if (!noOfColumns || noOfColumns <= 0) {
|
|
144
|
+
return tr;
|
|
145
|
+
}
|
|
146
|
+
const columnWidthUnresized = tableWidth / noOfColumns;
|
|
147
|
+
|
|
148
|
+
// If the table has not been resized, and the column width is bigger than the minimum column width
|
|
149
|
+
// we skip updating the size of columns here.
|
|
150
|
+
if (!hasTableBeenResized(table.node) && columnWidthUnresized > tableCellMinWidth) {
|
|
151
|
+
return tr;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// If the table has not been resized, and the column width is smaller than the minimum column width
|
|
155
|
+
// Or if the table has been resized, but each column width is either 48px or null
|
|
156
|
+
// we update the table to have 48px for each column
|
|
157
|
+
if (!hasTableBeenResized(table.node) && columnWidthUnresized <= tableCellMinWidth || hasTableBeenResized(table.node) && isMinCellWidthTable(table.node)) {
|
|
158
|
+
const widths = new Array(noOfColumns).fill(tableCellMinWidth);
|
|
159
|
+
const cols = widths.map((width, index) => ({
|
|
160
|
+
width: tableCellMinWidth,
|
|
161
|
+
minWidth: tableCellMinWidth,
|
|
162
|
+
index
|
|
163
|
+
}));
|
|
164
|
+
const overflow = tableWidth > maxSize;
|
|
165
|
+
const minWidthResizeState = {
|
|
166
|
+
cols,
|
|
167
|
+
widths,
|
|
168
|
+
maxSize,
|
|
169
|
+
tableWidth,
|
|
170
|
+
overflow
|
|
171
|
+
};
|
|
172
|
+
return updateColumnWidths(minWidthResizeState, table.node, table.start)(tr);
|
|
173
|
+
}
|
|
134
174
|
let resizeState = getResizeState({
|
|
135
175
|
minWidth: tableCellMinWidth,
|
|
136
176
|
table: table.node,
|
|
@@ -140,7 +180,7 @@ export const rescaleColumns = getEditorContainerWidth => (table, view) => tr =>
|
|
|
140
180
|
maxSize
|
|
141
181
|
});
|
|
142
182
|
const previousTableWidth = resizeState.tableWidth - tableNewColumnMinWidth;
|
|
143
|
-
const tableDidntPreviouslyOverflow = previousTableWidth <= maxSize;
|
|
183
|
+
const tableDidntPreviouslyOverflow = previousTableWidth <= Math.max(maxSize, tableMaxWidth);
|
|
144
184
|
|
|
145
185
|
// If the new table width will result in the table going into an overflow state
|
|
146
186
|
// we resize the cells to avoid the overflow occuring
|
|
@@ -6,6 +6,7 @@ import { splitCell } from '@atlaskit/editor-tables/utils';
|
|
|
6
6
|
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
7
7
|
import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
8
8
|
import { ColorPalette, cellBackgroundColorPalette } from '@atlaskit/editor-common/ui-color';
|
|
9
|
+
import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
|
|
9
10
|
import { DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
10
11
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
11
12
|
import { cellColourPreviewStyles } from './styles';
|
|
@@ -115,7 +116,9 @@ export class ContextualMenu extends Component {
|
|
|
115
116
|
value: {
|
|
116
117
|
name: 'background'
|
|
117
118
|
},
|
|
118
|
-
elemAfter: jsx("div",
|
|
119
|
+
elemAfter: jsx("div", {
|
|
120
|
+
className: DropdownMenuSharedCssClassName.SUBMENU
|
|
121
|
+
}, jsx("div", {
|
|
119
122
|
css: cellColourPreviewStyles(background),
|
|
120
123
|
className: ClassName.CONTEXTUAL_MENU_ICON
|
|
121
124
|
}), isSubmenuOpen && jsx("div", {
|
|
@@ -14,7 +14,7 @@ const cornerControlHeight = tableToolbarSize + 1;
|
|
|
14
14
|
that is aligned to the right edge initially on hover of the top right column control when table overflown,
|
|
15
15
|
its center should be aligned with the edge
|
|
16
16
|
*/
|
|
17
|
-
const insertColumnButtonOffset = tableInsertColumnButtonSize / 2;
|
|
17
|
+
export const insertColumnButtonOffset = tableInsertColumnButtonSize / 2;
|
|
18
18
|
const rangeSelectionStyles = `
|
|
19
19
|
.${ClassName.NODEVIEW_WRAPPER}.${akEditorSelectedNodeClassName} table tbody tr {
|
|
20
20
|
th,td {
|
|
@@ -523,6 +523,8 @@ export const tableStyles = props => {
|
|
|
523
523
|
table-layout: fixed;
|
|
524
524
|
white-space: normal;
|
|
525
525
|
border-top: none;
|
|
526
|
+
// 1px border width offset added here to prevent unwanted overflow and scolling - ED-16212
|
|
527
|
+
margin-right: -1px;
|
|
526
528
|
|
|
527
529
|
> tbody > tr {
|
|
528
530
|
white-space: pre-wrap;
|
|
@@ -643,7 +645,8 @@ export const tableStyles = props => {
|
|
|
643
645
|
export const tableFullPageEditorStyles = css`
|
|
644
646
|
.ProseMirror .${ClassName.TABLE_NODE_WRAPPER} > table {
|
|
645
647
|
margin-left: 0;
|
|
646
|
-
|
|
648
|
+
// 1px border width offset added here to prevent unwanted overflow and scolling - ED-16212
|
|
649
|
+
margin-right: -1px;
|
|
647
650
|
width: 100%;
|
|
648
651
|
}
|
|
649
652
|
`;
|
package/dist/es2019/version.json
CHANGED
|
@@ -31,6 +31,7 @@ import { containsHeaderRow, tablesHaveDifferentColumnWidths, tablesHaveDifferent
|
|
|
31
31
|
import { updateOverflowShadows } from './update-overflow-shadows';
|
|
32
32
|
import memoizeOne from 'memoize-one';
|
|
33
33
|
import { OverflowShadowsObserver } from './OverflowShadowsObserver';
|
|
34
|
+
import { getParentWidthWithoutPadding } from '../pm-plugins/table-resizing/utils/misc';
|
|
34
35
|
var isIE11 = browser.ie_version === 11;
|
|
35
36
|
var NOOP = function NOOP() {
|
|
36
37
|
return undefined;
|
|
@@ -192,15 +193,23 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
192
193
|
}
|
|
193
194
|
});
|
|
194
195
|
_defineProperty(_assertThisInitialized(_this), "handleWindowResize", function () {
|
|
196
|
+
var _node$attrs, _node$attrs2;
|
|
195
197
|
var _this$props4 = _this.props,
|
|
196
198
|
getNode = _this$props4.getNode,
|
|
197
199
|
containerWidth = _this$props4.containerWidth;
|
|
198
|
-
var
|
|
200
|
+
var node = getNode();
|
|
201
|
+
var prevNode = _this.node;
|
|
202
|
+
var layoutSize = _this.tableNodeLayoutSize(node);
|
|
203
|
+
var prevAttrs = prevNode === null || prevNode === void 0 ? void 0 : prevNode.attrs;
|
|
204
|
+
var layoutChanged = (prevAttrs === null || prevAttrs === void 0 ? void 0 : prevAttrs.layout) !== (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) && (prevAttrs === null || prevAttrs === void 0 ? void 0 : prevAttrs.__autoSize) === (node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.__autoSize);
|
|
199
205
|
if (containerWidth.width > layoutSize) {
|
|
200
206
|
return;
|
|
201
207
|
}
|
|
202
208
|
var parentWidth = _this.getParentNodeWidth();
|
|
203
|
-
_this.scaleTableDebounced(
|
|
209
|
+
_this.scaleTableDebounced({
|
|
210
|
+
layoutChanged: layoutChanged,
|
|
211
|
+
parentWidth: parentWidth
|
|
212
|
+
});
|
|
204
213
|
});
|
|
205
214
|
_defineProperty(_assertThisInitialized(_this), "updateTableContainerWidth", function () {
|
|
206
215
|
var _this$props5 = _this.props,
|
|
@@ -236,7 +245,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
236
245
|
if (!isValidPosition(pos, state)) {
|
|
237
246
|
return;
|
|
238
247
|
}
|
|
239
|
-
|
|
248
|
+
var parentNodeWith = getParentNodeWidth(pos, state, containerWidth, options && options.isFullWidthModeEnabled);
|
|
249
|
+
return getParentWidthWithoutPadding(parentNodeWith, pos, state);
|
|
240
250
|
});
|
|
241
251
|
_defineProperty(_assertThisInitialized(_this), "updateParentWidth", function (width) {
|
|
242
252
|
_this.setState({
|
|
@@ -10,7 +10,8 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
|
10
10
|
}
|
|
11
11
|
var node = options.node,
|
|
12
12
|
start = options.start,
|
|
13
|
-
parentWidth = options.parentWidth
|
|
13
|
+
parentWidth = options.parentWidth,
|
|
14
|
+
layoutChanged = options.layoutChanged;
|
|
14
15
|
|
|
15
16
|
// If a table has not been resized yet, columns should be auto.
|
|
16
17
|
if (hasTableBeenResized(node) === false) {
|
|
@@ -33,7 +34,11 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
|
33
34
|
// TODO: ED-8995
|
|
34
35
|
// We need to do this check to reduce the number of race conditions when working with tables.
|
|
35
36
|
// This metadata is been used in the sendTransaction function in the Collab plugin
|
|
36
|
-
|
|
37
|
+
/* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
|
|
38
|
+
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.
|
|
39
|
+
Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
|
|
40
|
+
*/
|
|
41
|
+
!layoutChanged && _tr.setMeta('scaleTable', true);
|
|
37
42
|
dispatch(_tr);
|
|
38
43
|
return true;
|
|
39
44
|
}
|
|
@@ -9,6 +9,7 @@ import { evenColumns, setDragging, stopResizing } from './commands';
|
|
|
9
9
|
import { getPluginState } from './plugin-factory';
|
|
10
10
|
import { currentColWidth, getLayoutSize, getResizeState, pointsAtCell, resizeColumn, updateControls } from './utils';
|
|
11
11
|
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
12
|
+
import { getParentWidthWithoutPadding } from './utils/misc';
|
|
12
13
|
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI) {
|
|
13
14
|
var state = view.state,
|
|
14
15
|
dispatch = view.dispatch;
|
|
@@ -29,7 +30,10 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
29
30
|
}
|
|
30
31
|
var containerWidth = getEditorContainerWidth();
|
|
31
32
|
var parentWidth = getParentNodeWidth(start, state, containerWidth);
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
// TODO - refactor this logic into getParentNodeWidth() in editor-common [ED-16718]
|
|
35
|
+
var parentActualWidth = getParentWidthWithoutPadding(parentWidth, start, state);
|
|
36
|
+
var maxSize = parentActualWidth || getLayoutSize(dom.getAttribute('data-layout'), containerWidth.width, {});
|
|
33
37
|
if (originalTable.attrs.isNumberColumnEnabled) {
|
|
34
38
|
maxSize -= akEditorTableNumberColumnWidth;
|
|
35
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { DOMSerializer } from 'prosemirror-model';
|
|
3
3
|
import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
4
5
|
export var generateColgroup = function generateColgroup(table) {
|
|
5
6
|
var cols = [];
|
|
6
7
|
table.content.firstChild.content.forEach(function (cell) {
|
|
@@ -40,6 +41,20 @@ export var hasTableBeenResized = function hasTableBeenResized(table) {
|
|
|
40
41
|
return cell.attrs.colwidth;
|
|
41
42
|
});
|
|
42
43
|
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if a table has all the column width set to tableCellMinWidth(48px) or null
|
|
47
|
+
*
|
|
48
|
+
* @param table
|
|
49
|
+
* @returns true if all column width is equal to tableCellMinWidth or null, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
export var isMinCellWidthTable = function isMinCellWidthTable(table) {
|
|
52
|
+
var cellArray = getFragmentBackingArray(table.content.firstChild.content);
|
|
53
|
+
var isTableMinCellWidth = cellArray.every(function (cell) {
|
|
54
|
+
return cell.attrs.colwidth && cell.attrs.colwidth[0] === tableCellMinWidth || cell.attrs.colwidth === null;
|
|
55
|
+
});
|
|
56
|
+
return isTableMinCellWidth;
|
|
57
|
+
};
|
|
43
58
|
function renderColgroupFromNode(table) {
|
|
44
59
|
var rendered = DOMSerializer.renderSpec(document, ['colgroup', {}].concat(_toConsumableArray(generateColgroup(table))));
|
|
45
60
|
return rendered.dom;
|
|
@@ -3,6 +3,8 @@ import { getBreakpoint, mapBreakpointToLayoutMaxWidth } from '@atlaskit/editor-c
|
|
|
3
3
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorGutterPadding, akEditorWideLayoutWidth, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
4
4
|
import { containsClassName } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
|
|
6
|
+
import { gridSize } from '@atlaskit/theme/constants';
|
|
7
|
+
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
6
8
|
export var tableLayoutToSize = {
|
|
7
9
|
default: akEditorDefaultLayoutWidth,
|
|
8
10
|
wide: akEditorWideLayoutWidth,
|
|
@@ -21,9 +23,6 @@ export function getLayoutSize(tableLayout) {
|
|
|
21
23
|
if (calculatedTableWidth.endsWith('px')) {
|
|
22
24
|
return parseInt(calculatedTableWidth, 10);
|
|
23
25
|
}
|
|
24
|
-
if (tableLayout === 'default') {
|
|
25
|
-
return getDefaultLayoutMaxWidth(containerWidth);
|
|
26
|
-
}
|
|
27
26
|
return tableLayoutToSize[tableLayout] || containerWidth;
|
|
28
27
|
}
|
|
29
28
|
export function getDefaultLayoutMaxWidth(containerWidth) {
|
|
@@ -72,9 +71,41 @@ export var getTableMaxWidth = function getTableMaxWidth(_ref2) {
|
|
|
72
71
|
getEditorContainerWidth = _ref2.getEditorContainerWidth;
|
|
73
72
|
var containerWidth = getEditorContainerWidth();
|
|
74
73
|
var parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
|
|
75
|
-
|
|
74
|
+
|
|
75
|
+
// TODO - refactor this logic into getParentNodeWidth() in editor-common [ED-16718]
|
|
76
|
+
var parentActualWidth = getParentWidthWithoutPadding(parentWidth, tableStart, state);
|
|
77
|
+
var maxWidth = parentActualWidth || getLayoutSize(layout, containerWidth.width, {});
|
|
76
78
|
if (table.attrs.isNumberColumnEnabled) {
|
|
77
79
|
maxWidth -= akEditorTableNumberColumnWidth;
|
|
78
80
|
}
|
|
79
81
|
return maxWidth;
|
|
82
|
+
};
|
|
83
|
+
export var getParentWidthWithoutPadding = function getParentWidthWithoutPadding(parentWidth, tableStartPos, state) {
|
|
84
|
+
var node = getNestedParentNode(tableStartPos, state);
|
|
85
|
+
if (!node) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
var schema = state.schema;
|
|
89
|
+
if (node.type === schema.nodes.expand) {
|
|
90
|
+
// padding
|
|
91
|
+
parentWidth -= gridSize() * 2;
|
|
92
|
+
// gutter offset
|
|
93
|
+
parentWidth += gridSize() * 1.5 * 2;
|
|
94
|
+
// padding right
|
|
95
|
+
parentWidth -= gridSize();
|
|
96
|
+
// padding left
|
|
97
|
+
parentWidth -= gridSize() * 4 - gridSize() / 2;
|
|
98
|
+
}
|
|
99
|
+
return parentWidth;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// copy of getNestedParentNode() from packages/editor/editor-common/src/node-width/index.ts
|
|
103
|
+
// to be removed later when we will move getParentWidthWithoutPadding() logic to editor-common
|
|
104
|
+
var getNestedParentNode = function getNestedParentNode(tablePos, state) {
|
|
105
|
+
if (tablePos === undefined) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
var $pos = state.doc.resolve(tablePos);
|
|
109
|
+
var parent = findParentNodeOfTypeClosestToPos($pos, [state.schema.nodes.bodiedExtension, state.schema.nodes.layoutSection, state.schema.nodes.expand]);
|
|
110
|
+
return parent ? parent.node : null;
|
|
80
111
|
};
|
|
@@ -16,7 +16,7 @@ export var growColumn = function growColumn(state, colIndex, amount, selectedCol
|
|
|
16
16
|
if (remaining > 0) {
|
|
17
17
|
newState = stackSpace(newState, colIndex, remaining).state;
|
|
18
18
|
}
|
|
19
|
-
if (selectedColumns) {
|
|
19
|
+
if (selectedColumns && selectedColumns.length > 1) {
|
|
20
20
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
21
21
|
}
|
|
22
22
|
return newState;
|
|
@@ -39,7 +39,7 @@ export var shrinkColumn = function shrinkColumn(state, colIndex, amount, selecte
|
|
|
39
39
|
if (remaining < 0) {
|
|
40
40
|
newState = stackSpace(newState, colIndex + 1, remaining).state;
|
|
41
41
|
}
|
|
42
|
-
if (selectedColumns) {
|
|
42
|
+
if (selectedColumns && selectedColumns.length > 1) {
|
|
43
43
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
44
44
|
}
|
|
45
45
|
return newState;
|
|
@@ -3,12 +3,15 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
5
|
import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
6
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
6
7
|
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
7
8
|
import { setMeta } from './metadata';
|
|
8
9
|
import { getResizeState, normaliseTableLayout } from '../pm-plugins/table-resizing/utils/resize-state';
|
|
9
10
|
import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
|
|
10
11
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
11
12
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
13
|
+
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
14
|
+
import { insertColumnButtonOffset } from '../ui/common-styles';
|
|
12
15
|
export var updateColumnWidths = function updateColumnWidths(resizeState, table, start) {
|
|
13
16
|
return function (tr) {
|
|
14
17
|
var map = TableMap.get(table);
|
|
@@ -112,16 +115,17 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
|
|
|
112
115
|
export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
|
|
113
116
|
return function (table, view) {
|
|
114
117
|
return function (tr) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (!view || !hasTableBeenResized(table.node)) {
|
|
118
|
+
var _tableRef$parentEleme;
|
|
119
|
+
if (!view) {
|
|
118
120
|
return tr;
|
|
119
121
|
}
|
|
122
|
+
var pos = table.pos;
|
|
123
|
+
var newTable = tr.doc.nodeAt(pos);
|
|
120
124
|
var state = view.state;
|
|
121
125
|
var domAtPos = view.domAtPos.bind(view);
|
|
122
126
|
var maybeTable = domAtPos(table.start).node;
|
|
123
127
|
var tableRef = maybeTable.closest('table');
|
|
124
|
-
if (!tableRef) {
|
|
128
|
+
if (!tableRef || !newTable) {
|
|
125
129
|
return tr;
|
|
126
130
|
}
|
|
127
131
|
var layout = normaliseTableLayout(tableRef === null || tableRef === void 0 ? void 0 : tableRef.dataset.layout);
|
|
@@ -133,6 +137,44 @@ export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
|
|
|
133
137
|
layout: layout,
|
|
134
138
|
getEditorContainerWidth: getEditorContainerWidth
|
|
135
139
|
});
|
|
140
|
+
var tableWidth = tableRef.clientWidth || akEditorDefaultLayoutWidth;
|
|
141
|
+
var tableMaxWidth = (tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || 0;
|
|
142
|
+
tableMaxWidth -= insertColumnButtonOffset;
|
|
143
|
+
var newTableMap = TableMap.get(newTable);
|
|
144
|
+
var noOfColumns = newTableMap.width;
|
|
145
|
+
if (!noOfColumns || noOfColumns <= 0) {
|
|
146
|
+
return tr;
|
|
147
|
+
}
|
|
148
|
+
var columnWidthUnresized = tableWidth / noOfColumns;
|
|
149
|
+
|
|
150
|
+
// If the table has not been resized, and the column width is bigger than the minimum column width
|
|
151
|
+
// we skip updating the size of columns here.
|
|
152
|
+
if (!hasTableBeenResized(table.node) && columnWidthUnresized > tableCellMinWidth) {
|
|
153
|
+
return tr;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// If the table has not been resized, and the column width is smaller than the minimum column width
|
|
157
|
+
// Or if the table has been resized, but each column width is either 48px or null
|
|
158
|
+
// we update the table to have 48px for each column
|
|
159
|
+
if (!hasTableBeenResized(table.node) && columnWidthUnresized <= tableCellMinWidth || hasTableBeenResized(table.node) && isMinCellWidthTable(table.node)) {
|
|
160
|
+
var widths = new Array(noOfColumns).fill(tableCellMinWidth);
|
|
161
|
+
var cols = widths.map(function (width, index) {
|
|
162
|
+
return {
|
|
163
|
+
width: tableCellMinWidth,
|
|
164
|
+
minWidth: tableCellMinWidth,
|
|
165
|
+
index: index
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
var overflow = tableWidth > maxSize;
|
|
169
|
+
var minWidthResizeState = {
|
|
170
|
+
cols: cols,
|
|
171
|
+
widths: widths,
|
|
172
|
+
maxSize: maxSize,
|
|
173
|
+
tableWidth: tableWidth,
|
|
174
|
+
overflow: overflow
|
|
175
|
+
};
|
|
176
|
+
return updateColumnWidths(minWidthResizeState, table.node, table.start)(tr);
|
|
177
|
+
}
|
|
136
178
|
var resizeState = getResizeState({
|
|
137
179
|
minWidth: tableCellMinWidth,
|
|
138
180
|
table: table.node,
|
|
@@ -142,7 +184,7 @@ export var rescaleColumns = function rescaleColumns(getEditorContainerWidth) {
|
|
|
142
184
|
maxSize: maxSize
|
|
143
185
|
});
|
|
144
186
|
var previousTableWidth = resizeState.tableWidth - tableNewColumnMinWidth;
|
|
145
|
-
var tableDidntPreviouslyOverflow = previousTableWidth <= maxSize;
|
|
187
|
+
var tableDidntPreviouslyOverflow = previousTableWidth <= Math.max(maxSize, tableMaxWidth);
|
|
146
188
|
|
|
147
189
|
// If the new table width will result in the table going into an overflow state
|
|
148
190
|
// we resize the cells to avoid the overflow occuring
|
|
@@ -16,6 +16,7 @@ import { splitCell } from '@atlaskit/editor-tables/utils';
|
|
|
16
16
|
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
17
17
|
import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
18
18
|
import { ColorPalette, cellBackgroundColorPalette } from '@atlaskit/editor-common/ui-color';
|
|
19
|
+
import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
|
|
19
20
|
import { DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
20
21
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
21
22
|
import { cellColourPreviewStyles } from './styles';
|
|
@@ -122,7 +123,9 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
122
123
|
value: {
|
|
123
124
|
name: 'background'
|
|
124
125
|
},
|
|
125
|
-
elemAfter: jsx("div",
|
|
126
|
+
elemAfter: jsx("div", {
|
|
127
|
+
className: DropdownMenuSharedCssClassName.SUBMENU
|
|
128
|
+
}, jsx("div", {
|
|
126
129
|
css: cellColourPreviewStyles(background),
|
|
127
130
|
className: ClassName.CONTEXTUAL_MENU_ICON
|
|
128
131
|
}), isSubmenuOpen && jsx("div", {
|