@atlaskit/editor-plugin-table 5.7.6 → 5.7.8

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands-with-analytics.js +29 -5
  3. package/dist/cjs/plugin.js +54 -52
  4. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +49 -4
  5. package/dist/cjs/pm-plugins/keymap.js +13 -1
  6. package/dist/cjs/ui/consts.js +1 -1
  7. package/dist/cjs/utils/drag-menu.js +14 -7
  8. package/dist/es2019/commands-with-analytics.js +26 -1
  9. package/dist/es2019/plugin.js +6 -1
  10. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +46 -2
  11. package/dist/es2019/pm-plugins/keymap.js +15 -3
  12. package/dist/es2019/ui/consts.js +1 -1
  13. package/dist/es2019/utils/drag-menu.js +15 -8
  14. package/dist/esm/commands-with-analytics.js +29 -5
  15. package/dist/esm/plugin.js +54 -52
  16. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +47 -2
  17. package/dist/esm/pm-plugins/keymap.js +15 -3
  18. package/dist/esm/ui/consts.js +1 -1
  19. package/dist/esm/utils/drag-menu.js +15 -8
  20. package/dist/types/commands-with-analytics.d.ts +3 -2
  21. package/dist/types/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +7 -5
  22. package/dist/types/pm-plugins/keymap.d.ts +1 -1
  23. package/dist/types/ui/consts.d.ts +1 -1
  24. package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -2
  25. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +7 -5
  26. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
  27. package/dist/types-ts4.5/ui/consts.d.ts +1 -1
  28. package/package.json +4 -4
  29. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +6 -6
  30. package/src/commands-with-analytics.ts +39 -2
  31. package/src/plugin.tsx +10 -2
  32. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +85 -7
  33. package/src/pm-plugins/keymap.ts +52 -0
  34. package/src/ui/consts.ts +1 -1
  35. package/src/utils/drag-menu.ts +13 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.7.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#65572](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65572) [`a13e13b8eb7d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a13e13b8eb7d) - [ux] Increases drag menu width by 10px to ensure "Move column right" option fits on one line.
8
+ - [#65031](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65031) [`a00094111b5a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a00094111b5a) - ED-21609 Update adf-schema to 35.3.0
9
+ - Updated dependencies
10
+
11
+ ## 5.7.7
12
+
13
+ ### Patch Changes
14
+
15
+ - [#64359](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/64359) [`e728a3537d3b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e728a3537d3b) - [ux] Adds table shortcust to move row or column and to delete row or column when drag and drop enabled
16
+
3
17
  ## 5.7.6
4
18
 
5
19
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.wrapTableInExpandWithAnalytics = exports.toggleTableLayoutWithAnalytics = exports.toggleNumberColumnWithAnalytics = exports.toggleHeaderRowWithAnalytics = exports.toggleHeaderColumnWithAnalytics = exports.splitCellWithAnalytics = exports.sortColumnWithAnalytics = exports.setColorWithAnalytics = exports.mergeCellsWithAnalytics = exports.insertRowWithAnalytics = exports.insertColumnWithAnalytics = exports.emptyMultipleCellsWithAnalytics = exports.distributeColumnsWidthsWithAnalytics = exports.deleteTableWithAnalytics = exports.deleteTableIfSelectedWithAnalytics = exports.deleteRowsWithAnalytics = exports.deleteColumnsWithAnalytics = exports.addRowAroundSelection = void 0;
7
+ exports.wrapTableInExpandWithAnalytics = exports.toggleTableLayoutWithAnalytics = exports.toggleNumberColumnWithAnalytics = exports.toggleHeaderRowWithAnalytics = exports.toggleHeaderColumnWithAnalytics = exports.splitCellWithAnalytics = exports.sortColumnWithAnalytics = exports.setColorWithAnalytics = exports.mergeCellsWithAnalytics = exports.insertRowWithAnalytics = exports.insertColumnWithAnalytics = exports.emptyMultipleCellsWithAnalytics = exports.distributeColumnsWidthsWithAnalytics = exports.deleteTableWithAnalytics = exports.deleteTableIfSelectedWithAnalytics = exports.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = exports.deleteRowsWithAnalytics = exports.deleteColumnsWithAnalytics = exports.addRowAroundSelection = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -261,6 +261,30 @@ var deleteColumnsWithAnalytics = exports.deleteColumnsWithAnalytics = function d
261
261
  })(editorAnalyticsAPI)((0, _delete.deleteColumnsCommand)(rect));
262
262
  };
263
263
  };
