@atlaskit/editor-plugin-table 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/plugins/table/nodeviews/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/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/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/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 +8 -6
- 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/common-styles.ts +5 -2
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
GetEditorContainerWidth,
|
|
32
32
|
GetEditorFeatureFlags,
|
|
33
33
|
} from '@atlaskit/editor-common/types';
|
|
34
|
+
import { getParentWidthWithoutPadding } from './utils/misc';
|
|
34
35
|
|
|
35
36
|
export const handleMouseDown = (
|
|
36
37
|
view: EditorView,
|
|
@@ -67,8 +68,15 @@ export const handleMouseDown = (
|
|
|
67
68
|
const containerWidth = getEditorContainerWidth();
|
|
68
69
|
const parentWidth = getParentNodeWidth(start, state, containerWidth);
|
|
69
70
|
|
|
71
|
+
// TODO - refactor this logic into getParentNodeWidth() in editor-common [ED-16718]
|
|
72
|
+
const parentActualWidth = getParentWidthWithoutPadding(
|
|
73
|
+
parentWidth,
|
|
74
|
+
start,
|
|
75
|
+
state,
|
|
76
|
+
);
|
|
77
|
+
|
|
70
78
|
let maxSize =
|
|
71
|
-
|
|
79
|
+
parentActualWidth ||
|
|
72
80
|
getLayoutSize(
|
|
73
81
|
dom.getAttribute('data-layout') as TableLayout,
|
|
74
82
|
containerWidth.width,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DOMSerializer, Node as PmNode } from 'prosemirror-model';
|
|
2
|
-
|
|
3
2
|
import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
4
4
|
|
|
5
5
|
type Col = Array<string | { [name: string]: string }>;
|
|
6
6
|
|
|
@@ -47,6 +47,24 @@ export const hasTableBeenResized = (table: PmNode) => {
|
|
|
47
47
|
);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Check if a table has all the column width set to tableCellMinWidth(48px) or null
|
|
52
|
+
*
|
|
53
|
+
* @param table
|
|
54
|
+
* @returns true if all column width is equal to tableCellMinWidth or null, false otherwise
|
|
55
|
+
*/
|
|
56
|
+
export const isMinCellWidthTable = (table: PmNode) => {
|
|
57
|
+
const cellArray = getFragmentBackingArray(table.content.firstChild!.content);
|
|
58
|
+
const isTableMinCellWidth = cellArray.every((cell) => {
|
|
59
|
+
return (
|
|
60
|
+
(cell.attrs.colwidth && cell.attrs.colwidth[0] === tableCellMinWidth) ||
|
|
61
|
+
cell.attrs.colwidth === null
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return isTableMinCellWidth;
|
|
66
|
+
};
|
|
67
|
+
|
|
50
68
|
function renderColgroupFromNode(table: PmNode): HTMLElement {
|
|
51
69
|
const rendered = DOMSerializer.renderSpec(document, [
|
|
52
70
|
'colgroup',
|
|
@@ -21,6 +21,8 @@ import { Node as PMNode } from 'prosemirror-model';
|
|
|
21
21
|
import { EditorState } from 'prosemirror-state';
|
|
22
22
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
23
23
|
import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
|
|
24
|
+
import { gridSize } from '@atlaskit/theme/constants';
|
|
25
|
+
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
24
26
|
|
|
25
27
|
export const tableLayoutToSize: Record<string, number> = {
|
|
26
28
|
default: akEditorDefaultLayoutWidth,
|
|
@@ -54,10 +56,6 @@ export function getLayoutSize(
|
|
|
54
56
|
return parseInt(calculatedTableWidth, 10);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
if (tableLayout === 'default') {
|
|
58
|
-
return getDefaultLayoutMaxWidth(containerWidth);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
59
|
return tableLayoutToSize[tableLayout] || containerWidth;
|
|
62
60
|
}
|
|
63
61
|
|
|
@@ -126,7 +124,15 @@ export const getTableMaxWidth = ({
|
|
|
126
124
|
const containerWidth = getEditorContainerWidth();
|
|
127
125
|
const parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
|
|
128
126
|
|
|
129
|
-
|
|
127
|
+
// TODO - refactor this logic into getParentNodeWidth() in editor-common [ED-16718]
|
|
128
|
+
const parentActualWidth = getParentWidthWithoutPadding(
|
|
129
|
+
parentWidth,
|
|
130
|
+
tableStart,
|
|
131
|
+
state,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
let maxWidth =
|
|
135
|
+
parentActualWidth || getLayoutSize(layout, containerWidth.width, {});
|
|
130
136
|
|
|
131
137
|
if (table.attrs.isNumberColumnEnabled) {
|
|
132
138
|
maxWidth -= akEditorTableNumberColumnWidth;
|
|
@@ -134,3 +140,49 @@ export const getTableMaxWidth = ({
|
|
|
134
140
|
|
|
135
141
|
return maxWidth;
|
|
136
142
|
};
|
|
143
|
+
|
|
144
|
+
export const getParentWidthWithoutPadding = (
|
|
145
|
+
parentWidth: number,
|
|
146
|
+
tableStartPos: number,
|
|
147
|
+
state: EditorState,
|
|
148
|
+
) => {
|
|
149
|
+
const node = getNestedParentNode(tableStartPos, state);
|
|
150
|
+
if (!node) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const { schema } = state;
|
|
155
|
+
|
|
156
|
+
if (node.type === schema.nodes.expand) {
|
|
157
|
+
// padding
|
|
158
|
+
parentWidth -= gridSize() * 2;
|
|
159
|
+
// gutter offset
|
|
160
|
+
parentWidth += gridSize() * 1.5 * 2;
|
|
161
|
+
// padding right
|
|
162
|
+
parentWidth -= gridSize();
|
|
163
|
+
// padding left
|
|
164
|
+
parentWidth -= gridSize() * 4 - gridSize() / 2;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return parentWidth;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// copy of getNestedParentNode() from packages/editor/editor-common/src/node-width/index.ts
|
|
171
|
+
// to be removed later when we will move getParentWidthWithoutPadding() logic to editor-common
|
|
172
|
+
const getNestedParentNode = (
|
|
173
|
+
tablePos: number,
|
|
174
|
+
state: EditorState,
|
|
175
|
+
): PMNode | null => {
|
|
176
|
+
if (tablePos === undefined) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const $pos = state.doc.resolve(tablePos);
|
|
181
|
+
const parent = findParentNodeOfTypeClosestToPos($pos, [
|
|
182
|
+
state.schema.nodes.bodiedExtension,
|
|
183
|
+
state.schema.nodes.layoutSection,
|
|
184
|
+
state.schema.nodes.expand,
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
return parent ? parent.node : null;
|
|
188
|
+
};
|
|
@@ -19,7 +19,7 @@ export const growColumn = (
|
|
|
19
19
|
if (remaining > 0) {
|
|
20
20
|
newState = stackSpace(newState, colIndex, remaining).state;
|
|
21
21
|
}
|
|
22
|
-
if (selectedColumns) {
|
|
22
|
+
if (selectedColumns && selectedColumns.length > 1) {
|
|
23
23
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -51,7 +51,7 @@ export const shrinkColumn = (
|
|
|
51
51
|
if (remaining < 0) {
|
|
52
52
|
newState = stackSpace(newState, colIndex + 1, remaining).state;
|
|
53
53
|
}
|
|
54
|
-
if (selectedColumns) {
|
|
54
|
+
if (selectedColumns && selectedColumns.length > 1) {
|
|
55
55
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -2,6 +2,7 @@ import { Node as PMNode } from 'prosemirror-model';
|
|
|
2
2
|
import { Transaction } from 'prosemirror-state';
|
|
3
3
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
4
4
|
import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
5
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
5
6
|
|
|
6
7
|
import { CellAttributes } from '@atlaskit/adf-schema';
|
|
7
8
|
|
|
@@ -21,6 +22,8 @@ import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
|
|
|
21
22
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
22
23
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
23
24
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
25
|
+
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
26
|
+
import { insertColumnButtonOffset } from '../ui/common-styles';
|
|
24
27
|
|
|
25
28
|
export const updateColumnWidths =
|
|
26
29
|
(resizeState: ResizeState, table: PMNode, start: number) =>
|
|
@@ -138,19 +141,18 @@ export const rescaleColumns =
|
|
|
138
141
|
(getEditorContainerWidth: GetEditorContainerWidth) =>
|
|
139
142
|
(table: ContentNodeWithPos, view: EditorView | undefined) =>
|
|
140
143
|
(tr: Transaction): Transaction => {
|
|
141
|
-
|
|
142
|
-
// of columns here.
|
|
143
|
-
if (!view || !hasTableBeenResized(table.node)) {
|
|
144
|
+
if (!view) {
|
|
144
145
|
return tr;
|
|
145
146
|
}
|
|
146
147
|
|
|
148
|
+
const pos = table.pos;
|
|
149
|
+
const newTable = tr.doc.nodeAt(pos);
|
|
147
150
|
const { state } = view;
|
|
148
151
|
const domAtPos = view.domAtPos.bind(view);
|
|
149
|
-
|
|
150
152
|
const maybeTable = domAtPos(table.start).node as HTMLElement;
|
|
151
153
|
const tableRef = maybeTable.closest('table');
|
|
152
154
|
|
|
153
|
-
if (!tableRef) {
|
|
155
|
+
if (!tableRef || !newTable) {
|
|
154
156
|
return tr;
|
|
155
157
|
}
|
|
156
158
|
|
|
@@ -163,6 +165,57 @@ export const rescaleColumns =
|
|
|
163
165
|
layout,
|
|
164
166
|
getEditorContainerWidth,
|
|
165
167
|
});
|
|
168
|
+
|
|
169
|
+
const tableWidth = tableRef.clientWidth || akEditorDefaultLayoutWidth;
|
|
170
|
+
let tableMaxWidth = tableRef?.parentElement?.clientWidth || 0;
|
|
171
|
+
tableMaxWidth -= insertColumnButtonOffset;
|
|
172
|
+
const newTableMap = TableMap.get(newTable);
|
|
173
|
+
const noOfColumns = newTableMap.width;
|
|
174
|
+
if (!noOfColumns || noOfColumns <= 0) {
|
|
175
|
+
return tr;
|
|
176
|
+
}
|
|
177
|
+
const columnWidthUnresized = tableWidth / noOfColumns;
|
|
178
|
+
|
|
179
|
+
// If the table has not been resized, and the column width is bigger than the minimum column width
|
|
180
|
+
// we skip updating the size of columns here.
|
|
181
|
+
if (
|
|
182
|
+
!hasTableBeenResized(table.node) &&
|
|
183
|
+
columnWidthUnresized > tableCellMinWidth
|
|
184
|
+
) {
|
|
185
|
+
return tr;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// If the table has not been resized, and the column width is smaller than the minimum column width
|
|
189
|
+
// Or if the table has been resized, but each column width is either 48px or null
|
|
190
|
+
// we update the table to have 48px for each column
|
|
191
|
+
if (
|
|
192
|
+
(!hasTableBeenResized(table.node) &&
|
|
193
|
+
columnWidthUnresized <= tableCellMinWidth) ||
|
|
194
|
+
(hasTableBeenResized(table.node) && isMinCellWidthTable(table.node))
|
|
195
|
+
) {
|
|
196
|
+
const widths: Array<number> = new Array(noOfColumns).fill(
|
|
197
|
+
tableCellMinWidth,
|
|
198
|
+
);
|
|
199
|
+
const cols = widths.map((width, index) => ({
|
|
200
|
+
width: tableCellMinWidth,
|
|
201
|
+
minWidth: tableCellMinWidth,
|
|
202
|
+
index,
|
|
203
|
+
}));
|
|
204
|
+
const overflow = tableWidth > maxSize;
|
|
205
|
+
const minWidthResizeState = {
|
|
206
|
+
cols,
|
|
207
|
+
widths,
|
|
208
|
+
maxSize,
|
|
209
|
+
tableWidth,
|
|
210
|
+
overflow,
|
|
211
|
+
};
|
|
212
|
+
return updateColumnWidths(
|
|
213
|
+
minWidthResizeState,
|
|
214
|
+
table.node,
|
|
215
|
+
table.start,
|
|
216
|
+
)(tr);
|
|
217
|
+
}
|
|
218
|
+
|
|
166
219
|
let resizeState = getResizeState({
|
|
167
220
|
minWidth: tableCellMinWidth,
|
|
168
221
|
table: table.node,
|
|
@@ -172,7 +225,8 @@ export const rescaleColumns =
|
|
|
172
225
|
maxSize,
|
|
173
226
|
});
|
|
174
227
|
const previousTableWidth = resizeState.tableWidth - tableNewColumnMinWidth;
|
|
175
|
-
const tableDidntPreviouslyOverflow =
|
|
228
|
+
const tableDidntPreviouslyOverflow =
|
|
229
|
+
previousTableWidth <= Math.max(maxSize, tableMaxWidth);
|
|
176
230
|
|
|
177
231
|
// If the new table width will result in the table going into an overflow state
|
|
178
232
|
// we resize the cells to avoid the overflow occuring
|
|
@@ -73,7 +73,7 @@ const cornerControlHeight = tableToolbarSize + 1;
|
|
|
73
73
|
that is aligned to the right edge initially on hover of the top right column control when table overflown,
|
|
74
74
|
its center should be aligned with the edge
|
|
75
75
|
*/
|
|
76
|
-
const insertColumnButtonOffset = tableInsertColumnButtonSize / 2;
|
|
76
|
+
export const insertColumnButtonOffset = tableInsertColumnButtonSize / 2;
|
|
77
77
|
|
|
78
78
|
const rangeSelectionStyles = `
|
|
79
79
|
.${ClassName.NODEVIEW_WRAPPER}.${akEditorSelectedNodeClassName} table tbody tr {
|
|
@@ -615,6 +615,8 @@ export const tableStyles = (
|
|
|
615
615
|
table-layout: fixed;
|
|
616
616
|
white-space: normal;
|
|
617
617
|
border-top: none;
|
|
618
|
+
// 1px border width offset added here to prevent unwanted overflow and scolling - ED-16212
|
|
619
|
+
margin-right: -1px;
|
|
618
620
|
|
|
619
621
|
> tbody > tr {
|
|
620
622
|
white-space: pre-wrap;
|
|
@@ -737,7 +739,8 @@ export const tableStyles = (
|
|
|
737
739
|
export const tableFullPageEditorStyles = css`
|
|
738
740
|
.ProseMirror .${ClassName.TABLE_NODE_WRAPPER} > table {
|
|
739
741
|
margin-left: 0;
|
|
740
|
-
|
|
742
|
+
// 1px border width offset added here to prevent unwanted overflow and scolling - ED-16212
|
|
743
|
+
margin-right: -1px;
|
|
741
744
|
width: 100%;
|
|
742
745
|
}
|
|
743
746
|
`;
|