@atlaskit/editor-plugin-table 7.22.0 → 7.24.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 +39 -0
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/pm-plugins/main.js +1 -5
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +34 -19
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-logic.js +3 -0
- package/dist/cjs/toolbar.js +15 -12
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +14 -8
- package/dist/cjs/utils/create.js +1 -1
- package/dist/es2019/plugin.js +1 -1
- package/dist/es2019/pm-plugins/main.js +1 -5
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +41 -25
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-logic.js +1 -0
- package/dist/es2019/toolbar.js +15 -12
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +14 -8
- package/dist/es2019/utils/create.js +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/pm-plugins/main.js +1 -5
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +35 -21
- package/dist/esm/pm-plugins/table-resizing/utils/resize-logic.js +3 -0
- package/dist/esm/toolbar.js +15 -12
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +14 -8
- package/dist/esm/utils/create.js +1 -1
- package/dist/types/utils/analytics.d.ts +2 -1
- package/dist/types-ts4.5/utils/analytics.d.ts +2 -1
- package/package.json +16 -16
- package/src/plugin.tsx +1 -0
- package/src/pm-plugins/main.ts +1 -4
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +59 -31
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +1 -0
- package/src/toolbar.tsx +19 -14
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +20 -7
- package/src/utils/analytics.ts +6 -1
- package/src/utils/create.ts +1 -1
|
@@ -2,8 +2,8 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
// Resize a given column by an amount from the current state
|
|
5
|
-
|
|
6
|
-
import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
|
|
5
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
6
|
+
import { akEditorFullWidthLayoutWidth, akEditorGutterPaddingDynamic, akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
7
7
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
8
8
|
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
9
9
|
import { getTableScalingPercent } from './misc';
|
|
@@ -33,17 +33,18 @@ export var resizeColumnAndTable = function resizeColumnAndTable(_ref) {
|
|
|
33
33
|
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled;
|
|
34
34
|
var editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
35
35
|
var isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
|
|
36
|
+
var isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
|
|
37
|
+
var isOverflow = resizeState.tableWidth > resizeState.maxSize;
|
|
36
38
|
var resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
37
39
|
var willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
38
|
-
var willResizedTableStayInOverflow =
|
|
40
|
+
var willResizedTableStayInOverflow = isOverflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
39
41
|
|
|
40
42
|
// STEP 1: Update col width
|
|
41
43
|
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
42
44
|
var _tableRef$closest;
|
|
43
45
|
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
44
46
|
resizeAmount = amount < 0 ? amount : resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth) / 2;
|
|
45
|
-
}
|
|
46
|
-
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
47
|
+
} else {
|
|
47
48
|
var diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
48
49
|
var rest = amount - diff;
|
|
49
50
|
var final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
@@ -54,25 +55,23 @@ export var resizeColumnAndTable = function resizeColumnAndTable(_ref) {
|
|
|
54
55
|
// STEP 2: Update table container width
|
|
55
56
|
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
56
57
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
57
|
-
newState.maxSize = Math.round(
|
|
58
|
+
newState.maxSize = Math.round(isOverflow ? willResizedTableStayInOverflow ?
|
|
58
59
|
// CASE 1A: table will stay in overflow
|
|
59
60
|
// do not grow the table because resize is happening in the overflow region
|
|
60
61
|
// and the overall table container needs to be retained
|
|
61
|
-
resizeState.maxSize :
|
|
62
|
+
isNumberColumnEnabled ? resizeState.maxSize + akEditorTableNumberColumnWidth : resizeState.maxSize :
|
|
62
63
|
// CASE 1B: table will no longer be in overflow, so adjust container width
|
|
63
64
|
// ensure the table is resized without any 'big jumps' by working out
|
|
64
65
|
// the difference between the new table width and the max size and adding the resize
|
|
65
|
-
resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
66
|
+
isNumberColumnEnabled ? resizeState.maxSize + akEditorTableNumberColumnWidth + (resizeState.tableWidth - resizeState.maxSize + akEditorTableNumberColumnWidth + delta) : resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta) : willTableHitEditorEdge ?
|
|
66
67
|
// CASE 2: table will hit editor edge
|
|
67
68
|
editorContainerWidth :
|
|
68
69
|
// CASE 3: table is being resized from a non-overflow state
|
|
69
|
-
resizeState.maxSize + delta);
|
|
70
|
+
isNumberColumnEnabled ? resizeState.maxSize + akEditorTableNumberColumnWidth + delta : resizeState.maxSize + delta);
|
|
70
71
|
|
|
71
72
|
// do not apply scaling logic because resize state is already scaled
|
|
72
73
|
updateColgroup(newState, tableRef, tableNode, false, false);
|
|
73
|
-
|
|
74
|
-
updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
75
|
-
}
|
|
74
|
+
updateTablePreview(tableRef, newState.maxSize, shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.maxSize));
|
|
76
75
|
return newState;
|
|
77
76
|
};
|
|
78
77
|
var updateTablePreview = function updateTablePreview(tableRef, newTableWidth, shouldChangeAlignment) {
|
|
@@ -100,37 +99,52 @@ export var scaleResizeState = function scaleResizeState(_ref2) {
|
|
|
100
99
|
tableRef = _ref2.tableRef,
|
|
101
100
|
tableNode = _ref2.tableNode,
|
|
102
101
|
editorWidth = _ref2.editorWidth;
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
var isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
|
|
103
|
+
var isTableScaled = isNumberColumnEnabled || resizeState.maxSize > getEditorContainerWidth(editorWidth);
|
|
104
|
+
|
|
105
|
+
// Tables with number column can cause the table to be in two different states:
|
|
106
|
+
// 1. The table sum of col widths will be smaller than the max size, which is incorrect. For this
|
|
107
|
+
// avoid scaling and take the document width
|
|
108
|
+
// 2. The table sum of col widths will be the same size as max width, which happens when the table
|
|
109
|
+
// is scaled using preserve table width logic, for this apply a scaled width
|
|
110
|
+
// return early if table isn't scaled
|
|
111
|
+
if (!isTableScaled || isNumberColumnEnabled && resizeState.maxSize > resizeState.tableWidth) {
|
|
105
112
|
return resizeState;
|
|
106
113
|
}
|
|
107
114
|
var scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
115
|
+
var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
108
116
|
var cols = resizeState.cols.map(function (col) {
|
|
109
117
|
return _objectSpread(_objectSpread({}, col), {}, {
|
|
110
|
-
|
|
118
|
+
minWidth: tableCellMinWidth,
|
|
119
|
+
width: Math.max(Math.round(col.width * scalePercent), tableCellMinWidth)
|
|
111
120
|
});
|
|
112
121
|
});
|
|
113
|
-
var scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
114
122
|
var calculatedTableWidth = cols.reduce(function (prev, curr) {
|
|
115
123
|
return prev + curr.width;
|
|
116
124
|
}, 0);
|
|
117
125
|
|
|
118
126
|
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
119
|
-
// distribute the difference to the
|
|
127
|
+
// distribute the difference to the first column
|
|
120
128
|
if (calculatedTableWidth > scaledTableWidth) {
|
|
121
129
|
var diff = calculatedTableWidth - scaledTableWidth;
|
|
130
|
+
var hasDiffBeenDistributed = false;
|
|
122
131
|
cols = cols.map(function (col) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
132
|
+
if (!hasDiffBeenDistributed && col.width - diff >= col.minWidth) {
|
|
133
|
+
hasDiffBeenDistributed = true;
|
|
134
|
+
return _objectSpread(_objectSpread({}, col), {}, {
|
|
135
|
+
width: col.width - diff
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return col;
|
|
126
139
|
});
|
|
127
140
|
}
|
|
141
|
+
var maxSize = isNumberColumnEnabled ? Math.round((resizeState.maxSize + akEditorTableNumberColumnWidth) * scalePercent) : Math.round(resizeState.maxSize * scalePercent);
|
|
128
142
|
return _objectSpread(_objectSpread({}, resizeState), {}, {
|
|
129
143
|
widths: cols.map(function (col) {
|
|
130
144
|
return col.width;
|
|
131
145
|
}),
|
|
132
146
|
tableWidth: scaledTableWidth,
|
|
133
|
-
maxSize:
|
|
147
|
+
maxSize: maxSize,
|
|
134
148
|
cols: cols
|
|
135
149
|
});
|
|
136
150
|
};
|
|
@@ -231,6 +231,9 @@ export function updateAffectedColumn(resizeState, colIndex, resizeAmount) {
|
|
|
231
231
|
return col;
|
|
232
232
|
});
|
|
233
233
|
return _objectSpread(_objectSpread({}, resizeState), {}, {
|
|
234
|
+
tableWidth: updatedCols.reduce(function (acc, col) {
|
|
235
|
+
return acc + col.width;
|
|
236
|
+
}, 0),
|
|
234
237
|
cols: updatedCols
|
|
235
238
|
});
|
|
236
239
|
}
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -209,19 +209,22 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
|
|
|
209
209
|
onMouseLeave: clearHoverSelection(),
|
|
210
210
|
selected: false,
|
|
211
211
|
disabled: false
|
|
212
|
-
}, {
|
|
213
|
-
id: 'editor.table.mergeCells',
|
|
214
|
-
title: formatMessage(messages.mergeCells),
|
|
215
|
-
onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
216
|
-
selected: false,
|
|
217
|
-
disabled: !canMergeCells(editorState.tr)
|
|
218
|
-
}, {
|
|
219
|
-
id: 'editor.table.splitCell',
|
|
220
|
-
title: formatMessage(messages.splitCell),
|
|
221
|
-
onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
222
|
-
selected: false,
|
|
223
|
-
disabled: !splitCell(editorState)
|
|
224
212
|
}];
|
|
213
|
+
if (pluginState.pluginConfig.allowMergeCells) {
|
|
214
|
+
options.push({
|
|
215
|
+
id: 'editor.table.mergeCells',
|
|
216
|
+
title: formatMessage(messages.mergeCells),
|
|
217
|
+
onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
218
|
+
selected: false,
|
|
219
|
+
disabled: !canMergeCells(editorState.tr)
|
|
220
|
+
}, {
|
|
221
|
+
id: 'editor.table.splitCell',
|
|
222
|
+
title: formatMessage(messages.splitCell),
|
|
223
|
+
onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
224
|
+
selected: false,
|
|
225
|
+
disabled: !splitCell(editorState)
|
|
226
|
+
});
|
|
227
|
+
}
|
|
225
228
|
if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo = pluginState.pluginConfig) !== null && _pluginState$pluginCo !== void 0 && _pluginState$pluginCo.allowDistributeColumns) {
|
|
226
229
|
var _newResizeStateWithAn;
|
|
227
230
|
var newResizeStateWithAnalytics = editorView ? getNewResizeStateFromSelectedColumns(initialSelectionRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled) : undefined;
|
|
@@ -208,8 +208,9 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
208
208
|
editorView = _this$props3.editorView;
|
|
209
209
|
var _getPluginState3 = getPluginState(editorView.state),
|
|
210
210
|
isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled;
|
|
211
|
+
var content = formatMessage(isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn);
|
|
211
212
|
return {
|
|
212
|
-
content:
|
|
213
|
+
content: content,
|
|
213
214
|
value: {
|
|
214
215
|
name: 'insert_column'
|
|
215
216
|
},
|
|
@@ -221,7 +222,8 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
221
222
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
222
223
|
jsx("span", {
|
|
223
224
|
css: elementBeforeIconStyles
|
|
224
|
-
}, jsx(AddColRightIcon, null)) : undefined
|
|
225
|
+
}, jsx(AddColRightIcon, null)) : undefined,
|
|
226
|
+
'aria-label': fg('platform_editor_announce_cell_options_hotkeys') ? tooltip(addColumnAfter, String(content)) : undefined
|
|
225
227
|
};
|
|
226
228
|
});
|
|
227
229
|
_defineProperty(_assertThisInitialized(_this), "createInsertRowItem", function () {
|
|
@@ -230,8 +232,9 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
230
232
|
editorView = _this$props4.editorView;
|
|
231
233
|
var _getPluginState4 = getPluginState(editorView.state),
|
|
232
234
|
isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled;
|
|
235
|
+
var content = formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow);
|
|
233
236
|
return {
|
|
234
|
-
content:
|
|
237
|
+
content: content,
|
|
235
238
|
value: {
|
|
236
239
|
name: 'insert_row'
|
|
237
240
|
},
|
|
@@ -243,7 +246,8 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
243
246
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
244
247
|
jsx("span", {
|
|
245
248
|
css: elementBeforeIconStyles
|
|
246
|
-
}, jsx(AddRowBelowIcon, null)) : undefined
|
|
249
|
+
}, jsx(AddRowBelowIcon, null)) : undefined,
|
|
250
|
+
'aria-label': fg('platform_editor_announce_cell_options_hotkeys') ? tooltip(addRowAfter, String(content)) : undefined
|
|
247
251
|
};
|
|
248
252
|
});
|
|
249
253
|
_defineProperty(_assertThisInitialized(_this), "createClearCellsItem", function () {
|
|
@@ -259,10 +263,11 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
259
263
|
left = selectionRect.left;
|
|
260
264
|
var noOfColumns = right - left;
|
|
261
265
|
var noOfRows = bottom - top;
|
|
266
|
+
var content = formatMessage(messages.clearCells, {
|
|
267
|
+
0: Math.max(noOfColumns, noOfRows)
|
|
268
|
+
});
|
|
262
269
|
return {
|
|
263
|
-
content:
|
|
264
|
-
0: Math.max(noOfColumns, noOfRows)
|
|
265
|
-
}),
|
|
270
|
+
content: content,
|
|
266
271
|
value: {
|
|
267
272
|
name: 'clear'
|
|
268
273
|
},
|
|
@@ -278,7 +283,8 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
278
283
|
label: formatMessage(messages.clearCells, {
|
|
279
284
|
0: Math.max(noOfColumns, noOfRows)
|
|
280
285
|
})
|
|
281
|
-
})) : undefined
|
|
286
|
+
})) : undefined,
|
|
287
|
+
'aria-label': fg('platform_editor_announce_cell_options_hotkeys') ? tooltip(backspace, String(content)) : undefined
|
|
282
288
|
};
|
|
283
289
|
});
|
|
284
290
|
_defineProperty(_assertThisInitialized(_this), "createDeleteColumnItem", function () {
|
package/dist/esm/utils/create.js
CHANGED
|
@@ -15,7 +15,7 @@ export var createTableWithWidth = function createTableWithWidth(_ref) {
|
|
|
15
15
|
if (isTableScalingEnabled && isFullWidthModeEnabled && !isCommentEditor) {
|
|
16
16
|
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
17
17
|
}
|
|
18
|
-
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
18
|
+
if (isTableAlignmentEnabled && (isFullWidthModeEnabled || isCommentEditor)) {
|
|
19
19
|
attrsOverrides.layout = 'align-start';
|
|
20
20
|
}
|
|
21
21
|
if (isCommentEditor && isTableResizingEnabled) {
|
|
@@ -3,8 +3,9 @@ import type { HigherOrderCommand } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
6
7
|
export declare function getSelectedTableInfo(selection: Selection): {
|
|
7
|
-
table:
|
|
8
|
+
table: ReturnType<typeof findTable> | undefined;
|
|
8
9
|
map: TableMap | undefined;
|
|
9
10
|
totalRowCount: number;
|
|
10
11
|
totalColumnCount: number;
|
|
@@ -3,8 +3,9 @@ import type { HigherOrderCommand } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
6
7
|
export declare function getSelectedTableInfo(selection: Selection): {
|
|
7
|
-
table:
|
|
8
|
+
table: ReturnType<typeof findTable> | undefined;
|
|
8
9
|
map: TableMap | undefined;
|
|
9
10
|
totalRowCount: number;
|
|
10
11
|
totalColumnCount: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.24.0",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,26 +30,26 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^40.3.0",
|
|
32
32
|
"@atlaskit/button": "^19.1.0",
|
|
33
|
-
"@atlaskit/custom-steps": "^0.
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
33
|
+
"@atlaskit/custom-steps": "^0.6.0",
|
|
34
|
+
"@atlaskit/editor-common": "^87.0.0",
|
|
35
35
|
"@atlaskit/editor-palette": "1.6.0",
|
|
36
|
-
"@atlaskit/editor-plugin-accessibility-utils": "^1.
|
|
37
|
-
"@atlaskit/editor-plugin-analytics": "^1.
|
|
38
|
-
"@atlaskit/editor-plugin-content-insertion": "^1.
|
|
39
|
-
"@atlaskit/editor-plugin-editor-viewmode": "^2.
|
|
40
|
-
"@atlaskit/editor-plugin-guideline": "^1.
|
|
41
|
-
"@atlaskit/editor-plugin-selection": "^1.
|
|
42
|
-
"@atlaskit/editor-plugin-width": "^1.
|
|
43
|
-
"@atlaskit/editor-prosemirror": "
|
|
36
|
+
"@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
|
|
37
|
+
"@atlaskit/editor-plugin-analytics": "^1.6.0",
|
|
38
|
+
"@atlaskit/editor-plugin-content-insertion": "^1.6.0",
|
|
39
|
+
"@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
|
|
40
|
+
"@atlaskit/editor-plugin-guideline": "^1.2.0",
|
|
41
|
+
"@atlaskit/editor-plugin-selection": "^1.3.0",
|
|
42
|
+
"@atlaskit/editor-plugin-width": "^1.2.0",
|
|
43
|
+
"@atlaskit/editor-prosemirror": "5.0.1",
|
|
44
44
|
"@atlaskit/editor-shared-styles": "^2.13.0",
|
|
45
|
-
"@atlaskit/editor-tables": "^2.
|
|
45
|
+
"@atlaskit/editor-tables": "^2.8.0",
|
|
46
46
|
"@atlaskit/icon": "^22.7.0",
|
|
47
47
|
"@atlaskit/menu": "^2.8.0",
|
|
48
48
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
49
49
|
"@atlaskit/pragmatic-drag-and-drop": "^1.2.0",
|
|
50
50
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
|
|
51
51
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
|
|
52
|
-
"@atlaskit/primitives": "^11.
|
|
52
|
+
"@atlaskit/primitives": "^11.1.0",
|
|
53
53
|
"@atlaskit/theme": "^12.11.0",
|
|
54
54
|
"@atlaskit/toggle": "^13.2.0",
|
|
55
55
|
"@atlaskit/tokens": "^1.56.0",
|
|
@@ -105,9 +105,6 @@
|
|
|
105
105
|
"platform_editor_lazy-node-views": {
|
|
106
106
|
"type": "boolean"
|
|
107
107
|
},
|
|
108
|
-
"platform.editor.transform-slice-for-nested-expand": {
|
|
109
|
-
"type": "boolean"
|
|
110
|
-
},
|
|
111
108
|
"platform.editor.table.use-shared-state-hook": {
|
|
112
109
|
"type": "boolean"
|
|
113
110
|
},
|
|
@@ -125,6 +122,9 @@
|
|
|
125
122
|
},
|
|
126
123
|
"platform_editor_a11y_table_context_menu": {
|
|
127
124
|
"type": "boolean"
|
|
125
|
+
},
|
|
126
|
+
"platform_editor_announce_cell_options_hotkeys": {
|
|
127
|
+
"type": "boolean"
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
package/src/plugin.tsx
CHANGED
package/src/pm-plugins/main.ts
CHANGED
|
@@ -294,10 +294,7 @@ export const createPlugin = (
|
|
|
294
294
|
slice = transformSliceRemoveCellBackgroundColor(slice, schema);
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
|
|
298
|
-
if (fg('platform.editor.transform-slice-for-nested-expand')) {
|
|
299
|
-
slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
|
|
300
|
-
}
|
|
297
|
+
slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
|
|
301
298
|
|
|
302
299
|
return slice;
|
|
303
300
|
},
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
3
|
import { type EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
5
|
import {
|
|
5
6
|
akEditorFullWidthLayoutWidth,
|
|
6
7
|
akEditorGutterPaddingDynamic,
|
|
8
|
+
akEditorTableNumberColumnWidth,
|
|
7
9
|
} from '@atlaskit/editor-shared-styles';
|
|
8
10
|
|
|
9
11
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
@@ -86,12 +88,13 @@ export const resizeColumnAndTable = ({
|
|
|
86
88
|
}: ResizeColumnAndTable): ResizeState => {
|
|
87
89
|
const editorContainerWidth = getEditorContainerWidth(editorWidth);
|
|
88
90
|
const isTableLeftAligned = tableNode.attrs.layout === ALIGN_START;
|
|
91
|
+
const isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
|
|
92
|
+
const isOverflow = resizeState.tableWidth > resizeState.maxSize;
|
|
89
93
|
let resizeAmount = isTableLeftAligned ? amount : amount * 2;
|
|
90
|
-
|
|
91
94
|
const willTableHitEditorEdge = resizeState.maxSize + resizeAmount > editorContainerWidth;
|
|
92
95
|
|
|
93
96
|
const willResizedTableStayInOverflow =
|
|
94
|
-
|
|
97
|
+
isOverflow && resizeState.tableWidth + resizeAmount / 2 > resizeState.maxSize;
|
|
95
98
|
|
|
96
99
|
// STEP 1: Update col width
|
|
97
100
|
if (willTableHitEditorEdge || willResizedTableStayInOverflow) {
|
|
@@ -100,54 +103,58 @@ export const resizeColumnAndTable = ({
|
|
|
100
103
|
amount < 0
|
|
101
104
|
? amount
|
|
102
105
|
: resizeAmount - (resizeState.maxSize + resizeAmount - tableContainerWidth!) / 2;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!willResizedTableStayInOverflow && !willTableHitEditorEdge) {
|
|
106
|
+
} else {
|
|
106
107
|
const diff = -(resizeState.tableWidth - resizeState.maxSize);
|
|
107
108
|
const rest = amount - diff;
|
|
108
109
|
const final = isTableLeftAligned ? diff + rest : diff + rest * 2;
|
|
109
110
|
resizeAmount = final;
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
const newState = updateAffectedColumn(resizeState, colIndex, resizeAmount);
|
|
113
114
|
|
|
114
115
|
// STEP 2: Update table container width
|
|
115
116
|
// columns have a min width, so delta !== resizeAmount when this is reached, use this for calculations
|
|
116
117
|
const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
117
118
|
|
|
118
119
|
newState.maxSize = Math.round(
|
|
119
|
-
|
|
120
|
+
isOverflow
|
|
120
121
|
? willResizedTableStayInOverflow
|
|
121
122
|
? // CASE 1A: table will stay in overflow
|
|
122
123
|
// do not grow the table because resize is happening in the overflow region
|
|
123
124
|
// and the overall table container needs to be retained
|
|
124
|
-
|
|
125
|
+
isNumberColumnEnabled
|
|
126
|
+
? resizeState.maxSize + akEditorTableNumberColumnWidth
|
|
127
|
+
: resizeState.maxSize
|
|
125
128
|
: // CASE 1B: table will no longer be in overflow, so adjust container width
|
|
126
129
|
// ensure the table is resized without any 'big jumps' by working out
|
|
127
130
|
// the difference between the new table width and the max size and adding the resize
|
|
128
|
-
|
|
131
|
+
isNumberColumnEnabled
|
|
132
|
+
? resizeState.maxSize +
|
|
133
|
+
akEditorTableNumberColumnWidth +
|
|
134
|
+
(resizeState.tableWidth - resizeState.maxSize + akEditorTableNumberColumnWidth + delta)
|
|
135
|
+
: resizeState.maxSize + (resizeState.tableWidth - resizeState.maxSize + delta)
|
|
129
136
|
: willTableHitEditorEdge
|
|
130
137
|
? // CASE 2: table will hit editor edge
|
|
131
138
|
editorContainerWidth
|
|
132
139
|
: // CASE 3: table is being resized from a non-overflow state
|
|
133
|
-
|
|
140
|
+
isNumberColumnEnabled
|
|
141
|
+
? resizeState.maxSize + akEditorTableNumberColumnWidth + delta
|
|
142
|
+
: resizeState.maxSize + delta,
|
|
134
143
|
);
|
|
135
144
|
|
|
136
145
|
// do not apply scaling logic because resize state is already scaled
|
|
137
146
|
updateColgroup(newState, tableRef, tableNode, false, false);
|
|
138
147
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
updateTablePreview(
|
|
149
|
+
tableRef,
|
|
150
|
+
newState.maxSize,
|
|
151
|
+
shouldChangeAlignmentToCenterResized(
|
|
152
|
+
isTableAlignmentEnabled,
|
|
153
|
+
tableNode,
|
|
154
|
+
lineLength,
|
|
142
155
|
newState.maxSize,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
tableNode,
|
|
146
|
-
lineLength,
|
|
147
|
-
newState.maxSize,
|
|
148
|
-
),
|
|
149
|
-
);
|
|
150
|
-
}
|
|
156
|
+
),
|
|
157
|
+
);
|
|
151
158
|
|
|
152
159
|
return newState;
|
|
153
160
|
};
|
|
@@ -184,34 +191,55 @@ export const scaleResizeState = ({
|
|
|
184
191
|
tableNode,
|
|
185
192
|
editorWidth,
|
|
186
193
|
}: TableReferences & { resizeState: ResizeState; editorWidth: number }): ResizeState => {
|
|
187
|
-
|
|
188
|
-
|
|
194
|
+
const isNumberColumnEnabled = tableNode.attrs.isNumberColumnEnabled;
|
|
195
|
+
const isTableScaled =
|
|
196
|
+
isNumberColumnEnabled || resizeState.maxSize > getEditorContainerWidth(editorWidth);
|
|
197
|
+
|
|
198
|
+
// Tables with number column can cause the table to be in two different states:
|
|
199
|
+
// 1. The table sum of col widths will be smaller than the max size, which is incorrect. For this
|
|
200
|
+
// avoid scaling and take the document width
|
|
201
|
+
// 2. The table sum of col widths will be the same size as max width, which happens when the table
|
|
202
|
+
// is scaled using preserve table width logic, for this apply a scaled width
|
|
203
|
+
// return early if table isn't scaled
|
|
204
|
+
if (!isTableScaled || (isNumberColumnEnabled && resizeState.maxSize > resizeState.tableWidth)) {
|
|
189
205
|
return resizeState;
|
|
190
206
|
}
|
|
191
207
|
|
|
192
208
|
const scalePercent = getTableScalingPercent(tableNode, tableRef);
|
|
193
|
-
let cols = resizeState.cols.map((col) => ({
|
|
194
|
-
...col,
|
|
195
|
-
width: Math.round(Math.max(col.width * scalePercent, col.minWidth)),
|
|
196
|
-
}));
|
|
197
|
-
|
|
198
209
|
const scaledTableWidth = Math.round(resizeState.tableWidth * scalePercent);
|
|
210
|
+
let cols = resizeState.cols.map((col) => {
|
|
211
|
+
return {
|
|
212
|
+
...col,
|
|
213
|
+
minWidth: tableCellMinWidth,
|
|
214
|
+
width: Math.max(Math.round(col.width * scalePercent), tableCellMinWidth),
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
|
|
199
218
|
const calculatedTableWidth = cols.reduce((prev, curr) => prev + curr.width, 0);
|
|
200
219
|
|
|
201
220
|
// using Math.round can cause the sum of col widths to be larger than the table width
|
|
202
|
-
// distribute the difference to the
|
|
221
|
+
// distribute the difference to the first column
|
|
203
222
|
if (calculatedTableWidth > scaledTableWidth) {
|
|
204
223
|
const diff = calculatedTableWidth - scaledTableWidth;
|
|
224
|
+
let hasDiffBeenDistributed = false;
|
|
205
225
|
cols = cols.map((col) => {
|
|
206
|
-
|
|
226
|
+
if (!hasDiffBeenDistributed && col.width - diff >= col.minWidth) {
|
|
227
|
+
hasDiffBeenDistributed = true;
|
|
228
|
+
return { ...col, width: col.width - diff };
|
|
229
|
+
}
|
|
230
|
+
return col;
|
|
207
231
|
});
|
|
208
232
|
}
|
|
209
233
|
|
|
234
|
+
const maxSize = isNumberColumnEnabled
|
|
235
|
+
? Math.round((resizeState.maxSize + akEditorTableNumberColumnWidth) * scalePercent)
|
|
236
|
+
: Math.round(resizeState.maxSize * scalePercent);
|
|
237
|
+
|
|
210
238
|
return {
|
|
211
239
|
...resizeState,
|
|
212
240
|
widths: cols.map((col) => col.width),
|
|
213
241
|
tableWidth: scaledTableWidth,
|
|
214
|
-
maxSize
|
|
242
|
+
maxSize,
|
|
215
243
|
cols,
|
|
216
244
|
};
|
|
217
245
|
};
|
package/src/toolbar.tsx
CHANGED
|
@@ -292,22 +292,27 @@ export const getToolbarCellOptionsConfig = (
|
|
|
292
292
|
selected: false,
|
|
293
293
|
disabled: false,
|
|
294
294
|
},
|
|
295
|
-
{
|
|
296
|
-
id: 'editor.table.mergeCells',
|
|
297
|
-
title: formatMessage(messages.mergeCells),
|
|
298
|
-
onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
299
|
-
selected: false,
|
|
300
|
-
disabled: !canMergeCells(editorState.tr),
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
id: 'editor.table.splitCell',
|
|
304
|
-
title: formatMessage(messages.splitCell),
|
|
305
|
-
onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
306
|
-
selected: false,
|
|
307
|
-
disabled: !splitCell(editorState),
|
|
308
|
-
},
|
|
309
295
|
];
|
|
310
296
|
|
|
297
|
+
if (pluginState.pluginConfig.allowMergeCells) {
|
|
298
|
+
options.push(
|
|
299
|
+
{
|
|
300
|
+
id: 'editor.table.mergeCells',
|
|
301
|
+
title: formatMessage(messages.mergeCells),
|
|
302
|
+
onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
303
|
+
selected: false,
|
|
304
|
+
disabled: !canMergeCells(editorState.tr),
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
id: 'editor.table.splitCell',
|
|
308
|
+
title: formatMessage(messages.splitCell),
|
|
309
|
+
onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
|
|
310
|
+
selected: false,
|
|
311
|
+
disabled: !splitCell(editorState),
|
|
312
|
+
},
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
311
316
|
if (pluginState?.pluginConfig?.allowDistributeColumns) {
|
|
312
317
|
const newResizeStateWithAnalytics = editorView
|
|
313
318
|
? getNewResizeStateFromSelectedColumns(
|
|
@@ -370,11 +370,12 @@ export class ContextualMenu extends Component<Props & WrappedComponentProps, Sta
|
|
|
370
370
|
editorView,
|
|
371
371
|
} = this.props;
|
|
372
372
|
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
373
|
+
const content = formatMessage(
|
|
374
|
+
isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn,
|
|
375
|
+
);
|
|
373
376
|
|
|
374
377
|
return {
|
|
375
|
-
content
|
|
376
|
-
isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn,
|
|
377
|
-
),
|
|
378
|
+
content,
|
|
378
379
|
value: { name: 'insert_column' },
|
|
379
380
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
380
381
|
elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
|
|
@@ -384,6 +385,9 @@ export class ContextualMenu extends Component<Props & WrappedComponentProps, Sta
|
|
|
384
385
|
<AddColRightIcon />
|
|
385
386
|
</span>
|
|
386
387
|
) : undefined,
|
|
388
|
+
'aria-label': fg('platform_editor_announce_cell_options_hotkeys')
|
|
389
|
+
? tooltip(addColumnAfter, String(content))
|
|
390
|
+
: undefined,
|
|
387
391
|
} as MenuItem;
|
|
388
392
|
};
|
|
389
393
|
|
|
@@ -393,9 +397,10 @@ export class ContextualMenu extends Component<Props & WrappedComponentProps, Sta
|
|
|
393
397
|
editorView,
|
|
394
398
|
} = this.props;
|
|
395
399
|
const { isDragAndDropEnabled } = getPluginState(editorView.state);
|
|
400
|
+
const content = formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow);
|
|
396
401
|
|
|
397
402
|
return {
|
|
398
|
-
content
|
|
403
|
+
content,
|
|
399
404
|
value: { name: 'insert_row' },
|
|
400
405
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
401
406
|
elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
|
|
@@ -405,6 +410,9 @@ export class ContextualMenu extends Component<Props & WrappedComponentProps, Sta
|
|
|
405
410
|
<AddRowBelowIcon />
|
|
406
411
|
</span>
|
|
407
412
|
) : undefined,
|
|
413
|
+
'aria-label': fg('platform_editor_announce_cell_options_hotkeys')
|
|
414
|
+
? tooltip(addRowAfter, String(content))
|
|
415
|
+
: undefined,
|
|
408
416
|
} as MenuItem;
|
|
409
417
|
};
|
|
410
418
|
|
|
@@ -419,10 +427,12 @@ export class ContextualMenu extends Component<Props & WrappedComponentProps, Sta
|
|
|
419
427
|
const noOfColumns = right - left;
|
|
420
428
|
const noOfRows = bottom - top;
|
|
421
429
|
|
|
430
|
+
const content = formatMessage(messages.clearCells, {
|
|
431
|
+
0: Math.max(noOfColumns, noOfRows),
|
|
432
|
+
});
|
|
433
|
+
|
|
422
434
|
return {
|
|
423
|
-
content
|
|
424
|
-
0: Math.max(noOfColumns, noOfRows),
|
|
425
|
-
}),
|
|
435
|
+
content,
|
|
426
436
|
value: { name: 'clear' },
|
|
427
437
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
428
438
|
elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
|
|
@@ -436,6 +446,9 @@ export class ContextualMenu extends Component<Props & WrappedComponentProps, Sta
|
|
|
436
446
|
/>
|
|
437
447
|
</span>
|
|
438
448
|
) : undefined,
|
|
449
|
+
'aria-label': fg('platform_editor_announce_cell_options_hotkeys')
|
|
450
|
+
? tooltip(backspace, String(content))
|
|
451
|
+
: undefined,
|
|
439
452
|
} as MenuItem;
|
|
440
453
|
};
|
|
441
454
|
|