264
+ var deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = exports.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = function deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI) {
265
+ return function (state, dispatch) {
266
+ var selection = state.selection;
267
+ var isCellSelection = selection instanceof _cellSelection.CellSelection;
268
+ if (!isCellSelection) {
269
+ return false;
270
+ }
271
+ var rect = (0, _utils.getSelectionRect)(selection);
272
+ if (!rect) {
273
+ return false;
274
+ }
275
+ var selectionType = (0, _misc.getTableSelectionType)(selection);
276
+ if (selectionType === 'row') {
277
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
278
+ pluginConfig = _getPluginState.pluginConfig;
279
+ var isHeaderRowRequired = pluginConfig.isHeaderRowRequired || false;
280
+ return deleteRowsWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, rect, isHeaderRowRequired)(state, dispatch);
281
+ } else if (selectionType === 'column') {
282
+ return deleteColumnsWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, rect)(state, dispatch);
283
+ } else {
284
+ return false;
285
+ }
286
+ };
287
+ };
264
288
  var getTableDeletedAnalytics = function getTableDeletedAnalytics(selection, inputMethod) {
265
289
  var _getSelectedTableInfo5 = (0, _utils2.getSelectedTableInfo)(selection),
266
290
  totalRowCount = _getSelectedTableInfo5.totalRowCount,
@@ -295,8 +319,8 @@ var toggleHeaderRowWithAnalytics = exports.toggleHeaderRowWithAnalytics = functi
295
319
  var _getSelectedTableInfo6 = (0, _utils2.getSelectedTableInfo)(state.selection),
296
320
  totalRowCount = _getSelectedTableInfo6.totalRowCount,
297
321
  totalColumnCount = _getSelectedTableInfo6.totalColumnCount;
298
- var _getPluginState = (0, _pluginFactory.getPluginState)(state),
299
- isHeaderRowEnabled = _getPluginState.isHeaderRowEnabled;
322
+ var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
323
+ isHeaderRowEnabled = _getPluginState2.isHeaderRowEnabled;
300
324
  return {
301
325
  action: _analytics.TABLE_ACTION.TOGGLED_HEADER_ROW,
302
326
  actionSubject: _analytics.ACTION_SUBJECT.TABLE,
@@ -315,8 +339,8 @@ var toggleHeaderColumnWithAnalytics = exports.toggleHeaderColumnWithAnalytics =
315
339
  var _getSelectedTableInfo7 = (0, _utils2.getSelectedTableInfo)(state.selection),
316
340
  totalRowCount = _getSelectedTableInfo7.totalRowCount,
317
341
  totalColumnCount = _getSelectedTableInfo7.totalColumnCount;
318
- var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
319
- isHeaderColumnEnabled = _getPluginState2.isHeaderColumnEnabled;
342
+ var _getPluginState3 = (0, _pluginFactory.getPluginState)(state),
343
+ isHeaderColumnEnabled = _getPluginState3.isHeaderColumnEnabled;
320
344
  return {
321
345
  action: _analytics.TABLE_ACTION.TOGGLED_HEADER_COLUMN,
322
346
  actionSubject: _analytics.ACTION_SUBJECT.TABLE,
@@ -148,7 +148,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
148
148
  {
149
149
  name: 'tableKeymap',
150
150
  plugin: function plugin() {
151
- return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI);
151
+ var _ref6 = options || {},
152
+ dragAndDropEnabled = _ref6.dragAndDropEnabled;
153
+ return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled);
152
154
  }
153
155
  }, {
154
156
  name: 'tableSelectionKeymap',
@@ -158,12 +160,12 @@ var tablesPlugin = function tablesPlugin(_ref) {
158
160
  }, {
159
161
  name: 'tableEditing',
160
162
  plugin: function plugin() {
161
- var _ref6 = options || {},
162
- dragAndDropEnabled = _ref6.dragAndDropEnabled;
163
+ var _ref7 = options || {},
164
+ dragAndDropEnabled = _ref7.dragAndDropEnabled;
163
165
  return (0, _pmPlugins.tableEditing)({
164
- reportFixedTable: function reportFixedTable(_ref7) {
165
- var tr = _ref7.tr,
166
- reason = _ref7.reason;
166
+ reportFixedTable: function reportFixedTable(_ref8) {
167
+ var tr = _ref8.tr,
168
+ reason = _ref8.reason;
167
169
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
168
170
  action: _analytics.TABLE_ACTION.FIXED,
169
171
  actionSubject: _analytics.ACTION_SUBJECT.TABLE,
@@ -179,50 +181,50 @@ var tablesPlugin = function tablesPlugin(_ref) {
179
181
  }
180
182
  }, {
181
183
  name: 'tableStickyHeaders',
182
- plugin: function plugin(_ref8) {
183
- var dispatch = _ref8.dispatch,
184
- eventDispatcher = _ref8.eventDispatcher;
184
+ plugin: function plugin(_ref9) {
185
+ var dispatch = _ref9.dispatch,
186
+ eventDispatcher = _ref9.eventDispatcher;
185
187
  return options && options.tableOptions.stickyHeaders ? (0, _stickyHeaders.createPlugin)(dispatch, eventDispatcher, function () {
186
188
  return [];
187
189
  }, (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags) : undefined;
188
190
  }
189
191
  }, {
190
192
  name: 'tableDragAndDrop',
191
- plugin: function plugin(_ref9) {
192
- var dispatch = _ref9.dispatch,
193
- eventDispatcher = _ref9.eventDispatcher,
194
- dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
193
+ plugin: function plugin(_ref10) {
194
+ var dispatch = _ref10.dispatch,
195
+ eventDispatcher = _ref10.eventDispatcher,
196
+ dispatchAnalyticsEvent = _ref10.dispatchAnalyticsEvent;
195
197
  return options !== null && options !== void 0 && options.dragAndDropEnabled ? (0, _dragAndDrop.createPlugin)(dispatch, eventDispatcher, editorAnalyticsAPI) : undefined;
196
198
  }
197
199
  }, {
198
200
  name: 'tableLocalId',
199
- plugin: function plugin(_ref10) {
200
- var dispatch = _ref10.dispatch;
201
+ plugin: function plugin(_ref11) {
202
+ var dispatch = _ref11.dispatch;
201
203
  return (0, _tableLocalId.createPlugin)(dispatch);
202
204
  }
203
205
  }, {
204
206
  name: 'tableWidth',
205
- plugin: function plugin(_ref11) {
207
+ plugin: function plugin(_ref12) {
206
208
  var _options$fullWidthEna;
207
- var dispatchAnalyticsEvent = _ref11.dispatchAnalyticsEvent,
208
- dispatch = _ref11.dispatch;
209
+ var dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent,
210
+ dispatch = _ref12.dispatch;
209
211
  return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
210
212
  }
211
213
  },
212
214
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
213
215
  {
214
216
  name: 'tableOverflowAnalyticsPlugin',
215
- plugin: function plugin(_ref12) {
217
+ plugin: function plugin(_ref13) {
216
218
  var _options$tableResizin;
217
- var dispatch = _ref12.dispatch,
218
- dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent;
219
+ var dispatch = _ref13.dispatch,
220
+ dispatchAnalyticsEvent = _ref13.dispatchAnalyticsEvent;
219
221
  return (0, _tableAnalytics.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
220
222
  }
221
223
  }, {
222
224
  name: 'tableAnalyticsPlugin',
223
- plugin: function plugin(_ref13) {
224
- var dispatch = _ref13.dispatch,
225
- dispatchAnalyticsEvent = _ref13.dispatchAnalyticsEvent;
225
+ plugin: function plugin(_ref14) {
226
+ var dispatch = _ref14.dispatch,
227
+ dispatchAnalyticsEvent = _ref14.dispatchAnalyticsEvent;
226
228
  return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.analytics-plugin-moved-event') ? (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent) : undefined;
227
229
  }
228
230
  }, {
@@ -253,12 +255,12 @@ var tablesPlugin = function tablesPlugin(_ref) {
253
255
  }
254
256
  return plugins;
255
257
  },
256
- contentComponent: function contentComponent(_ref14) {
257
- var editorView = _ref14.editorView,
258
- popupsMountPoint = _ref14.popupsMountPoint,
259
- popupsBoundariesElement = _ref14.popupsBoundariesElement,
260
- popupsScrollableElement = _ref14.popupsScrollableElement,
261
- dispatchAnalyticsEvent = _ref14.dispatchAnalyticsEvent;
258
+ contentComponent: function contentComponent(_ref15) {
259
+ var editorView = _ref15.editorView,
260
+ popupsMountPoint = _ref15.popupsMountPoint,
261
+ popupsBoundariesElement = _ref15.popupsBoundariesElement,
262
+ popupsScrollableElement = _ref15.popupsScrollableElement,
263
+ dispatchAnalyticsEvent = _ref15.dispatchAnalyticsEvent;
262
264
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
263
265
  component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
264
266
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -272,30 +274,30 @@ var tablesPlugin = function tablesPlugin(_ref) {
272
274
  stickyHeadersState: _stickyHeaders.pluginKey,
273
275
  dragAndDropState: _dragAndDrop.pluginKey
274
276
  },
275
- render: function render(_ref15) {
276
- var resizingPluginState = _ref15.tableResizingPluginState,
277
- stickyHeadersState = _ref15.stickyHeadersState,
278
- tablePluginState = _ref15.tablePluginState,
279
- tableWidthPluginState = _ref15.tableWidthPluginState,
280
- dragAndDropState = _ref15.dragAndDropState;
277
+ render: function render(_ref16) {
278
+ var resizingPluginState = _ref16.tableResizingPluginState,
279
+ stickyHeadersState = _ref16.stickyHeadersState,
280
+ tablePluginState = _ref16.tablePluginState,
281
+ tableWidthPluginState = _ref16.tableWidthPluginState,
282
+ dragAndDropState = _ref16.dragAndDropState;
281
283
  var state = editorView.state;
282
284
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
283
285
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
284
286
  var isResizing = isColumnResizing || isTableResizing;
285
- var _ref16 = tablePluginState,
286
- tableNode = _ref16.tableNode,
287
- tablePos = _ref16.tablePos,
288
- targetCellPosition = _ref16.targetCellPosition,
289
- isContextualMenuOpen = _ref16.isContextualMenuOpen,
290
- layout = _ref16.layout,
291
- tableRef = _ref16.tableRef,
292
- pluginConfig = _ref16.pluginConfig,
293
- insertColumnButtonIndex = _ref16.insertColumnButtonIndex,
294
- insertRowButtonIndex = _ref16.insertRowButtonIndex,
295
- isHeaderColumnEnabled = _ref16.isHeaderColumnEnabled,
296
- isHeaderRowEnabled = _ref16.isHeaderRowEnabled,
297
- isDragAndDropEnabled = _ref16.isDragAndDropEnabled,
298
- tableWrapperTarget = _ref16.tableWrapperTarget;
287
+ var _ref17 = tablePluginState,
288
+ tableNode = _ref17.tableNode,
289
+ tablePos = _ref17.tablePos,
290
+ targetCellPosition = _ref17.targetCellPosition,
291
+ isContextualMenuOpen = _ref17.isContextualMenuOpen,
292
+ layout = _ref17.layout,
293
+ tableRef = _ref17.tableRef,
294
+ pluginConfig = _ref17.pluginConfig,
295
+ insertColumnButtonIndex = _ref17.insertColumnButtonIndex,
296
+ insertRowButtonIndex = _ref17.insertRowButtonIndex,
297
+ isHeaderColumnEnabled = _ref17.isHeaderColumnEnabled,
298
+ isHeaderRowEnabled = _ref17.isHeaderRowEnabled,
299
+ isDragAndDropEnabled = _ref17.isDragAndDropEnabled,
300
+ tableWrapperTarget = _ref17.tableWrapperTarget;
299
301
  var allowControls = pluginConfig.allowControls;
300
302
  var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
301
303
  var LayoutContent = options && !options.tableResizingEnabled && (0, _utils3.isLayoutSupported)(state) && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
@@ -376,8 +378,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
376
378
  }));
377
379
  },
378
380
  pluginsOptions: {
379
- quickInsert: function quickInsert(_ref17) {
380
- var formatMessage = _ref17.formatMessage;
381
+ quickInsert: function quickInsert(_ref18) {
382
+ var formatMessage = _ref18.formatMessage;
381
383
  return [{
382
384
  id: 'table',
383
385
  title: formatMessage(_messages.toolbarInsertBlockMessages.table),
@@ -3,16 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.moveSourceWithAnalytics = exports.clearDropTargetWithAnalytics = void 0;
6
+ exports.moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalytics = exports.clearDropTargetWithAnalytics = void 0;
7
7
  var _analytics = require("@atlaskit/editor-common/analytics");
8
- var _utils = require("../../utils");
8
+ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
9
+ var _utils = require("@atlaskit/editor-tables/utils");
10
+ var _utils2 = require("../../utils");
9
11
  var _analytics2 = require("../../utils/analytics");
10
12
  var _commands = require("./commands");
11
13
  var clearDropTargetWithAnalytics = exports.clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
12
14
  return function (inputMethod, sourceType, status, tr) {
13
15
  return (0, _analytics2.withEditorAnalyticsAPI)(function (_ref) {
14
16
  var selection = _ref.selection;
15
- var _getSelectedTableInfo = (0, _utils.getSelectedTableInfo)(selection),
17
+ var _getSelectedTableInfo = (0, _utils2.getSelectedTableInfo)(selection),
16
18
  totalRowCount = _getSelectedTableInfo.totalRowCount,
17
19
  totalColumnCount = _getSelectedTableInfo.totalColumnCount;
18
20
  return {
@@ -42,7 +44,7 @@ var moveSourceWithAnalytics = exports.moveSourceWithAnalytics = function moveSou
42
44
  return function (inputMethod, sourceType, sourceIndex, targetIndex, tr) {
43
45
  return (0, _analytics2.withEditorAnalyticsAPI)(function (_ref2) {
44
46
  var selection = _ref2.selection;
45
- var _getSelectedTableInfo2 = (0, _utils.getSelectedTableInfo)(selection),
47
+ var _getSelectedTableInfo2 = (0, _utils2.getSelectedTableInfo)(selection),
46
48
  totalRowCount = _getSelectedTableInfo2.totalRowCount,
47
49
  totalColumnCount = _getSelectedTableInfo2.totalColumnCount;
48
50
  return {
@@ -69,4 +71,47 @@ var moveSourceWithAnalytics = exports.moveSourceWithAnalytics = function moveSou
69
71
  return true;
70
72
  });
71
73
  };
74
+ };
75
+ var moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalyticsViaShortcut = function moveSourceWithAnalyticsViaShortcut(editorAnalyticsAPI) {
76
+ return function (sourceType, direction) {
77
+ return function (state, dispatch) {
78
+ var selection = state.selection;
79
+ var isCellSelection = selection instanceof _cellSelection.CellSelection;
80
+ var selectionRect = isCellSelection ? (0, _utils.getSelectionRect)(selection) : (0, _utils.findCellRectClosestToPos)(selection.$from);
81
+ if (!selectionRect) {
82
+ return false;
83
+ }
84
+ var isRow = sourceType === 'table-row';
85
+ var selectedIndexes = isRow ? (0, _utils2.getSelectedRowIndexes)(selectionRect) : (0, _utils2.getSelectedColumnIndexes)(selectionRect);
86
+
87
+ // We can move if only one row/column selected
88
+ if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
89
+ return false;
90
+ }
91
+ var sourceIndex = selectedIndexes[0];
92
+ // we can move only by one row/column
93
+ // 'direction' can only be 1 (for right or down) or -1 (for left or up)
94
+ var targetIndex = sourceIndex + direction;
95
+
96
+ // We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
97
+ var _getSelectedTableInfo3 = (0, _utils2.getSelectedTableInfo)(selection),
98
+ totalRowCount = _getSelectedTableInfo3.totalRowCount,
99
+ totalColumnCount = _getSelectedTableInfo3.totalColumnCount;
100
+ var isValidTargetIndex = targetIndex < 0 ? false : isRow ? targetIndex <= totalRowCount - 1 : targetIndex <= totalColumnCount - 1;
101
+ if (!isValidTargetIndex) {
102
+ return false;
103
+ }
104
+
105
+ // We can move only if there are no merged cells in the source or target row/column
106
+ var hasMergedCellsInSource = isRow ? (0, _utils2.hasMergedCellsInRow)(sourceIndex)(selection) : (0, _utils2.hasMergedCellsInColumn)(sourceIndex)(selection);
107
+ if (hasMergedCellsInSource) {
108
+ return false;
109
+ }
110
+ var hasMergedCellsInTarget = isRow ? (0, _utils2.hasMergedCellsInRow)(targetIndex)(selection) : (0, _utils2.hasMergedCellsInColumn)(targetIndex)(selection);
111
+ if (hasMergedCellsInTarget) {
112
+ return false;
113
+ }
114
+ return moveSourceWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, sourceType, sourceIndex, targetIndex)(state, dispatch);
115
+ };
116
+ };
72
117
  };
@@ -12,6 +12,7 @@ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
12
12
  var _commands2 = require("../commands");
13
13
  var _commandsWithAnalytics = require("../commands-with-analytics");
14
14
  var _insert = require("../commands/insert");
15
+ var _commandsWithAnalytics2 = require("../pm-plugins/drag-and-drop/commands-with-analytics");
15
16
  var _analytics2 = require("../utils/analytics");
16
17
  var createTableWithAnalytics = function createTableWithAnalytics(editorAnalyticsAPI) {
17
18
  return (0, _analytics2.withEditorAnalyticsAPI)({
@@ -24,7 +25,7 @@ var createTableWithAnalytics = function createTableWithAnalytics(editorAnalytics
24
25
  eventType: _analytics.EVENT_TYPE.TRACK
25
26
  })(editorAnalyticsAPI)((0, _commands2.createTable)());
26
27
  };
27
- function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI) {
28
+ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
28
29
  var list = {};
29
30
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.nextCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI)(1), list);
30
31
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.previousCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI)(-1), list);
@@ -37,6 +38,17 @@ function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI) {
37
38
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.addRowAfter.common, (0, _commandsWithAnalytics.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list);
38
39
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnBefore.common, (0, _commands2.triggerUnlessTableHeader)((0, _insert.addColumnBefore)(getEditorContainerWidth)), list);
39
40
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.addColumnAfter.common, (0, _insert.addColumnAfter)(getEditorContainerWidth), list);
41
+ if (dragAndDropEnabled) {
42
+ // Move row/column shortcuts
43
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRowDown.common, (0, _commandsWithAnalytics2.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI)('table-row', 1), list);
44
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRowUp.common, (0, _commandsWithAnalytics2.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI)('table-row', -1), list);
45
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveColumnLeft.common, (0, _commandsWithAnalytics2.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI)('table-column', -1), list);
46
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveColumnRight.common, (0, _commandsWithAnalytics2.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI)('table-column', 1), list);
47
+
48
+ // Delete row/column shortcuts
49
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteColumn.common, (0, _commandsWithAnalytics.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut)(editorAnalyticsAPI), list);
50
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteRow.common, (0, _commandsWithAnalytics.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut)(editorAnalyticsAPI), list);
51
+ }
40
52
  return (0, _keymap.keymap)(list);
41
53
  }
42
54
  var _default = exports.default = keymapPlugin;
@@ -70,6 +70,6 @@ var STICKY_HEADER_TOGGLE_TOLERANCE_MS = exports.STICKY_HEADER_TOGGLE_TOLERANCE_M
70
70
  // table margins and padding. For example a guideline at 1800px and the view at 1860px wide, means the guidelines is visible
71
71
  // BUT it cannot be snapped to during resize due to padding being applied to the resizer wrapper. This accommodates that difference.
72
72
  var TABLE_GUIDELINE_VISIBLE_ADJUSTMENT = exports.TABLE_GUIDELINE_VISIBLE_ADJUSTMENT = -68;
73
- var dragMenuDropdownWidth = exports.dragMenuDropdownWidth = 240;
73
+ var dragMenuDropdownWidth = exports.dragMenuDropdownWidth = 250;
74
74
  var dragTableInsertColumnButtonSize = exports.dragTableInsertColumnButtonSize = 16;
75
75
  var dropTargetExtendedWidth = exports.dropTargetExtendedWidth = 150;
@@ -71,7 +71,8 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
71
71
  canMove: function canMove(index) {
72
72
  return canDrag && canDecrease(index);
73
73
  },
74
- icon: _arrowUp.default
74
+ icon: _arrowUp.default,
75
+ keymap: _keymaps.moveRowUp
75
76
  }, {
76
77
  label: 'down',
77
78
  offset: 1,
@@ -79,14 +80,16 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
79
80
  var _tableMap$height;
80
81
  return canDrag && canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
81
82
  },
82
- icon: _arrowDown.default
83
+ icon: _arrowDown.default,
84
+ keymap: _keymaps.moveRowDown
83
85
  }] : [{
84
86
  label: 'left',
85
87
  offset: -1,
86
88
  canMove: function canMove(index) {
87
89
  return canDrag && canDecrease(index);
88
90
  },
89
- icon: _arrowLeft.default
91
+ icon: _arrowLeft.default,
92
+ keymap: _keymaps.moveColumnLeft
90
93
  }, {
91
94
  label: 'right',
92
95
  offset: 1,
@@ -94,7 +97,8 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
94
97
  var _tableMap$width;
95
98
  return canDrag && canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
96
99
  },
97
- icon: _arrowRight.default
100
+ icon: _arrowRight.default,
101
+ keymap: _keymaps.moveColumnRight
98
102
  }];
99
103
  var sortOptions = direction === 'column' ? [{
100
104
  label: 'increasing',
@@ -163,12 +167,14 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
163
167
  }
164
168
  return true;
165
169
  },
166
- icon: _remove.default
170
+ icon: _remove.default,
171
+ keymap: direction === 'row' ? (0, _keymaps.tooltip)(_keymaps.deleteRow) : (0, _keymaps.tooltip)(_keymaps.deleteColumn)
167
172
  }], (0, _toConsumableArray2.default)(moveOptions.map(function (_ref2) {
168
173
  var label = _ref2.label,
169
174
  offset = _ref2.offset,
170
175
  canMove = _ref2.canMove,
171
- icon = _ref2.icon;
176
+ icon = _ref2.icon,
177
+ keymap = _ref2.keymap;
172
178
  return {
173
179
  id: "move_".concat(direction, "_").concat(label),
174
180
  title: "Move ".concat(direction, " ").concat(label),
@@ -182,7 +188,8 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
182
188
  return true;
183
189
  }
184
190
  return false;
185
- }
191
+ },
192
+ keymap: keymap && (0, _keymaps.tooltip)(keymap)
186
193
  };
187
194
  })), (0, _toConsumableArray2.default)(sortOptions.map(function (_ref3) {
188
195
  var label = _ref3.label,
@@ -6,7 +6,7 @@ import { clearMultipleCells } from './commands/clear';
6
6
  import { wrapTableInExpand } from './commands/collapse';
7
7
  import { deleteColumnsCommand } from './commands/delete';
8
8
  import { insertColumn, insertRow } from './commands/insert';
9
- import { deleteTable, deleteTableIfSelected, setMultipleCellAttrs } from './commands/misc';
9
+ import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs } from './commands/misc';
10
10
  import { sortByColumn } from './commands/sort';
11
11
  import { splitCell } from './commands/split-cell';
12
12
  import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
@@ -232,6 +232,31 @@ export const deleteColumnsWithAnalytics = editorAnalyticsAPI => (inputMethod, re
232
232
  eventType: EVENT_TYPE.TRACK
233
233
  };
234
234
  })(editorAnalyticsAPI)(deleteColumnsCommand(rect));
235
+ export const deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = editorAnalyticsAPI => (state, dispatch) => {
236
+ const {
237
+ selection
238
+ } = state;
239
+ const isCellSelection = selection instanceof CellSelection;
240
+ if (!isCellSelection) {
241
+ return false;
242
+ }
243
+ const rect = getSelectionRect(selection);
244
+ if (!rect) {
245
+ return false;
246
+ }
247
+ const selectionType = getTableSelectionType(selection);
248
+ if (selectionType === 'row') {
249
+ const {
250
+ pluginConfig
251
+ } = getPluginState(state);
252
+ const isHeaderRowRequired = pluginConfig.isHeaderRowRequired || false;
253
+ return deleteRowsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, rect, isHeaderRowRequired)(state, dispatch);
254
+ } else if (selectionType === 'column') {
255
+ return deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, rect)(state, dispatch);
256
+ } else {
257
+ return false;
258
+ }
259
+ };
235
260
  const getTableDeletedAnalytics = (selection, inputMethod) => {
236
261
  const {
237
262
  totalRowCount,
@@ -140,7 +140,12 @@ const tablesPlugin = ({
140
140
  // plugin as it is currently swallowing backspace events inside tables
141
141
  {
142
142
  name: 'tableKeymap',
143
- plugin: () => keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI)
143
+ plugin: () => {
144
+ const {
145
+ dragAndDropEnabled
146
+ } = options || {};
147
+ return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled);
148
+ }
144
149
  }, {
145
150
  name: 'tableSelectionKeymap',
146
151
  plugin: () => tableSelectionKeymapPlugin(api === null || api === void 0 ? void 0 : api.selection)
@@ -1,5 +1,7 @@
1
- import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
- import { getSelectedTableInfo } from '../../utils';
1
+ import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
3
+ import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
4
+ import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
3
5
  import { withEditorAnalyticsAPI } from '../../utils/analytics';
4
6
  import { clearDropTarget, moveSource } from './commands';
5
7
  export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, status, tr) => {
@@ -63,4 +65,46 @@ export const moveSourceWithAnalytics = editorAnalyticsAPI => (inputMethod, sourc
63
65
  }
64
66
  return true;
65
67
  });
68
+ };
69
+ export const moveSourceWithAnalyticsViaShortcut = editorAnalyticsAPI => (sourceType, direction) => (state, dispatch) => {
70
+ const {
71
+ selection
72
+ } = state;
73
+ const isCellSelection = selection instanceof CellSelection;
74
+ const selectionRect = isCellSelection ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
75
+ if (!selectionRect) {
76
+ return false;
77
+ }
78
+ const isRow = sourceType === 'table-row';
79
+ const selectedIndexes = isRow ? getSelectedRowIndexes(selectionRect) : getSelectedColumnIndexes(selectionRect);
80
+
81
+ // We can move if only one row/column selected
82
+ if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
83
+ return false;
84
+ }
85
+ const sourceIndex = selectedIndexes[0];
86
+ // we can move only by one row/column
87
+ // 'direction' can only be 1 (for right or down) or -1 (for left or up)
88
+ const targetIndex = sourceIndex + direction;
89
+
90
+ // We can move only if targetIndex is a positive number and is not higher than the total number of rows/columns.
91
+ const {
92
+ totalRowCount,
93
+ totalColumnCount
94
+ } = getSelectedTableInfo(selection);
95
+ const isValidTargetIndex = targetIndex < 0 ? false : isRow ? targetIndex <= totalRowCount - 1 : targetIndex <= totalColumnCount - 1;
96
+ if (!isValidTargetIndex) {
97
+ return false;
98
+ }
99
+
100
+ // We can move only if there are no merged cells in the source or target row/column
101
+ const hasMergedCellsInSource = isRow ? hasMergedCellsInRow(sourceIndex)(selection) : hasMergedCellsInColumn(sourceIndex)(selection);
102
+ if (hasMergedCellsInSource) {
103
+ return false;
104
+ }
105
+ const hasMergedCellsInTarget = isRow ? hasMergedCellsInRow(targetIndex)(selection) : hasMergedCellsInColumn(targetIndex)(selection);
106
+ if (hasMergedCellsInTarget) {
107
+ return false;
108
+ }
109
+ return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, sourceIndex, targetIndex)(state, dispatch);
66
110
  };
