@atlaskit/editor-plugin-table 5.5.10 → 5.5.12
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 +14 -0
- package/dist/cjs/plugins/table/commands/insert.js +17 -2
- package/dist/cjs/plugins/table/commands/misc.js +3 -3
- package/dist/cjs/plugins/table/index.js +5 -1
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +12 -0
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -1
- package/dist/cjs/plugins/table/utils/drag-menu.js +2 -1
- package/dist/es2019/plugins/table/commands/insert.js +15 -1
- package/dist/es2019/plugins/table/commands/misc.js +3 -3
- package/dist/es2019/plugins/table/index.js +5 -1
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +13 -0
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/es2019/plugins/table/utils/drag-menu.js +2 -1
- package/dist/esm/plugins/table/commands/insert.js +16 -1
- package/dist/esm/plugins/table/commands/misc.js +3 -3
- package/dist/esm/plugins/table/index.js +5 -1
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +12 -0
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/esm/plugins/table/utils/drag-menu.js +2 -1
- package/dist/types/plugins/table/commands/insert.d.ts +3 -1
- package/dist/types/plugins/table/index.d.ts +5 -1
- package/dist/types/plugins/table/utils/drag-menu.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/commands/insert.d.ts +3 -1
- package/dist/types-ts4.5/plugins/table/index.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +1 -1
- package/package.json +3 -3
- package/src/plugins/table/commands/insert.ts +26 -0
- package/src/plugins/table/commands/misc.ts +4 -3
- package/src/plugins/table/index.tsx +16 -0
- package/src/plugins/table/pm-plugins/analytics/plugin.ts +1 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +12 -0
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +4 -0
- package/src/plugins/table/utils/drag-menu.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.5.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#60612](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/60612) [`7edc766361a2`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7edc766361a2) - Created an EditorCommad on table plugin to insert a table of custom size
|
|
8
|
+
|
|
9
|
+
## 5.5.11
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#60830](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/60830) [`5472a318103f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5472a318103f) - force colgroup to update after column drop to ensure the correct column width is shown
|
|
14
|
+
- [#60767](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/60767) [`737f3666a35d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/737f3666a35d) - Ensure the target that is being pasted is a table
|
|
15
|
+
- [#60717](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/60717) [`15f7bd8c548a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/15f7bd8c548a) - disable sort in drag menu when there is merged cell in table
|
|
16
|
+
|
|
3
17
|
## 5.5.10
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.addColumnAfter = void 0;
|
|
7
7
|
exports.addColumnAt = addColumnAt;
|
|
8
|
-
exports.insertRow = exports.insertColumn = exports.createTable = exports.addColumnBefore = void 0;
|
|
8
|
+
exports.insertTableWithSize = exports.insertRow = exports.insertColumn = exports.createTable = exports.addColumnBefore = void 0;
|
|
9
9
|
var _customSteps = require("@atlaskit/custom-steps");
|
|
10
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
@@ -154,4 +154,19 @@ var createTable = exports.createTable = function createTable() {
|
|
|
154
154
|
return true;
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
|
-
// #endregion
|
|
157
|
+
// #endregion
|
|
158
|
+
|
|
159
|
+
var insertTableWithSize = exports.insertTableWithSize = function insertTableWithSize(editorAnalyticsAPI) {
|
|
160
|
+
return function (rowsCount, colsCount, inputMethod) {
|
|
161
|
+
return function (_ref) {
|
|
162
|
+
var tr = _ref.tr;
|
|
163
|
+
var tableNode = (0, _utils2.createTable)({
|
|
164
|
+
schema: tr.doc.type.schema,
|
|
165
|
+
rowsCount: rowsCount,
|
|
166
|
+
colsCount: colsCount
|
|
167
|
+
});
|
|
168
|
+
var newTr = (0, _utils.safeInsert)(tableNode)(tr).scrollIntoView();
|
|
169
|
+
return newTr;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
@@ -185,17 +185,17 @@ var getTableElementMoveTypeBySlice = exports.getTableElementMoveTypeBySlice = fu
|
|
|
185
185
|
var _state$schema$nodes = state.schema.nodes,
|
|
186
186
|
tableRow = _state$schema$nodes.tableRow,
|
|
187
187
|
table = _state$schema$nodes.table;
|
|
188
|
+
var currentTable = (0, _utils2.findTable)(state.tr.selection);
|
|
188
189
|
|
|
189
190
|
// check if copied slice is a table or table row
|
|
190
|
-
if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
|
|
191
|
-
return;
|
|
191
|
+
if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow || !currentTable) {
|
|
192
|
+
return undefined;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
// if the slice only contains one table row, assume it's a row
|
|
195
196
|
if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
|
|
196
197
|
return 'row';
|
|
197
198
|
}
|
|
198
|
-
var currentTable = (0, _utils2.findTable)(state.tr.selection);
|
|
199
199
|
var map = _tableMap.TableMap.get(currentTable.node);
|
|
200
200
|
var slicedMap = _tableMap.TableMap.get(slice.content.firstChild);
|
|
201
201
|
return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
|
|
@@ -18,6 +18,7 @@ var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
|
|
|
18
18
|
var _pmPlugins = require("@atlaskit/editor-tables/pm-plugins");
|
|
19
19
|
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
20
20
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
21
|
+
var _insert = require("./commands/insert");
|
|
21
22
|
var _createPluginConfig = require("./create-plugin-config");
|
|
22
23
|
var _plugin = require("./pm-plugins/analytics/plugin");
|
|
23
24
|
var _pluginKey = require("./pm-plugins/analytics/plugin-key");
|
|
@@ -49,7 +50,7 @@ var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
|
49
50
|
* from `@atlaskit/editor-core`.
|
|
50
51
|
*/
|
|
51
52
|
var tablesPlugin = function tablesPlugin(_ref) {
|
|
52
|
-
var _api$analytics;
|
|
53
|
+
var _api$analytics, _api$analytics2;
|
|
53
54
|
var options = _ref.config,
|
|
54
55
|
api = _ref.api;
|
|
55
56
|
var editorViewRef = {
|
|
@@ -84,6 +85,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
},
|
|
88
|
+
commands: {
|
|
89
|
+
insertTableWithSize: (0, _insert.insertTableWithSize)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
90
|
+
},
|
|
87
91
|
nodes: function nodes() {
|
|
88
92
|
var tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? _adfSchema.tableWithCustomWidth : _adfSchema.table;
|
|
89
93
|
return [{
|
|
@@ -45,7 +45,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
45
45
|
var type = (0, _misc.getTableElementMoveTypeBySlice)(slice, state);
|
|
46
46
|
|
|
47
47
|
// if the selection wasn't in the first cell of a row or column, don't count it
|
|
48
|
-
if (!(0, _misc.isInsideFirstCellOfRowOrColumn)(state.selection, type)) {
|
|
48
|
+
if (!type || !(0, _misc.isInsideFirstCellOfRowOrColumn)(state.selection, type)) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
var count = (0, _misc.countCellsInSlice)(slice, schema, type);
|
|
@@ -15,6 +15,7 @@ var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
|
|
|
15
15
|
var _utils2 = require("../../utils");
|
|
16
16
|
var _pluginFactory = require("../plugin-factory");
|
|
17
17
|
var _pluginKey = require("../plugin-key");
|
|
18
|
+
var _utils3 = require("../table-resizing/utils");
|
|
18
19
|
var _actions = require("./actions");
|
|
19
20
|
var _commands = require("./commands");
|
|
20
21
|
var _consts = require("./consts");
|
|
@@ -189,6 +190,17 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
|
|
|
189
190
|
sourceIndex = _sourceIndexes[0];
|
|
190
191
|
requestAnimationFrame(function () {
|
|
191
192
|
(0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
193
|
+
|
|
194
|
+
// force a colgroup update here, otherwise dropped columns don't have
|
|
195
|
+
// the correct width immediately after the drop
|
|
196
|
+
if (sourceType === 'table-column') {
|
|
197
|
+
var _getTablePluginState5 = (0, _pluginFactory.getPluginState)(editorView.state),
|
|
198
|
+
tableRef = _getTablePluginState5.tableRef,
|
|
199
|
+
tableNode = _getTablePluginState5.tableNode;
|
|
200
|
+
if (tableRef && tableNode) {
|
|
201
|
+
(0, _utils3.insertColgroupFromNode)(tableRef, tableNode);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
192
204
|
editorView.focus();
|
|
193
205
|
});
|
|
194
206
|
}
|
|
@@ -84,7 +84,8 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
|
|
|
84
84
|
var selectionRect = (0, _utils.isSelectionType)(selection, 'cell') ? (0, _utils.getSelectionRect)(selection) : (0, _utils.findCellRectClosestToPos)(selection.$from);
|
|
85
85
|
var hasMergedCells = direction === 'row' ? _utils2.hasMergedCellsInRow : _utils2.hasMergedCellsInColumn;
|
|
86
86
|
var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
|
|
87
|
-
var
|
|
87
|
+
var hasMergedCellsInTable = (0, _utils2.getMergedCellsPositions)(state.tr).length > 0;
|
|
88
|
+
var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect);
|
|
88
89
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
89
90
|
menuItems = _convertToDropdownIte.menuItems,
|
|
90
91
|
menuCallback = _convertToDropdownIte.menuCallback;
|
|
@@ -42,7 +42,7 @@ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
|
|
|
42
42
|
}
|
|
43
43
|
return false;
|
|
44
44
|
};
|
|
45
|
-
var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, editorView, tableMap, index, targetCellPosition, selectionRect) {
|
|
45
|
+
var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect) {
|
|
46
46
|
var addOptions = direction === 'row' ? [{
|
|
47
47
|
label: 'above',
|
|
48
48
|
offset: 0,
|
|
@@ -190,6 +190,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
190
190
|
return {
|
|
191
191
|
id: "sort_column_".concat(order),
|
|
192
192
|
title: "Sort ".concat(label),
|
|
193
|
+
disabled: hasMergedCellsInTable,
|
|
193
194
|
icon: icon,
|
|
194
195
|
onClick: function onClick(state, dispatch) {
|
|
195
196
|
(0, _commands.sortByColumn)(index, order)(state, dispatch);
|
|
@@ -133,4 +133,18 @@ export const createTable = () => (state, dispatch) => {
|
|
|
133
133
|
}
|
|
134
134
|
return true;
|
|
135
135
|
};
|
|
136
|
-
// #endregion
|
|
136
|
+
// #endregion
|
|
137
|
+
|
|
138
|
+
export const insertTableWithSize = editorAnalyticsAPI => (rowsCount, colsCount, inputMethod) => {
|
|
139
|
+
return ({
|
|
140
|
+
tr
|
|
141
|
+
}) => {
|
|
142
|
+
const tableNode = createTableNode({
|
|
143
|
+
schema: tr.doc.type.schema,
|
|
144
|
+
rowsCount: rowsCount,
|
|
145
|
+
colsCount: colsCount
|
|
146
|
+
});
|
|
147
|
+
const newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
148
|
+
return newTr;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
@@ -191,17 +191,17 @@ export const getTableElementMoveTypeBySlice = (slice, state) => {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
} = state;
|
|
194
|
+
const currentTable = findTable(state.tr.selection);
|
|
194
195
|
|
|
195
196
|
// check if copied slice is a table or table row
|
|
196
|
-
if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
|
|
197
|
-
return;
|
|
197
|
+
if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow || !currentTable) {
|
|
198
|
+
return undefined;
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
// if the slice only contains one table row, assume it's a row
|
|
201
202
|
if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
|
|
202
203
|
return 'row';
|
|
203
204
|
}
|
|
204
|
-
const currentTable = findTable(state.tr.selection);
|
|
205
205
|
const map = TableMap.get(currentTable.node);
|
|
206
206
|
const slicedMap = TableMap.get(slice.content.firstChild);
|
|
207
207
|
return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
|
|
@@ -11,6 +11,7 @@ import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
|
11
11
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
12
12
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
13
13
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { insertTableWithSize } from './commands/insert';
|
|
14
15
|
import { pluginConfig } from './create-plugin-config';
|
|
15
16
|
import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
|
|
16
17
|
import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
|
|
@@ -43,7 +44,7 @@ const tablesPlugin = ({
|
|
|
43
44
|
config: options,
|
|
44
45
|
api
|
|
45
46
|
}) => {
|
|
46
|
-
var _api$analytics;
|
|
47
|
+
var _api$analytics, _api$analytics2;
|
|
47
48
|
const editorViewRef = {
|
|
48
49
|
current: null
|
|
49
50
|
};
|
|
@@ -74,6 +75,9 @@ const tablesPlugin = ({
|
|
|
74
75
|
})) !== null && _api$contentInsertion !== void 0 ? _api$contentInsertion : false;
|
|
75
76
|
}
|
|
76
77
|
},
|
|
78
|
+
commands: {
|
|
79
|
+
insertTableWithSize: insertTableWithSize(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
80
|
+
},
|
|
77
81
|
nodes() {
|
|
78
82
|
const tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? tableWithCustomWidth : table;
|
|
79
83
|
return [{
|
|
@@ -41,7 +41,7 @@ export const createPlugin = (dispatch, dispatchAnalyticsEvent) => new SafePlugin
|
|
|
41
41
|
const type = getTableElementMoveTypeBySlice(slice, state);
|
|
42
42
|
|
|
43
43
|
// if the selection wasn't in the first cell of a row or column, don't count it
|
|
44
|
-
if (!isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
44
|
+
if (!type || !isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
const count = countCellsInSlice(slice, schema, type);
|
|
@@ -6,6 +6,7 @@ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/el
|
|
|
6
6
|
import { findNearestCellIndexToPoint, hasMergedCellsInBetween } from '../../utils';
|
|
7
7
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
8
8
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
9
|
+
import { insertColgroupFromNode } from '../table-resizing/utils';
|
|
9
10
|
import { DragAndDropActionType } from './actions';
|
|
10
11
|
import { clearDropTarget, moveSource, setDropTarget, toggleDragMenu } from './commands';
|
|
11
12
|
import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
|
|
@@ -190,6 +191,18 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
190
191
|
const [sourceIndex] = sourceIndexes;
|
|
191
192
|
requestAnimationFrame(() => {
|
|
192
193
|
moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
194
|
+
|
|
195
|
+
// force a colgroup update here, otherwise dropped columns don't have
|
|
196
|
+
// the correct width immediately after the drop
|
|
197
|
+
if (sourceType === 'table-column') {
|
|
198
|
+
const {
|
|
199
|
+
tableRef,
|
|
200
|
+
tableNode
|
|
201
|
+
} = getTablePluginState(editorView.state);
|
|
202
|
+
if (tableRef && tableNode) {
|
|
203
|
+
insertColgroupFromNode(tableRef, tableNode);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
193
206
|
editorView.focus();
|
|
194
207
|
});
|
|
195
208
|
}
|
|
@@ -7,7 +7,7 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
|
|
|
7
7
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
8
8
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
9
9
|
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
10
|
-
import { getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
10
|
+
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
11
11
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
12
12
|
import { dragMenuDropdownWidth } from '../consts';
|
|
13
13
|
const groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
|
|
@@ -75,7 +75,8 @@ export const DragMenu = ({
|
|
|
75
75
|
const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
76
76
|
const hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
77
77
|
const shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
|
|
78
|
-
const
|
|
78
|
+
const hasMergedCellsInTable = getMergedCellsPositions(state.tr).length > 0;
|
|
79
|
+
const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect);
|
|
79
80
|
const {
|
|
80
81
|
menuItems,
|
|
81
82
|
menuCallback
|
|
@@ -28,7 +28,7 @@ const isDistributeColumnsEnabled = state => {
|
|
|
28
28
|
}
|
|
29
29
|
return false;
|
|
30
30
|
};
|
|
31
|
-
export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, editorView, tableMap, index, targetCellPosition, selectionRect) => {
|
|
31
|
+
export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect) => {
|
|
32
32
|
const addOptions = direction === 'row' ? [{
|
|
33
33
|
label: 'above',
|
|
34
34
|
offset: 0,
|
|
@@ -172,6 +172,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, e
|
|
|
172
172
|
}) => ({
|
|
173
173
|
id: `sort_column_${order}`,
|
|
174
174
|
title: `Sort ${label}`,
|
|
175
|
+
disabled: hasMergedCellsInTable,
|
|
175
176
|
icon,
|
|
176
177
|
onClick: (state, dispatch) => {
|
|
177
178
|
sortByColumn(index, order)(state, dispatch);
|
|
@@ -145,4 +145,19 @@ export var createTable = function createTable() {
|
|
|
145
145
|
return true;
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
|
-
// #endregion
|
|
148
|
+
// #endregion
|
|
149
|
+
|
|
150
|
+
export var insertTableWithSize = function insertTableWithSize(editorAnalyticsAPI) {
|
|
151
|
+
return function (rowsCount, colsCount, inputMethod) {
|
|
152
|
+
return function (_ref) {
|
|
153
|
+
var tr = _ref.tr;
|
|
154
|
+
var tableNode = createTableNode({
|
|
155
|
+
schema: tr.doc.type.schema,
|
|
156
|
+
rowsCount: rowsCount,
|
|
157
|
+
colsCount: colsCount
|
|
158
|
+
});
|
|
159
|
+
var newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
160
|
+
return newTr;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
@@ -178,17 +178,17 @@ export var getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySl
|
|
|
178
178
|
var _state$schema$nodes = state.schema.nodes,
|
|
179
179
|
tableRow = _state$schema$nodes.tableRow,
|
|
180
180
|
table = _state$schema$nodes.table;
|
|
181
|
+
var currentTable = findTable(state.tr.selection);
|
|
181
182
|
|
|
182
183
|
// check if copied slice is a table or table row
|
|
183
|
-
if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
|
|
184
|
-
return;
|
|
184
|
+
if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow || !currentTable) {
|
|
185
|
+
return undefined;
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
// if the slice only contains one table row, assume it's a row
|
|
188
189
|
if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
|
|
189
190
|
return 'row';
|
|
190
191
|
}
|
|
191
|
-
var currentTable = findTable(state.tr.selection);
|
|
192
192
|
var map = TableMap.get(currentTable.node);
|
|
193
193
|
var slicedMap = TableMap.get(slice.content.firstChild);
|
|
194
194
|
return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
|
|
@@ -11,6 +11,7 @@ import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
|
11
11
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
12
12
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
13
13
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { insertTableWithSize } from './commands/insert';
|
|
14
15
|
import { pluginConfig } from './create-plugin-config';
|
|
15
16
|
import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
|
|
16
17
|
import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
|
|
@@ -42,7 +43,7 @@ var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
|
42
43
|
* from `@atlaskit/editor-core`.
|
|
43
44
|
*/
|
|
44
45
|
var tablesPlugin = function tablesPlugin(_ref) {
|
|
45
|
-
var _api$analytics;
|
|
46
|
+
var _api$analytics, _api$analytics2;
|
|
46
47
|
var options = _ref.config,
|
|
47
48
|
api = _ref.api;
|
|
48
49
|
var editorViewRef = {
|
|
@@ -77,6 +78,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
},
|
|
81
|
+
commands: {
|
|
82
|
+
insertTableWithSize: insertTableWithSize(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
83
|
+
},
|
|
80
84
|
nodes: function nodes() {
|
|
81
85
|
var tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? tableWithCustomWidth : table;
|
|
82
86
|
return [{
|
|
@@ -39,7 +39,7 @@ export var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent
|
|
|
39
39
|
var type = getTableElementMoveTypeBySlice(slice, state);
|
|
40
40
|
|
|
41
41
|
// if the selection wasn't in the first cell of a row or column, don't count it
|
|
42
|
-
if (!isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
42
|
+
if (!type || !isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
var count = countCellsInSlice(slice, schema, type);
|
|
@@ -10,6 +10,7 @@ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/el
|
|
|
10
10
|
import { findNearestCellIndexToPoint, hasMergedCellsInBetween } from '../../utils';
|
|
11
11
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
12
12
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
13
|
+
import { insertColgroupFromNode } from '../table-resizing/utils';
|
|
13
14
|
import { DragAndDropActionType } from './actions';
|
|
14
15
|
import { clearDropTarget, moveSource, setDropTarget, toggleDragMenu } from './commands';
|
|
15
16
|
import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
|
|
@@ -182,6 +183,17 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
182
183
|
sourceIndex = _sourceIndexes[0];
|
|
183
184
|
requestAnimationFrame(function () {
|
|
184
185
|
moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
186
|
+
|
|
187
|
+
// force a colgroup update here, otherwise dropped columns don't have
|
|
188
|
+
// the correct width immediately after the drop
|
|
189
|
+
if (sourceType === 'table-column') {
|
|
190
|
+
var _getTablePluginState5 = getTablePluginState(editorView.state),
|
|
191
|
+
tableRef = _getTablePluginState5.tableRef,
|
|
192
|
+
tableNode = _getTablePluginState5.tableNode;
|
|
193
|
+
if (tableRef && tableNode) {
|
|
194
|
+
insertColgroupFromNode(tableRef, tableNode);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
185
197
|
editorView.focus();
|
|
186
198
|
});
|
|
187
199
|
}
|
|
@@ -8,7 +8,7 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
|
|
|
8
8
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
9
9
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
10
10
|
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
11
|
-
import { getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
11
|
+
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
12
12
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
13
13
|
import { dragMenuDropdownWidth } from '../consts';
|
|
14
14
|
var groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
|
|
@@ -76,7 +76,8 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
76
76
|
var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
77
77
|
var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
78
78
|
var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
|
|
79
|
-
var
|
|
79
|
+
var hasMergedCellsInTable = getMergedCellsPositions(state.tr).length > 0;
|
|
80
|
+
var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect);
|
|
80
81
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
81
82
|
menuItems = _convertToDropdownIte.menuItems,
|
|
82
83
|
menuCallback = _convertToDropdownIte.menuCallback;
|
|
@@ -35,7 +35,7 @@ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
|
|
|
35
35
|
}
|
|
36
36
|
return false;
|
|
37
37
|
};
|
|
38
|
-
export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, editorView, tableMap, index, targetCellPosition, selectionRect) {
|
|
38
|
+
export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect) {
|
|
39
39
|
var addOptions = direction === 'row' ? [{
|
|
40
40
|
label: 'above',
|
|
41
41
|
offset: 0,
|
|
@@ -183,6 +183,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
|
|
|
183
183
|
return {
|
|
184
184
|
id: "sort_column_".concat(order),
|
|
185
185
|
title: "Sort ".concat(label),
|
|
186
|
+
disabled: hasMergedCellsInTable,
|
|
186
187
|
icon: icon,
|
|
187
188
|
onClick: function onClick(state, dispatch) {
|
|
188
189
|
sortByColumn(index, order)(state, dispatch);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { Command, EditorCommand, GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
export declare function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth): (column: number, allowAddColumnCustomStep: boolean | undefined, view: EditorView | undefined) => (tr: Transaction) => Transaction;
|
|
@@ -7,3 +8,4 @@ export declare const addColumnAfter: (getEditorContainerWidth: GetEditorContaine
|
|
|
7
8
|
export declare const insertColumn: (getEditorContainerWidth: GetEditorContainerWidth) => (column: number) => Command;
|
|
8
9
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean) => Command;
|
|
9
10
|
export declare const createTable: () => Command;
|
|
11
|
+
export declare const insertTableWithSize: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import
|
|
2
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { Command, EditorCommand, GetEditorFeatureFlags, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
5
|
import type { ContentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
5
6
|
import type { GuidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
@@ -22,6 +23,9 @@ export type TablePlugin = NextEditorPlugin<'table', {
|
|
|
22
23
|
actions: {
|
|
23
24
|
insertTable: InsertTableAction;
|
|
24
25
|
};
|
|
26
|
+
commands: {
|
|
27
|
+
insertTableWithSize: (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
|
|
28
|
+
};
|
|
25
29
|
dependencies: [
|
|
26
30
|
AnalyticsPlugin,
|
|
27
31
|
ContentInsertionPlugin,
|
|
@@ -8,4 +8,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
|
|
|
8
8
|
icon?: React.ComponentType<IconProps>;
|
|
9
9
|
keymap?: string;
|
|
10
10
|
}
|
|
11
|
-
export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
|
|
11
|
+
export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, hasMergedCellsInTable: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { Command, EditorCommand, GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
export declare function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth): (column: number, allowAddColumnCustomStep: boolean | undefined, view: EditorView | undefined) => (tr: Transaction) => Transaction;
|
|
@@ -7,3 +8,4 @@ export declare const addColumnAfter: (getEditorContainerWidth: GetEditorContaine
|
|
|
7
8
|
export declare const insertColumn: (getEditorContainerWidth: GetEditorContainerWidth) => (column: number) => Command;
|
|
8
9
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean) => Command;
|
|
9
10
|
export declare const createTable: () => Command;
|
|
11
|
+
export declare const insertTableWithSize: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import
|
|
2
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { Command, EditorCommand, GetEditorFeatureFlags, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
5
|
import type { ContentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
5
6
|
import type { GuidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
@@ -22,6 +23,9 @@ export type TablePlugin = NextEditorPlugin<'table', {
|
|
|
22
23
|
actions: {
|
|
23
24
|
insertTable: InsertTableAction;
|
|
24
25
|
};
|
|
26
|
+
commands: {
|
|
27
|
+
insertTableWithSize: (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
|
|
28
|
+
};
|
|
25
29
|
dependencies: [
|
|
26
30
|
AnalyticsPlugin,
|
|
27
31
|
ContentInsertionPlugin,
|
|
@@ -8,4 +8,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
|
|
|
8
8
|
icon?: React.ComponentType<IconProps>;
|
|
9
9
|
keymap?: string;
|
|
10
10
|
}
|
|
11
|
-
export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
|
|
11
|
+
export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, hasMergedCellsInTable: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.12",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"@atlaskit/pragmatic-drag-and-drop": "^0.25.0",
|
|
45
45
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.8.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
|
|
47
|
-
"@atlaskit/primitives": "^1.
|
|
47
|
+
"@atlaskit/primitives": "^1.15.0",
|
|
48
48
|
"@atlaskit/theme": "^12.6.0",
|
|
49
|
-
"@atlaskit/tokens": "^1.
|
|
49
|
+
"@atlaskit/tokens": "^1.30.0",
|
|
50
50
|
"@atlaskit/tooltip": "^18.0.0",
|
|
51
51
|
"@babel/runtime": "^7.0.0",
|
|
52
52
|
"@emotion/react": "^11.7.1",
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// #region Imports
|
|
2
2
|
import { AddColumnStep } from '@atlaskit/custom-steps';
|
|
3
|
+
import type {
|
|
4
|
+
EditorAnalyticsAPI,
|
|
5
|
+
INPUT_METHOD,
|
|
6
|
+
} from '@atlaskit/editor-common/analytics';
|
|
3
7
|
import { TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
|
|
4
8
|
import type {
|
|
5
9
|
Command,
|
|
10
|
+
EditorCommand,
|
|
6
11
|
GetEditorContainerWidth,
|
|
7
12
|
} from '@atlaskit/editor-common/types';
|
|
8
13
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -201,3 +206,24 @@ export const createTable = (): Command => (state, dispatch) => {
|
|
|
201
206
|
return true;
|
|
202
207
|
};
|
|
203
208
|
// #endregion
|
|
209
|
+
|
|
210
|
+
export const insertTableWithSize =
|
|
211
|
+
(editorAnalyticsAPI: EditorAnalyticsAPI | undefined) =>
|
|
212
|
+
(
|
|
213
|
+
rowsCount: number,
|
|
214
|
+
colsCount: number,
|
|
215
|
+
inputMethod?:
|
|
216
|
+
| INPUT_METHOD.PICKER
|
|
217
|
+
| INPUT_METHOD.ASCII
|
|
218
|
+
| INPUT_METHOD.TYPEAHEAD,
|
|
219
|
+
): EditorCommand => {
|
|
220
|
+
return ({ tr }) => {
|
|
221
|
+
const tableNode = createTableNode({
|
|
222
|
+
schema: tr.doc.type.schema,
|
|
223
|
+
rowsCount: rowsCount,
|
|
224
|
+
colsCount: colsCount,
|
|
225
|
+
});
|
|
226
|
+
const newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
227
|
+
return newTr;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
@@ -283,14 +283,16 @@ export const getTableElementMoveTypeBySlice = (
|
|
|
283
283
|
nodes: { tableRow, table },
|
|
284
284
|
},
|
|
285
285
|
} = state;
|
|
286
|
+
const currentTable = findTable(state.tr.selection);
|
|
286
287
|
|
|
287
288
|
// check if copied slice is a table or table row
|
|
288
289
|
if (
|
|
289
290
|
!slice.content.firstChild ||
|
|
290
291
|
(slice.content.firstChild.type !== table &&
|
|
291
|
-
slice.content.firstChild.type !== tableRow)
|
|
292
|
+
slice.content.firstChild.type !== tableRow) ||
|
|
293
|
+
!currentTable
|
|
292
294
|
) {
|
|
293
|
-
return;
|
|
295
|
+
return undefined;
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
// if the slice only contains one table row, assume it's a row
|
|
@@ -301,7 +303,6 @@ export const getTableElementMoveTypeBySlice = (
|
|
|
301
303
|
return 'row';
|
|
302
304
|
}
|
|
303
305
|
|
|
304
|
-
const currentTable = findTable(state.tr.selection)!;
|
|
305
306
|
const map = TableMap.get(currentTable.node);
|
|
306
307
|
const slicedMap = TableMap.get(slice.content.firstChild);
|
|
307
308
|
|
|
@@ -23,6 +23,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
|
|
|
23
23
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
24
24
|
import type {
|
|
25
25
|
Command,
|
|
26
|
+
EditorCommand,
|
|
26
27
|
EditorPlugin,
|
|
27
28
|
GetEditorContainerWidth,
|
|
28
29
|
GetEditorFeatureFlags,
|
|
@@ -41,6 +42,7 @@ import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
|
41
42
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
42
43
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
43
44
|
|
|
45
|
+
import { insertTableWithSize } from './commands/insert';
|
|
44
46
|
import { pluginConfig } from './create-plugin-config';
|
|
45
47
|
import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
|
|
46
48
|
import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
|
|
@@ -78,6 +80,7 @@ import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
|
78
80
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
79
81
|
import LayoutButton from './ui/LayoutButton';
|
|
80
82
|
import { isLayoutSupported } from './utils';
|
|
83
|
+
|
|
81
84
|
export interface TablePluginOptions {
|
|
82
85
|
tableOptions: PluginConfig;
|
|
83
86
|
// experimental custom table resizing experience, set inside editor-core behind a feature flag
|
|
@@ -103,6 +106,16 @@ export type TablePlugin = NextEditorPlugin<
|
|
|
103
106
|
actions: {
|
|
104
107
|
insertTable: InsertTableAction;
|
|
105
108
|
};
|
|
109
|
+
commands: {
|
|
110
|
+
insertTableWithSize: (
|
|
111
|
+
rowsCount: number,
|
|
112
|
+
colsCount: number,
|
|
113
|
+
inputMethod?:
|
|
114
|
+
| INPUT_METHOD.PICKER
|
|
115
|
+
| INPUT_METHOD.ASCII
|
|
116
|
+
| INPUT_METHOD.TYPEAHEAD,
|
|
117
|
+
) => EditorCommand;
|
|
118
|
+
};
|
|
106
119
|
dependencies: [
|
|
107
120
|
AnalyticsPlugin,
|
|
108
121
|
ContentInsertionPlugin,
|
|
@@ -152,6 +165,9 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
152
165
|
);
|
|
153
166
|
},
|
|
154
167
|
},
|
|
168
|
+
commands: {
|
|
169
|
+
insertTableWithSize: insertTableWithSize(api?.analytics?.actions),
|
|
170
|
+
},
|
|
155
171
|
|
|
156
172
|
nodes() {
|
|
157
173
|
const tableNode = options?.tableResizingEnabled
|
|
@@ -59,7 +59,7 @@ export const createPlugin = (
|
|
|
59
59
|
const type = getTableElementMoveTypeBySlice(slice, state);
|
|
60
60
|
|
|
61
61
|
// if the selection wasn't in the first cell of a row or column, don't count it
|
|
62
|
-
if (!isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
62
|
+
if (!type || !isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from '../../utils';
|
|
17
17
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
18
18
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
19
|
+
import { insertColgroupFromNode } from '../table-resizing/utils';
|
|
19
20
|
|
|
20
21
|
import { DragAndDropActionType } from './actions';
|
|
21
22
|
import {
|
|
@@ -236,6 +237,17 @@ export const createPlugin = (
|
|
|
236
237
|
tr,
|
|
237
238
|
)(editorView.state, editorView.dispatch);
|
|
238
239
|
|
|
240
|
+
// force a colgroup update here, otherwise dropped columns don't have
|
|
241
|
+
// the correct width immediately after the drop
|
|
242
|
+
if (sourceType === 'table-column') {
|
|
243
|
+
const { tableRef, tableNode } = getTablePluginState(
|
|
244
|
+
editorView.state,
|
|
245
|
+
);
|
|
246
|
+
if (tableRef && tableNode) {
|
|
247
|
+
insertColgroupFromNode(tableRef, tableNode);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
239
251
|
editorView.focus();
|
|
240
252
|
});
|
|
241
253
|
},
|
|
@@ -27,6 +27,7 @@ import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
|
27
27
|
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
28
28
|
import type { PluginConfig, TableDirection } from '../../types';
|
|
29
29
|
import {
|
|
30
|
+
getMergedCellsPositions,
|
|
30
31
|
getSelectedColumnIndexes,
|
|
31
32
|
getSelectedRowIndexes,
|
|
32
33
|
hasMergedCellsInColumn,
|
|
@@ -136,10 +137,13 @@ export const DragMenu = ({
|
|
|
136
137
|
const shouldMoveDisabled =
|
|
137
138
|
index !== undefined && hasMergedCells(index)(selection);
|
|
138
139
|
|
|
140
|
+
const hasMergedCellsInTable = getMergedCellsPositions(state.tr).length > 0;
|
|
141
|
+
|
|
139
142
|
const dragMenuConfig = getDragMenuConfig(
|
|
140
143
|
direction,
|
|
141
144
|
getEditorContainerWidth,
|
|
142
145
|
!!canDrag && !shouldMoveDisabled,
|
|
146
|
+
hasMergedCellsInTable,
|
|
143
147
|
editorView,
|
|
144
148
|
tableMap,
|
|
145
149
|
index,
|
|
@@ -73,6 +73,7 @@ export const getDragMenuConfig = (
|
|
|
73
73
|
direction: TableDirection,
|
|
74
74
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
75
75
|
canDrag: boolean,
|
|
76
|
+
hasMergedCellsInTable: boolean,
|
|
76
77
|
editorView: EditorView,
|
|
77
78
|
tableMap?: TableMap,
|
|
78
79
|
index?: number,
|
|
@@ -248,6 +249,7 @@ export const getDragMenuConfig = (
|
|
|
248
249
|
...sortOptions.map(({ label, order, icon }) => ({
|
|
249
250
|
id: `sort_column_${order}`,
|
|
250
251
|
title: `Sort ${label}`,
|
|
252
|
+
disabled: hasMergedCellsInTable,
|
|
251
253
|
icon,
|
|
252
254
|
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
253
255
|
sortByColumn(index!, order)(state, dispatch);
|