@atlaskit/editor-plugin-table 5.3.34 → 5.3.36

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 (41) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/commands/selection.js +42 -1
  3. package/dist/cjs/plugins/table/event-handlers.js +1 -1
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +10 -4
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +5 -2
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +4 -2
  7. package/dist/cjs/plugins/table/pm-plugins/table-selection-keymap.js +2 -0
  8. package/dist/cjs/plugins/table/utils/drag-menu.js +3 -1
  9. package/dist/cjs/plugins/table/utils/transforms.js +11 -0
  10. package/dist/es2019/plugins/table/commands/selection.js +38 -1
  11. package/dist/es2019/plugins/table/event-handlers.js +1 -1
  12. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +8 -4
  13. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +5 -2
  14. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +4 -2
  15. package/dist/es2019/plugins/table/pm-plugins/table-selection-keymap.js +4 -2
  16. package/dist/es2019/plugins/table/utils/drag-menu.js +3 -1
  17. package/dist/es2019/plugins/table/utils/transforms.js +5 -0
  18. package/dist/esm/plugins/table/commands/selection.js +42 -1
  19. package/dist/esm/plugins/table/event-handlers.js +1 -1
  20. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +10 -4
  21. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +5 -2
  22. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +4 -2
  23. package/dist/esm/plugins/table/pm-plugins/table-selection-keymap.js +4 -2
  24. package/dist/esm/plugins/table/utils/drag-menu.js +3 -1
  25. package/dist/esm/plugins/table/utils/transforms.js +5 -0
  26. package/dist/types/plugins/table/commands/selection.d.ts +2 -0
  27. package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +1 -0
  28. package/dist/types/plugins/table/utils/transforms.d.ts +2 -0
  29. package/dist/types-ts4.5/plugins/table/commands/selection.d.ts +2 -0
  30. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +1 -0
  31. package/dist/types-ts4.5/plugins/table/utils/transforms.d.ts +2 -0
  32. package/package.json +2 -2
  33. package/src/plugins/table/commands/selection.ts +63 -2
  34. package/src/plugins/table/event-handlers.ts +4 -1
  35. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +26 -4
  36. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +9 -5
  37. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  38. package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +1 -0
  39. package/src/plugins/table/pm-plugins/table-selection-keymap.ts +16 -0
  40. package/src/plugins/table/utils/drag-menu.ts +7 -5
  41. package/src/plugins/table/utils/transforms.ts +10 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.36
4
+
5
+ ### Patch Changes
6
+
7
+ - [#42221](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42221) [`1f49a73a590`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1f49a73a590) - [ux] [ECA11Y-110] Selecting table columns, rows, whole table via shortcuts
8
+
9
+ ## 5.3.35
10
+
11
+ ### Patch Changes
12
+
13
+ - [#43255](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43255) [`404fa3bc44e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/404fa3bc44e) - Add requestAnimationFrame around move row/column command to fix an issue where selection would be lost
14
+ - Updated dependencies
15
+
3
16
  ## 5.3.34
4
17
 
5
18
  ### Patch Changes
@@ -3,12 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.shiftArrowUpFromTable = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
6
+ exports.shiftArrowUpFromTable = exports.selectRows = exports.selectColumns = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
10
10
  var _tableMap = require("@atlaskit/editor-tables/table-map");
11
11
  var _utils = require("@atlaskit/editor-tables/utils");
12
+ var _misc = require("../commands/misc");
12
13
  var _toolbar = require("../toolbar");
13
14
  var TableSelectionDirection = exports.TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
14
15
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
@@ -45,6 +46,46 @@ var arrowRightFromTable = exports.arrowRightFromTable = function arrowRightFromT
45
46
  };
46
47
  };
47
48
  };