@@ -1,10 +1,11 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, nextCell, previousCell, toggleTable } from '@atlaskit/editor-common/keymaps';
2
+ import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, deleteColumn, deleteRow, moveColumnLeft, moveColumnRight, moveRowDown, moveRowUp, nextCell, previousCell, toggleTable } from '@atlaskit/editor-common/keymaps';
3
3
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
4
4
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { createTable, goToNextCell, moveCursorBackward, triggerUnlessTableHeader } from '../commands';
6
- import { addRowAroundSelection, deleteTableIfSelectedWithAnalytics, emptyMultipleCellsWithAnalytics } from '../commands-with-analytics';
6
+ import { addRowAroundSelection, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut, deleteTableIfSelectedWithAnalytics, emptyMultipleCellsWithAnalytics } from '../commands-with-analytics';
7
7
  import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand } from '../commands/insert';
8
+ import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
8
9
  import { withEditorAnalyticsAPI } from '../utils/analytics';
9
10
  const createTableWithAnalytics = editorAnalyticsAPI => withEditorAnalyticsAPI({
10
11
  action: ACTION.INSERTED,
@@ -15,7 +16,7 @@ const createTableWithAnalytics = editorAnalyticsAPI => withEditorAnalyticsAPI({
15
16
  },
16
17
  eventType: EVENT_TYPE.TRACK
17
18
  })(editorAnalyticsAPI)(createTable());
18
- export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI) {
19
+ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
19
20
  const list = {};
20
21
  bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
21
22
  bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
@@ -28,6 +29,17 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI) {
28
29
  bindKeymapWithCommand(addRowAfter.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
29
30
  bindKeymapWithCommand(addColumnBefore.common, triggerUnlessTableHeader(addColumnBeforeCommand(getEditorContainerWidth)), list);
30
31
  bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(getEditorContainerWidth), list);
32
+ if (dragAndDropEnabled) {
33
+ // Move row/column shortcuts
34
+ bindKeymapWithCommand(moveRowDown.common, moveSourceWithAnalyticsViaShortcut(editorAnalyticsAPI)('table-row', 1), list);
35
+ bindKeymapWithCommand(moveRowUp.common, moveSourceWithAnalyticsViaShortcut(editorAnalyticsAPI)('table-row', -1), list);
36
+ bindKeymapWithCommand(moveColumnLeft.common, moveSourceWithAnalyticsViaShortcut(editorAnalyticsAPI)('table-column', -1), list);
37
+ bindKeymapWithCommand(moveColumnRight.common, moveSourceWithAnalyticsViaShortcut(editorAnalyticsAPI)('table-column', 1), list);
38
+
39
+ // Delete row/column shortcuts
40
+ bindKeymapWithCommand(deleteColumn.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
41
+ bindKeymapWithCommand(deleteRow.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
42
+ }
31
43
  return keymap(list);
32
44
  }
33
45
  export default keymapPlugin;
@@ -65,6 +65,6 @@ export const STICKY_HEADER_TOGGLE_TOLERANCE_MS = 5;
65
65
  // table margins and padding. For example a guideline at 1800px and the view at 1860px wide, means the guidelines is visible
66
66
  // BUT it cannot be snapped to during resize due to padding being applied to the resizer wrapper. This accommodates that difference.
67
67
  export const TABLE_GUIDELINE_VISIBLE_ADJUSTMENT = -68;
68
- export const dragMenuDropdownWidth = 240;
68
+ export const dragMenuDropdownWidth = 250;
69
69
  export const dragTableInsertColumnButtonSize = 16;
70
70
  export const dropTargetExtendedWidth = 150;