49
+ var selectColumns = exports.selectColumns = function selectColumns(editorSelectionAPI) {
50
+ return function () {
51
+ return function (state, dispatch) {
52
+ var selection = state.selection;
53
+ var table = (0, _utils.findTable)(selection);
54
+ var rect = (0, _utils.selectedRect)(state);
55
+ if (table && (0, _utils.isRowSelected)(rect.top)(selection)) {
56
+ return selectFullTable(editorSelectionAPI)({
57
+ node: table.node,
58
+ startPos: table.start,
59
+ dir: TableSelectionDirection.BottomToTop
60
+ })(state, dispatch);
61
+ }
62
+ if (table && rect) {
63
+ return (0, _misc.selectColumn)(rect.left)(state, dispatch);
64
+ }
65
+ return false;
66
+ };
67
+ };
68
+ };
69
+ var selectRows = exports.selectRows = function selectRows(editorSelectionAPI) {
70
+ return function () {
71
+ return function (state, dispatch) {
72
+ var selection = state.selection;
73
+ var table = (0, _utils.findTable)(selection);
74
+ var rect = (0, _utils.selectedRect)(state);
75
+ if (table && (0, _utils.isColumnSelected)(rect.left)(selection)) {
76
+ return selectFullTable(editorSelectionAPI)({
77
+ node: table.node,
78
+ startPos: table.start,
79
+ dir: TableSelectionDirection.BottomToTop
80
+ })(state, dispatch);
81
+ }
82
+ if (table && rect) {
83
+ return (0, _misc.selectRow)(rect.top)(state, dispatch);
84
+ }
85
+ return false;
86
+ };
87
+ };
88
+ };
48
89
  var arrowLeftFromCellSelection = function arrowLeftFromCellSelection(editorSelectionAPI) {
49
90
  return function (selection) {
50
91
  return function (state, dispatch) {
@@ -359,7 +359,7 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
359
359
  };
360
360
  var withCellTracking = exports.withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
361
361
  return function (view, mouseEvent) {
362
- if ((0, _pluginFactory2.getPluginState)(view.state).isDragAndDropEnabled) {
362
+ if ((0, _pluginFactory2.getPluginState)(view.state).isDragAndDropEnabled && !(0, _pluginFactory.getPluginState)(view.state).isDragging) {
363
363
  trackCellLocation(view, mouseEvent);
364
364
  }
365
365
  return eventHandler(view, mouseEvent, elementContentRects);
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.updatePluginStateDecorations = exports.toggleDragMenu = exports.setDropTarget = exports.moveSource = exports.getDecorations = exports.clearDropTarget = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
7
8
  var _view = require("@atlaskit/editor-prosemirror/view");
8
9
  var _utils = require("@atlaskit/editor-tables/utils");
9
10
  var _types = require("../../types");
10
11
  var _utils2 = require("../../utils");
12
+ var _transforms = require("../../utils/transforms");
11
13
  var _actions = require("./actions");
12
14
  var _consts = require("./consts");
13
15
  var _pluginFactory = require("./plugin-factory");
@@ -76,11 +78,15 @@ var moveSource = exports.moveSource = function moveSource(sourceType, sourceInde
76
78
  if (sourceIndex === targetIndex) {
77
79
  return tr.setMeta('addToHistory', false);
78
80
  }
81
+ var anchor = tr.selection.anchor;
82
+ var selectStartOfTable = function selectStartOfTable(newTr) {
83
+ return newTr.setSelection(_state.TextSelection.create(newTr.doc, anchor));
84
+ };
79
85
  var isTableRow = sourceType === 'table-row';
80
- var move = isTableRow ? _utils.moveRow : _utils.moveColumn;
81
- var newTr = move(sourceIndex, targetIndex)(tr);
82
- var select = isTableRow ? _utils.selectRow : _utils.selectColumn;
83
- return select(targetIndex)(newTr);
86
+ if (isTableRow) {
87
+ return (0, _transforms.combineTransforms)([(0, _utils.moveRow)(sourceIndex, targetIndex), selectStartOfTable, (0, _utils.selectRow)(targetIndex)], tr);
88
+ }
89
+ return (0, _transforms.combineTransforms)([(0, _utils.moveColumn)(sourceIndex, targetIndex), selectStartOfTable, (0, _utils.selectColumn)(targetIndex)], tr);
84
90
  });
85
91
  };
86
92
  var toggleDragMenu = exports.toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
@@ -27,7 +27,8 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
27
27
  dropTargetType: _consts.DropTargetType.NONE,
28
28
  dropTargetIndex: 0,
29
29
  isDragMenuOpen: false,
30
- dragMenuIndex: 0
30
+ dragMenuIndex: 0,
31
+ isDragging: false
31
32
  };
32
33
  }),
33
34
  key: _pluginKey.pluginKey,
@@ -132,7 +133,9 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
132
133
  }
133
134
  var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
134
135
  sourceIndex = _sourceIndexes[0];
135
- (0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
136
+ requestAnimationFrame(function () {
137
+ (0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
138
+ });
136
139
  }
137
140
  })
138
141
  };
@@ -16,13 +16,15 @@ var _default = exports.default = function _default(pluginState, action) {
16
16
  return _objectSpread(_objectSpread({}, pluginState), {}, {
17
17
  decorationSet: action.data.decorationSet,
18
18
  dropTargetType: action.data.type,
19
- dropTargetIndex: action.data.index
19
+ dropTargetIndex: action.data.index,
20
+ isDragging: true
20
21
  });
21
22
  case _actions.DragAndDropActionType.CLEAR_DROP_TARGET:
22
23
  return _objectSpread(_objectSpread({}, pluginState), {}, {
23
24
  decorationSet: action.data.decorationSet,
24
25
  dropTargetType: _consts.DropTargetType.NONE,
25
- dropTargetIndex: 0
26
+ dropTargetIndex: 0,
27
+ isDragging: false
26
28
  });
27
29
  case _actions.DragAndDropActionType.TOGGLE_DRAG_MENU:
28
30
  return _objectSpread(_objectSpread({}, pluginState), {}, {
@@ -16,6 +16,8 @@ function tableSelectionKeymapPlugin(editorSelectionAPI) {
16
16
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.shift-arrowup-fix')) {
17
17
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.shiftArrowUp.common, (0, _selection.shiftArrowUpFromTable)(editorSelectionAPI)(), list);
18
18
  }
19
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.selectColumn.common, (0, _selection.selectColumns)(editorSelectionAPI)(), list);
20
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.selectRow.common, (0, _selection.selectRows)(editorSelectionAPI)(), list);
19
21
  return (0, _keymap.keymap)(list);
20
22
  }
21
23
  var _default = exports.default = tableSelectionKeymapPlugin;
@@ -148,7 +148,9 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
148
148
  icon: icon,
149
149
  onClick: function onClick(state, dispatch) {
150
150
  if (canMove(index)) {
151
- (0, _commands2.moveSource)("table-".concat(direction), index, index + offset)(state, dispatch);
151
+ requestAnimationFrame(function () {
152
+ (0, _commands2.moveSource)("table-".concat(direction), index, index + offset)(state, dispatch);
153
+ });
152
154
  return true;
153
155
  }
154
156
  return false;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.combineTransforms = void 0;
7
+ var combineTransforms = exports.combineTransforms = function combineTransforms(transforms, tr) {
8
+ return transforms.reduce(function (prev, curr) {
9
+ return curr(prev);
10
+ }, tr);
11
+ };
@@ -2,7 +2,8 @@ import { GapCursorSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode, R
2
2
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
- import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
5
+ import { findTable, isColumnSelected, isRowSelected, isTableSelected, selectedRect } from '@atlaskit/editor-tables/utils';
6
+ import { selectColumn, selectRow } from '../commands/misc';
6
7
  import { getClosestSelectionRect } from '../toolbar';
7
8
  export let TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
8
9
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
@@ -35,6 +36,42 @@ export const arrowRightFromTable = editorSelectionAPI => () => (state, dispatch)
35
36
  }
36
37
  return false;
37
38
  };
39
+ export const selectColumns = editorSelectionAPI => () => (state, dispatch) => {
40
+ const {
41
+ selection
42
+ } = state;
43
+ const table = findTable(selection);
44
+ const rect = selectedRect(state);
45
+ if (table && isRowSelected(rect.top)(selection)) {
46
+ return selectFullTable(editorSelectionAPI)({
47
+ node: table.node,
48
+ startPos: table.start,
49
+ dir: TableSelectionDirection.BottomToTop
50
+ })(state, dispatch);
51
+ }
52
+ if (table && rect) {
53
+ return selectColumn(rect.left)(state, dispatch);
54
+ }
55
+ return false;
56
+ };
57
+ export const selectRows = editorSelectionAPI => () => (state, dispatch) => {
58
+ const {
59
+ selection
60
+ } = state;
61
+ const table = findTable(selection);
62
+ const rect = selectedRect(state);
63
+ if (table && isColumnSelected(rect.left)(selection)) {
64
+ return selectFullTable(editorSelectionAPI)({
65
+ node: table.node,
66
+ startPos: table.start,
67
+ dir: TableSelectionDirection.BottomToTop
68
+ })(state, dispatch);
69
+ }
70
+ if (table && rect) {
71
+ return selectRow(rect.top)(state, dispatch);
72
+ }
73
+ return false;
74
+ };
38
75
  const arrowLeftFromCellSelection = editorSelectionAPI => selection => (state, dispatch) => {
39
76
  if (isTableSelected(state.selection) && editorSelectionAPI) {
40
77
  const selectionState = editorSelectionAPI.sharedState.currentState() || {};
@@ -366,7 +366,7 @@ const trackCellLocation = (view, mouseEvent) => {
366
366
  }
367
367
  };
368
368
  export const withCellTracking = (eventHandler, elementContentRects) => (view, mouseEvent) => {
369
- if (getPluginState(view.state).isDragAndDropEnabled) {
369
+ if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
370
370
  trackCellLocation(view, mouseEvent);
371
371
  }
372
372
  return eventHandler(view, mouseEvent, elementContentRects);
@@ -1,7 +1,9 @@
1
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
1
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
3
  import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
3
4
  import { TableDecorations } from '../../types';
4
5
  import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
6
+ import { combineTransforms } from '../../utils/transforms';
5
7
  import { DragAndDropActionType } from './actions';
6
8
  import { DropTargetType } from './consts';
7
9
  import { createCommand, getPluginState } from './plugin-factory';
@@ -62,11 +64,13 @@ export const moveSource = (sourceType, sourceIndex, targetIndex) => createComman
62
64
  if (sourceIndex === targetIndex) {
63
65
  return tr.setMeta('addToHistory', false);
64
66
  }
67
+ const anchor = tr.selection.anchor;
68
+ const selectStartOfTable = newTr => newTr.setSelection(TextSelection.create(newTr.doc, anchor));
65
69
  const isTableRow = sourceType === 'table-row';
66
- const move = isTableRow ? moveRow : moveColumn;
67
- const newTr = move(sourceIndex, targetIndex)(tr);
68
- const select = isTableRow ? selectRow : selectColumn;
69
- return select(targetIndex)(newTr);
70
+ if (isTableRow) {
71
+ return combineTransforms([moveRow(sourceIndex, targetIndex), selectStartOfTable, selectRow(targetIndex)], tr);
72
+ }
73
+ return combineTransforms([moveColumn(sourceIndex, targetIndex), selectStartOfTable, selectColumn(targetIndex)], tr);
70
74
  });
71
75
  export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
72
76
  let {
@@ -18,7 +18,8 @@ export const createPlugin = (dispatch, eventDispatcher) => {
18
18
  dropTargetType: DropTargetType.NONE,
19
19
  dropTargetIndex: 0,
20
20
  isDragMenuOpen: false,
21
- dragMenuIndex: 0
21
+ dragMenuIndex: 0,
22
+ isDragging: false
22
23
  })),
23
24
  key: pluginKey,
24
25
  appendTransaction: (transactions, oldState, newState) => {
@@ -132,7 +133,9 @@ export const createPlugin = (dispatch, eventDispatcher) => {
132
133
  return;
133
134
  }
134
135
  const [sourceIndex] = sourceIndexes;
135
- moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
136
+ requestAnimationFrame(() => {
137
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
138
+ });
136
139
  }
137
140
  })
138
141
  };
@@ -7,14 +7,16 @@ export default ((pluginState, action) => {
7
7
  ...pluginState,
8
8
  decorationSet: action.data.decorationSet,
9
9
  dropTargetType: action.data.type,
10
- dropTargetIndex: action.data.index
10
+ dropTargetIndex: action.data.index,
11
+ isDragging: true
11
12
  };
12
13
  case DragAndDropActionType.CLEAR_DROP_TARGET:
13
14
  return {
14
15
  ...pluginState,
15
16
  decorationSet: action.data.decorationSet,
16
17
  dropTargetType: DropTargetType.NONE,
17
- dropTargetIndex: 0
18
+ dropTargetIndex: 0,
19
+ isDragging: false
18
20
  };
19
21
  case DragAndDropActionType.TOGGLE_DRAG_MENU:
20
22
  return {
@@ -1,7 +1,7 @@
1
- import { bindKeymapWithCommand, moveLeft, moveRight, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
1
+ import { bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
2
2
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
3
3
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
- import { arrowLeftFromTable, arrowRightFromTable, shiftArrowUpFromTable } from '../commands/selection';
4
+ import { arrowLeftFromTable, arrowRightFromTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
5
5
  export function tableSelectionKeymapPlugin(editorSelectionAPI) {
6
6
  const list = {};
7
7
  bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
@@ -9,6 +9,8 @@ export function tableSelectionKeymapPlugin(editorSelectionAPI) {
9
9
  if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
10
10
  bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
11
11
  }
12
+ bindKeymapWithCommand(selectColumn.common, selectColumns(editorSelectionAPI)(), list);
13
+ bindKeymapWithCommand(selectRow.common, selectRows(editorSelectionAPI)(), list);
12
14
  return keymap(list);
13
15
  }
14
16
  export default tableSelectionKeymapPlugin;
@@ -133,7 +133,9 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, tableMap,
133
133
  icon,
134
134
  onClick: (state, dispatch) => {
135
135
  if (canMove(index)) {
136
- moveSource(`table-${direction}`, index, index + offset)(state, dispatch);
136
+ requestAnimationFrame(() => {
137
+ moveSource(`table-${direction}`, index, index + offset)(state, dispatch);
138
+ });
137
139
  return true;
138
140
  }
139
141
  return false;
@@ -0,0 +1,5 @@
1
+ export const combineTransforms = (transforms, tr) => {
2
+ return transforms.reduce((prev, curr) => {
3
+ return curr(prev);
4
+ }, tr);
5
+ };
@@ -2,7 +2,8 @@ import { GapCursorSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode, R
2
2
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
- import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
5
+ import { findTable, isColumnSelected, isRowSelected, isTableSelected, selectedRect } from '@atlaskit/editor-tables/utils';
6
+ import { selectColumn, selectRow } from '../commands/misc';
6
7
  import { getClosestSelectionRect } from '../toolbar';
7
8
  export var TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
8
9
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
@@ -39,6 +40,46 @@ export var arrowRightFromTable = function arrowRightFromTable(editorSelectionAPI
39
40
  };
40
41
  };
41
42
  };
43
+ export var selectColumns = function selectColumns(editorSelectionAPI) {
44
+ return function () {
45
+ return function (state, dispatch) {
46
+ var selection = state.selection;
47
+ var table = findTable(selection);
48
+ var rect = selectedRect(state);
49
+ if (table && isRowSelected(rect.top)(selection)) {
50
+ return selectFullTable(editorSelectionAPI)({
51
+ node: table.node,
52
+ startPos: table.start,
53
+ dir: TableSelectionDirection.BottomToTop
54
+ })(state, dispatch);
55
+ }
56
+ if (table && rect) {
57
+ return selectColumn(rect.left)(state, dispatch);
58
+ }
59
+ return false;
60
+ };
61
+ };
62
+ };
63
+ export var selectRows = function selectRows(editorSelectionAPI) {
64
+ return function () {
65
+ return function (state, dispatch) {
66
+ var selection = state.selection;
67
+ var table = findTable(selection);
68
+ var rect = selectedRect(state);
69
+ if (table && isColumnSelected(rect.left)(selection)) {
70
+ return selectFullTable(editorSelectionAPI)({
71
+ node: table.node,
72
+ startPos: table.start,
73
+ dir: TableSelectionDirection.BottomToTop
74
+ })(state, dispatch);
75
+ }
76
+ if (table && rect) {
77
+ return selectRow(rect.top)(state, dispatch);
78
+ }
79
+ return false;
80
+ };
81
+ };
82
+ };
42
83
  var arrowLeftFromCellSelection = function arrowLeftFromCellSelection(editorSelectionAPI) {
43
84
  return function (selection) {
44
85
  return function (state, dispatch) {
@@ -350,7 +350,7 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
350
350
  };
351
351
  export var withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
352
352
  return function (view, mouseEvent) {
353
- if (getPluginState(view.state).isDragAndDropEnabled) {
353
+ if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
354
354
  trackCellLocation(view, mouseEvent);
355
355
  }
356
356
  return eventHandler(view, mouseEvent, elementContentRects);
@@ -1,7 +1,9 @@
1
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
1
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
3
  import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
3
4
  import { TableDecorations } from '../../types';
4
5
  import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
6
+ import { combineTransforms } from '../../utils/transforms';
5
7
  import { DragAndDropActionType } from './actions';
6
8
  import { DropTargetType } from './consts';
7
9
  import { createCommand, getPluginState } from './plugin-factory';
@@ -71,11 +73,15 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
71
73
  if (sourceIndex === targetIndex) {
72
74
  return tr.setMeta('addToHistory', false);
73
75
  }
76
+ var anchor = tr.selection.anchor;
77
+ var selectStartOfTable = function selectStartOfTable(newTr) {
78
+ return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
79
+ };
74
80
  var isTableRow = sourceType === 'table-row';
75
- var move = isTableRow ? moveRow : moveColumn;
76
- var newTr = move(sourceIndex, targetIndex)(tr);
77
- var select = isTableRow ? selectRow : selectColumn;
78
- return select(targetIndex)(newTr);
81
+ if (isTableRow) {
82
+ return combineTransforms([moveRow(sourceIndex, targetIndex), selectStartOfTable, selectRow(targetIndex)], tr);
83
+ }
84
+ return combineTransforms([moveColumn(sourceIndex, targetIndex), selectStartOfTable, selectColumn(targetIndex)], tr);
79
85
  });
80
86
  };
81
87
  export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
@@ -20,7 +20,8 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
20
20
  dropTargetType: DropTargetType.NONE,
21
21
  dropTargetIndex: 0,
22
22
  isDragMenuOpen: false,
23
- dragMenuIndex: 0
23
+ dragMenuIndex: 0,
24
+ isDragging: false
24
25
  };
25
26
  }),
26
27
  key: pluginKey,
@@ -125,7 +126,9 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
125
126
  }
126
127
  var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
127
128
  sourceIndex = _sourceIndexes[0];
128
- moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
129
+ requestAnimationFrame(function () {
130
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
131
+ });
129
132
  }
130
133
  })
131
134
  };
@@ -9,13 +9,15 @@ export default (function (pluginState, action) {
9
9
  return _objectSpread(_objectSpread({}, pluginState), {}, {
10
10
  decorationSet: action.data.decorationSet,
11
11
  dropTargetType: action.data.type,
12
- dropTargetIndex: action.data.index
12
+ dropTargetIndex: action.data.index,
13
+ isDragging: true
13
14
  });
14
15
  case DragAndDropActionType.CLEAR_DROP_TARGET:
15
16
  return _objectSpread(_objectSpread({}, pluginState), {}, {
16
17
  decorationSet: action.data.decorationSet,
17
18
  dropTargetType: DropTargetType.NONE,
18
- dropTargetIndex: 0
19
+ dropTargetIndex: 0,
20
+ isDragging: false
19
21
  });
20
22
  case DragAndDropActionType.TOGGLE_DRAG_MENU:
21
23
  return _objectSpread(_objectSpread({}, pluginState), {}, {
@@ -1,7 +1,7 @@
1
- import { bindKeymapWithCommand, moveLeft, moveRight, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
1
+ import { bindKeymapWithCommand, moveLeft, moveRight, selectColumn, selectRow, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
2
2
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
3
3
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
- import { arrowLeftFromTable, arrowRightFromTable, shiftArrowUpFromTable } from '../commands/selection';
4
+ import { arrowLeftFromTable, arrowRightFromTable, selectColumns, selectRows, shiftArrowUpFromTable } from '../commands/selection';
5
5
  export function tableSelectionKeymapPlugin(editorSelectionAPI) {
6
6
  var list = {};
7
7
  bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
@@ -9,6 +9,8 @@ export function tableSelectionKeymapPlugin(editorSelectionAPI) {
9
9
  if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
10
10
  bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
11
11
  }
12
+ bindKeymapWithCommand(selectColumn.common, selectColumns(editorSelectionAPI)(), list);
13
+ bindKeymapWithCommand(selectRow.common, selectRows(editorSelectionAPI)(), list);
12
14
  return keymap(list);
13
15
  }
14
16
  export default tableSelectionKeymapPlugin;
@@ -141,7 +141,9 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
141
141
  icon: icon,
142
142
  onClick: function onClick(state, dispatch) {
143
143
  if (canMove(index)) {
144
- moveSource("table-".concat(direction), index, index + offset)(state, dispatch);
144
+ requestAnimationFrame(function () {
145
+ moveSource("table-".concat(direction), index, index + offset)(state, dispatch);
146
+ });
145
147
  return true;
146
148
  }
147
149
  return false;
@@ -0,0 +1,5 @@
1
+ export var combineTransforms = function combineTransforms(transforms, tr) {
2
+ return transforms.reduce(function (prev, curr) {
3
+ return curr(prev);
4
+ }, tr);
5
+ };
@@ -6,4 +6,6 @@ export declare enum TableSelectionDirection {
6
6
  }
7
7
  export declare const arrowLeftFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
8
8
  export declare const arrowRightFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
9
+ export declare const selectColumns: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
10
+ export declare const selectRows: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
9
11
  export declare const shiftArrowUpFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
@@ -8,4 +8,5 @@ export interface DragAndDropPluginState {
8
8
  isDragMenuOpen: boolean;
9
9
  dragMenuDirection?: TableDirection;
10
10
  dragMenuIndex: number;
11
+ isDragging: boolean;
11
12
  }
@@ -0,0 +1,2 @@
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const combineTransforms: (transforms: ((tr: Transaction) => Transaction)[], tr: Transaction) => Transaction;
@@ -6,4 +6,6 @@ export declare enum TableSelectionDirection {
6
6
  }
7
7
  export declare const arrowLeftFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
8
8
  export declare const arrowRightFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
9
+ export declare const selectColumns: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
10
+ export declare const selectRows: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
9
11
  export declare const shiftArrowUpFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
@@ -8,4 +8,5 @@ export interface DragAndDropPluginState {
8
8
  isDragMenuOpen: boolean;
9
9
  dragMenuDirection?: TableDirection;
10
10
  dragMenuIndex: number;
11
+ isDragging: boolean;
11
12
  }
@@ -0,0 +1,2 @@
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const combineTransforms: (transforms: ((tr: Transaction) => Transaction)[], tr: Transaction) => Transaction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.34",
3
+ "version": "5.3.36",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -44,7 +44,7 @@
44
44
  "@atlaskit/pragmatic-drag-and-drop": "^0.24.0",
45
45
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.7.0",
46
46
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
47
- "@atlaskit/primitives": "^1.10.0",
47
+ "@atlaskit/primitives": "^1.11.0",
48
48
  "@atlaskit/theme": "^12.6.0",
49
49
  "@atlaskit/tokens": "^1.28.0",
50
50
  "@atlaskit/tooltip": "^18.0.0",
@@ -17,8 +17,15 @@ import type {
17
17
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
18
18
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
19
19
  import { TableMap } from '@atlaskit/editor-tables/table-map';
20
- import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
21
-
20
+ import {
21
+ findTable,
22
+ isColumnSelected,
23
+ isRowSelected,
24
+ isTableSelected,
25
+ selectedRect,
26
+ } from '@atlaskit/editor-tables/utils';
27
+
28
+ import { selectColumn, selectRow } from '../commands/misc';
22
29
  import type tablePlugin from '../index';
23
30
  import { getClosestSelectionRect } from '../toolbar';
24
31
 
@@ -78,6 +85,60 @@ export const arrowRightFromTable =
78
85
  return false;
79
86
  };
80
87
 
88
+ export const selectColumns =
89
+ (
90
+ editorSelectionAPI:
91
+ | ExtractInjectionAPI<typeof tablePlugin>['selection']
92
+ | undefined,
93
+ ) =>
94
+ (): Command =>
95
+ (state, dispatch) => {
96
+ const { selection } = state;
97
+ const table = findTable(selection);
98
+ const rect = selectedRect(state);
99
+
100
+ if (table && isRowSelected(rect.top)(selection)) {
101
+ return selectFullTable(editorSelectionAPI)({
102
+ node: table.node,
103
+ startPos: table.start,
104
+ dir: TableSelectionDirection.BottomToTop,
105
+ })(state, dispatch);
106
+ }
107
+
108
+ if (table && rect) {
109
+ return selectColumn(rect.left)(state, dispatch);
110
+ }
111
+
112
+ return false;
113
+ };
114
+
115
+ export const selectRows =
116
+ (
117
+ editorSelectionAPI:
118
+ | ExtractInjectionAPI<typeof tablePlugin>['selection']
119
+ | undefined,
120
+ ) =>
121
+ (): Command =>
122
+ (state, dispatch) => {
123
+ const { selection } = state;
124
+ const table = findTable(selection);
125
+ const rect = selectedRect(state);
126
+
127
+ if (table && isColumnSelected(rect.left)(selection)) {
128
+ return selectFullTable(editorSelectionAPI)({
129
+ node: table.node,
130
+ startPos: table.start,
131
+ dir: TableSelectionDirection.BottomToTop,
132
+ })(state, dispatch);
133
+ }
134
+
135
+ if (table && rect) {
136
+ return selectRow(rect.top)(state, dispatch);
137
+ }
138
+
139
+ return false;
140
+ };
141
+
81
142
  const arrowLeftFromCellSelection =
82
143
  (
83
144
  editorSelectionAPI:
@@ -587,7 +587,10 @@ export const withCellTracking =
587
587
  elementContentRects?: ElementContentRects,
588
588
  ) =>
589
589
  (view: EditorView, mouseEvent: Event): boolean => {
590
- if (getPluginState(view.state).isDragAndDropEnabled) {
590
+ if (
591
+ getPluginState(view.state).isDragAndDropEnabled &&
592
+ !getDragDropPluginState(view.state).isDragging
593
+ ) {
591
594
  trackCellLocation(view, mouseEvent);
592
595
  }
593
596
  return eventHandler(view, mouseEvent, elementContentRects);
@@ -2,6 +2,7 @@ import type {
2
2
  EditorState,
3
3
  Transaction,
4
4
  } from '@atlaskit/editor-prosemirror/state';
5
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
5
6
  import type { Decoration } from '@atlaskit/editor-prosemirror/view';
6
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
8
  import {
@@ -18,6 +19,7 @@ import {
18
19
  createRowInsertLine,
19
20
  updateDecorations,
20
21
  } from '../../utils';
22
+ import { combineTransforms } from '../../utils/transforms';
21
23
 
22
24
  import { DragAndDropActionType } from './actions';
23
25
  import { DropTargetType } from './consts';
@@ -114,11 +116,31 @@ export const moveSource = (
114
116
  return tr.setMeta('addToHistory', false);
115
117
  }
116
118
 
119
+ const anchor = tr.selection.anchor;
120
+ const selectStartOfTable = (newTr: Transaction) =>
121
+ newTr.setSelection(TextSelection.create(newTr.doc, anchor));
122
+
117
123
  const isTableRow = sourceType === 'table-row';
118
- const move = isTableRow ? moveRow : moveColumn;
119
- const newTr = move(sourceIndex, targetIndex)(tr);
120
- const select = isTableRow ? selectRow : selectColumn;
121
- return select(targetIndex)(newTr);
124
+
125
+ if (isTableRow) {
126
+ return combineTransforms(
127
+ [
128
+ moveRow(sourceIndex, targetIndex),
129
+ selectStartOfTable,
130
+ selectRow(targetIndex),
131
+ ],
132
+ tr,
133
+ );
134
+ }
135
+
136
+ return combineTransforms(
137
+ [
138
+ moveColumn(sourceIndex, targetIndex),
139
+ selectStartOfTable,
140
+ selectColumn(targetIndex),
141
+ ],
142
+ tr,
143
+ );
122
144
  },
123
145
  );
124
146
 
@@ -39,6 +39,7 @@ export const createPlugin = (
39
39
  dropTargetIndex: 0,
40
40
  isDragMenuOpen: false,
41
41
  dragMenuIndex: 0,
42
+ isDragging: false,
42
43
  })),
43
44
  key: pluginKey,
44
45
  appendTransaction: (transactions, oldState, newState) => {
@@ -160,11 +161,14 @@ export const createPlugin = (
160
161
  }
161
162
 
162
163
  const [sourceIndex] = sourceIndexes;
163
- moveSource(
164
- sourceType,
165
- sourceIndex,
166
- targetAdjustedIndex + (direction === -1 ? 0 : -1),
167
- )(editorView.state, editorView.dispatch);
164
+
165
+ requestAnimationFrame(() => {
166
+ moveSource(
167
+ sourceType,
168
+ sourceIndex,
169
+ targetAdjustedIndex + (direction === -1 ? 0 : -1),
170
+ )(editorView.state, editorView.dispatch);
171
+ });
168
172
  },
169
173
  }),
170
174
  };
@@ -14,6 +14,7 @@ export default (
14
14
  decorationSet: action.data.decorationSet,
15
15
  dropTargetType: action.data.type,
16
16
  dropTargetIndex: action.data.index,
17
+ isDragging: true,
17
18
  };
18
19
  case DragAndDropActionType.CLEAR_DROP_TARGET:
19
20
  return {
@@ -21,6 +22,7 @@ export default (
21
22
  decorationSet: action.data.decorationSet,
22
23
  dropTargetType: DropTargetType.NONE,
23
24
  dropTargetIndex: 0,
25
+ isDragging: false,
24
26
  };
25
27
  case DragAndDropActionType.TOGGLE_DRAG_MENU:
26
28
  return {
@@ -11,4 +11,5 @@ export interface DragAndDropPluginState {
11
11
  isDragMenuOpen: boolean;
12
12
  dragMenuDirection?: TableDirection;
13
13
  dragMenuIndex: number;
14
+ isDragging: boolean;
14
15
  }
@@ -2,6 +2,8 @@ import {
2
2
  bindKeymapWithCommand,
3
3
  moveLeft,
4
4
  moveRight,
5
+ selectColumn,
6
+ selectRow,
5
7
  shiftArrowUp,
6
8
  } from '@atlaskit/editor-common/keymaps';
7
9
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
@@ -12,6 +14,8 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
14
  import {
13
15
  arrowLeftFromTable,
14
16
  arrowRightFromTable,
17
+ selectColumns,
18
+ selectRows,
15
19
  shiftArrowUpFromTable,
16
20
  } from '../commands/selection';
17
21
  import type tablePlugin from '../index';
@@ -43,6 +47,18 @@ export function tableSelectionKeymapPlugin(
43
47
  );
44
48
  }
45
49
 
50
+ bindKeymapWithCommand(
51
+ selectColumn.common!,
52
+ selectColumns(editorSelectionAPI)(),
53
+ list,
54
+ );
55
+
56
+ bindKeymapWithCommand(
57
+ selectRow.common!,
58
+ selectRows(editorSelectionAPI)(),
59
+ list,
60
+ );
61
+
46
62
  return keymap(list) as SafePlugin;
47
63
  }
48
64
 
@@ -194,11 +194,13 @@ export const getDragMenuConfig = (
194
194
  icon,
195
195
  onClick: (state: EditorState, dispatch?: CommandDispatch) => {
196
196
  if (canMove(index)) {
197
- moveSource(
198
- `table-${direction}`,
199
- index!,
200
- index! + offset,
201
- )(state, dispatch);
197
+ requestAnimationFrame(() => {
198
+ moveSource(
199
+ `table-${direction}`,
200
+ index!,
201
+ index! + offset,
202
+ )(state, dispatch);
203
+ });
202
204
  return true;
203
205
  }
204
206
  return false;
@@ -0,0 +1,10 @@
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+
3
+ export const combineTransforms = (
4
+ transforms: Array<(tr: Transaction) => Transaction>,
5
+ tr: Transaction,
6
+ ) => {
7
+ return transforms.reduce((prev, curr) => {
8
+ return curr(prev);
9
+ }, tr);
10
+ };