@atlaskit/editor-tables 2.3.11 → 2.3.13

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 (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/cell-bookmark.js +2 -3
  3. package/dist/cjs/cell-selection.js +1 -2
  4. package/dist/cjs/pm-plugins/input.js +2 -3
  5. package/dist/cjs/pm-plugins/plugin-key.js +2 -4
  6. package/dist/cjs/table-map.js +4 -8
  7. package/dist/cjs/utils/add-column-at.js +2 -3
  8. package/dist/cjs/utils/add-row-at.js +3 -5
  9. package/dist/cjs/utils/clone-tr.js +2 -3
  10. package/dist/cjs/utils/create-table.js +2 -3
  11. package/dist/cjs/utils/empty-cells.js +2 -3
  12. package/dist/cjs/utils/find.js +5 -9
  13. package/dist/cjs/utils/for-each-cell.js +3 -5
  14. package/dist/cjs/utils/get-cells-in-column.js +2 -3
  15. package/dist/cjs/utils/get-cells-in-row.js +2 -3
  16. package/dist/cjs/utils/get-cells-in-table.js +2 -3
  17. package/dist/cjs/utils/get-selection-range-in-column.js +2 -3
  18. package/dist/cjs/utils/get-selection-range-in-row.js +2 -3
  19. package/dist/cjs/utils/get-selection-rect.js +2 -3
  20. package/dist/cjs/utils/is-selected.js +5 -9
  21. package/dist/cjs/utils/move-column.js +12 -4
  22. package/dist/cjs/utils/move-row.js +12 -4
  23. package/dist/cjs/utils/remove-column.js +4 -7
  24. package/dist/cjs/utils/remove-row.js +4 -7
  25. package/dist/cjs/utils/remove-table.js +2 -3
  26. package/dist/cjs/utils/reorder-utils.js +7 -13
  27. package/dist/cjs/utils/replace-table.js +2 -3
  28. package/dist/cjs/utils/select-nodes.js +54 -10
  29. package/dist/cjs/utils/set-cell-attrs.js +2 -3
  30. package/dist/cjs/utils/split-cell.js +2 -3
  31. package/dist/cjs/utils/test-utils.js +5 -9
  32. package/dist/cjs/utils/uuid.js +4 -5
  33. package/dist/es2019/utils/move-column.js +10 -1
  34. package/dist/es2019/utils/move-row.js +10 -1
  35. package/dist/es2019/utils/select-nodes.js +49 -1
  36. package/dist/esm/pm-plugins/input.js +1 -1
  37. package/dist/esm/utils/move-column.js +10 -1
  38. package/dist/esm/utils/move-row.js +10 -1
  39. package/dist/esm/utils/select-nodes.js +49 -1
  40. package/dist/types/utils/move-column.d.ts +1 -1
  41. package/dist/types/utils/move-row.d.ts +1 -1
  42. package/dist/types/utils/select-nodes.d.ts +2 -2
  43. package/dist/types-ts4.5/utils/move-column.d.ts +1 -1
  44. package/dist/types-ts4.5/utils/move-row.d.ts +1 -1
  45. package/dist/types-ts4.5/utils/select-nodes.d.ts +2 -2
  46. package/package.json +9 -2
@@ -33,7 +33,7 @@ var _tableMap = require("../table-map");
33
33
  // ['a3', 'b3', 'c3', 'd3'],
34
34
  // ]
35
35
  // ```
36
- var transpose = function transpose(array) {
36
+ var transpose = exports.transpose = function transpose(array) {
37
37
  return array[0].map(function (_, i) {
38
38
  return array.map(function (column) {
39
39
  return column[i];
@@ -67,8 +67,7 @@ var transpose = function transpose(array) {
67
67
  // |______|______|______|______|
68
68
  // ```
69
69
  //
70
- exports.transpose = transpose;
71
- var convertArrayOfRowsToTableNode = function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {
70
+ var convertArrayOfRowsToTableNode = exports.convertArrayOfRowsToTableNode = function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {
72
71
  var rowsPM = [];
73
72
  var map = _tableMap.TableMap.get(tableNode);
74
73
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
@@ -92,7 +91,6 @@ var convertArrayOfRowsToTableNode = function convertArrayOfRowsToTableNode(table
92
91
  var newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
93
92
  return newTable;
94
93
  };
95
- exports.convertArrayOfRowsToTableNode = convertArrayOfRowsToTableNode;
96
94
  var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOrigin, indexesTarget, directionOverride) {
97
95
  var direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
98
96
  var rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
@@ -137,7 +135,7 @@ var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOr
137
135
  // [A3. B3, C2, null],
138
136
  // ]
139
137
  // ```
140
- var convertTableNodeToArrayOfRows = function convertTableNodeToArrayOfRows(tableNode) {
138
+ var convertTableNodeToArrayOfRows = exports.convertTableNodeToArrayOfRows = function convertTableNodeToArrayOfRows(tableNode) {
141
139
  var map = _tableMap.TableMap.get(tableNode);
142
140
  var rows = [];
143
141
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
@@ -158,21 +156,18 @@ var convertTableNodeToArrayOfRows = function convertTableNodeToArrayOfRows(table
158
156
  }
159
157
  return rows;
160
158
  };
161
- exports.convertTableNodeToArrayOfRows = convertTableNodeToArrayOfRows;
162
- var moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction) {
159
+ var moveTableRow = exports.moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction) {
163
160
  var rows = convertTableNodeToArrayOfRows(table.node);
164
161
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
165
162
  return convertArrayOfRowsToTableNode(table.node, rows);
166
163
  };
167
- exports.moveTableRow = moveTableRow;
168
- var moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction) {
164
+ var moveTableColumn = exports.moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction) {
169
165
  var rows = transpose(convertTableNodeToArrayOfRows(table.node));
170
166
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
171
167
  rows = transpose(rows);
172
168
  return convertArrayOfRowsToTableNode(table.node, rows);
173
169
  };
174
- exports.moveTableColumn = moveTableColumn;
175
- var isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type) {
170
+ var isValidReorder = exports.isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type) {
176
171
  var direction = originIndex > targetIndex ? -1 : 1;
177
172
  var errorMessage = "Target position is invalid, you can't move the ".concat(type, " ").concat(originIndex, " to ").concat(targetIndex, ", the target can't be split. You could use tryToFit option.");
178
173
  if (direction === 1) {
@@ -185,5 +180,4 @@ var isValidReorder = function isValidReorder(originIndex, targetIndex, targets,
185
180
  }
186
181
  }
187
182
  return true;
188
- };
189
- exports.isValidReorder = isValidReorder;
183
+ };
@@ -8,7 +8,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _find = require("./find");
10
10
  var _isSelected = require("./is-selected");
11
- var replaceSelectedTable = function replaceSelectedTable(state, content) {
11
+ var replaceSelectedTable = exports.replaceSelectedTable = function replaceSelectedTable(state, content) {
12
12
  if ((0, _isSelected.isTableSelected)(state.selection)) {
13
13
  var table = (0, _find.findTable)(state.selection);
14
14
  if (table) {
@@ -19,5 +19,4 @@ var replaceSelectedTable = function replaceSelectedTable(state, content) {
19
19
  }
20
20
  }
21
21
  return state.tr;
22
- };
23
- exports.replaceSelectedTable = replaceSelectedTable;
22
+ };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.selectTableClosestToPos = exports.selectTable = exports.selectRow = exports.selectColumn = void 0;
7
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
7
8
  var _cellSelection = require("../cell-selection");
8
9
  var _tableMap = require("../table-map");
9
10
  var _cloneTr = require("./clone-tr");
@@ -13,6 +14,8 @@ var select = function select(type) {
13
14
  return function (tr) {
14
15
  var table = (0, _find.findTable)(tr.selection);
15
16
  var isRowSelection = type === 'row';
17
+ var prevSelection = tr.selection;
18
+ var isPrevRowSelection = !!prevSelection.$anchorCell && !!prevSelection.$headCell;
16
19
  if (table) {
17
20
  var map = _tableMap.TableMap.get(table.node);
18
21
 
@@ -22,6 +25,7 @@ var select = function select(type) {
22
25
  var top = isRowSelection ? index : 0;
23
26
  var right = isRowSelection ? map.width : index + 1;
24
27
  var bottom = isRowSelection ? index + 1 : map.height;
28
+ var cellsInFirstRow = [];
25
29
  if (expand) {
26
30
  var cell = (0, _find.findCellClosestToPos)(tr.selection.$from);
27
31
  if (!cell) {
@@ -31,12 +35,56 @@ var select = function select(type) {
31
35
  if (isRowSelection) {
32
36
  top = Math.min(top, selRect.top);
33
37
  bottom = Math.max(bottom, selRect.bottom);
38
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-shift-click-selection-backward')) {
39
+ cellsInFirstRow = map.cellsInRect({
40
+ left: left,
41
+ top: top,
42
+ right: right,
43
+ bottom: top + 1
44
+ });
45
+ var targetRowCells = map.cellsInRect({
46
+ left: left,
47
+ top: index,
48
+ right: right,
49
+ bottom: index + 1
50
+ });
51
+ var isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
52
+ if (isBackwardSelection && isPrevRowSelection) {
53
+ var _head = table.start + cellsInFirstRow[0];
54
+ var _anchor = prevSelection.$anchorCell.pos;
55
+ var _$head = tr.doc.resolve(_head);
56
+ var _$anchor = tr.doc.resolve(_anchor);
57
+ return (0, _cloneTr.cloneTr)(tr.setSelection(new _cellSelection.CellSelection(_$anchor, _$head)));
58
+ }
59
+ }
34
60
  } else {
35
61
  left = Math.min(left, selRect.left);
36
62
  right = Math.max(right, selRect.right);
63
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-shift-click-selection-backward')) {
64
+ cellsInFirstRow = map.cellsInRect({
65
+ left: left,
66
+ top: top,
67
+ right: left + 1,
68
+ bottom: bottom
69
+ });
70
+ var _targetRowCells = map.cellsInRect({
71
+ left: index,
72
+ top: top,
73
+ right: index + 1,
74
+ bottom: bottom
75
+ });
76
+ var _isBackwardSelection = _targetRowCells[0] < prevSelection.$head.pos;
77
+ if (_isBackwardSelection && isPrevRowSelection) {
78
+ var _head2 = table.start + cellsInFirstRow[0];
79
+ var _anchor2 = prevSelection.$anchorCell.pos;
80
+ var _$head2 = tr.doc.resolve(_head2);
81
+ var _$anchor2 = tr.doc.resolve(_anchor2);
82
+ return (0, _cloneTr.cloneTr)(tr.setSelection(new _cellSelection.CellSelection(_$anchor2, _$head2)));
83
+ }
84
+ }
37
85
  }
38
86
  }
39
- var cellsInFirstRow = map.cellsInRect({
87
+ cellsInFirstRow = map.cellsInRect({
40
88
  left: left,
41
89
  top: top,
42
90
  right: isRowSelection ? right : left + 1,
@@ -62,16 +110,14 @@ var select = function select(type) {
62
110
 
63
111
  // Returns a new transaction that selects a column at index `columnIndex`.
64
112
  // Use the optional `expand` param to extend from current selection.
65
- var selectColumn = select('column');
113
+ var selectColumn = exports.selectColumn = select('column');
66
114
 
67
115
  // Returns a new transaction that selects a row at index `rowIndex`.
68
116
  // Use the optional `expand` param to extend from current selection.
69
- exports.selectColumn = selectColumn;
70
- var selectRow = select('row');
117
+ var selectRow = exports.selectRow = select('row');
71
118
 
72
119
  // Returns a new transaction that selects a table.
73
- exports.selectRow = selectRow;
74
- var selectTable = function selectTable(tr) {
120
+ var selectTable = exports.selectTable = function selectTable(tr) {
75
121
  var table = (0, _find.findTable)(tr.selection);
76
122
  if (table) {
77
123
  var _TableMap$get = _tableMap.TableMap.get(table.node),
@@ -86,8 +132,7 @@ var selectTable = function selectTable(tr) {
86
132
  }
87
133
  return tr;
88
134
  };
89
- exports.selectTable = selectTable;
90
- var selectTableClosestToPos = function selectTableClosestToPos(tr, $pos) {
135
+ var selectTableClosestToPos = exports.selectTableClosestToPos = function selectTableClosestToPos(tr, $pos) {
91
136
  var table = (0, _find.findTableClosestToPos)($pos);
92
137
  if (table) {
93
138
  var _TableMap$get2 = _tableMap.TableMap.get(table.node),
@@ -101,5 +146,4 @@ var selectTableClosestToPos = function selectTableClosestToPos(tr, $pos) {
101
146
  }
102
147
  }
103
148
  return tr;
104
- };
105
- exports.selectTableClosestToPos = selectTableClosestToPos;
149
+ };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.setCellAttrs = void 0;
7
7
  var _cloneTr = require("./clone-tr");
8
8
  // Returns a new transaction that sets given `attrs` to a given `cell`.
9
- var setCellAttrs = function setCellAttrs(cell, attrs) {
9
+ var setCellAttrs = exports.setCellAttrs = function setCellAttrs(cell, attrs) {
10
10
  return function (tr) {
11
11
  if (cell) {
12
12
  tr.setNodeMarkup(cell.pos, undefined, Object.assign({}, cell.node.attrs, attrs));
@@ -14,5 +14,4 @@ var setCellAttrs = function setCellAttrs(cell, attrs) {
14
14
  }
15
15
  return tr;
16
16
  };
17
- };
18
- exports.setCellAttrs = setCellAttrs;
17
+ };
@@ -8,11 +8,10 @@ var _splitCellWithType = require("./split-cell-with-type");
8
8
  var _tableNodeTypes = require("./table-node-types");
9
9
  // Split a selected cell, whose rowpan or colspan is greater than one,
10
10
  // into smaller cells. Use the first cell type for the new cells.
11
- var splitCell = function splitCell(state, dispatch) {
11
+ var splitCell = exports.splitCell = function splitCell(state, dispatch) {
12
12
  var nodeTypes = (0, _tableNodeTypes.tableNodeTypes)(state.schema);
13
13
  return (0, _splitCellWithType.splitCellWithType)(function (_ref) {
14
14
  var node = _ref.node;
15
15
  return nodeTypes[node.type.spec.tableRole];
16
16
  })(state, dispatch);
17
- };
18
- exports.splitCell = splitCell;
17
+ };
@@ -10,7 +10,7 @@ var _selectionRect = require("./selection-rect");
10
10
  var _tables = require("./tables");
11
11
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
12
12
  // Add a table row before the selection.
13
- var addRowBefore = function addRowBefore(state, dispatch) {
13
+ var addRowBefore = exports.addRowBefore = function addRowBefore(state, dispatch) {
14
14
  if (!(0, _tables.isInTable)(state)) {
15
15
  return false;
16
16
  }
@@ -23,8 +23,7 @@ var addRowBefore = function addRowBefore(state, dispatch) {
23
23
 
24
24
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
25
25
  // Add a table row after the selection.
26
- exports.addRowBefore = addRowBefore;
27
- var addRowAfter = function addRowAfter(state, dispatch) {
26
+ var addRowAfter = exports.addRowAfter = function addRowAfter(state, dispatch) {
28
27
  if (!(0, _tables.isInTable)(state)) {
29
28
  return false;
30
29
  }
@@ -37,8 +36,7 @@ var addRowAfter = function addRowAfter(state, dispatch) {
37
36
 
38
37
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
39
38
  // Command to add a column before the column with the selection.
40
- exports.addRowAfter = addRowAfter;
41
- var addColumnBefore = function addColumnBefore(state, dispatch) {
39
+ var addColumnBefore = exports.addColumnBefore = function addColumnBefore(state, dispatch) {
42
40
  if (!(0, _tables.isInTable)(state)) {
43
41
  return false;
44
42
  }
@@ -51,8 +49,7 @@ var addColumnBefore = function addColumnBefore(state, dispatch) {
51
49
 
52
50
  // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
53
51
  // Command to add a column after the column with the selection.
54
- exports.addColumnBefore = addColumnBefore;
55
- var addColumnAfter = function addColumnAfter(state, dispatch) {
52
+ var addColumnAfter = exports.addColumnAfter = function addColumnAfter(state, dispatch) {
56
53
  if (!(0, _tables.isInTable)(state)) {
57
54
  return false;
58
55
  }
@@ -61,5 +58,4 @@ var addColumnAfter = function addColumnAfter(state, dispatch) {
61
58
  dispatch((0, _addColumn.addColumn)(state.tr, rect, rect.right));
62
59
  }
63
60
  return true;
64
- };
65
- exports.addColumnAfter = addColumnAfter;
61
+ };
@@ -10,21 +10,20 @@ exports.uuid = exports.generateUuid = void 0;
10
10
  */
11
11
 
12
12
  /* eslint-disable no-bitwise */
13
- var generateUuid = function generateUuid() {
13
+ var generateUuid = exports.generateUuid = function generateUuid() {
14
14
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
15
15
  var r = Math.random() * 16 | 0;
16
16
  return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
17
17
  });
18
18
  };
19
19
  /* eslint-enable no-bitwise */
20
- exports.generateUuid = generateUuid;
20
+
21
21
  var staticValue = false;
22
- var uuid = {
22
+ var uuid = exports.uuid = {
23
23
  setStatic: function setStatic(value) {
24
24
  staticValue = value;
25
25
  },
26
26
  generate: function generate() {
27
27
  return staticValue || generateUuid();
28
28
  }
29
- };
30
- exports.uuid = uuid;
29
+ };
@@ -1,3 +1,5 @@
1
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
3
  import { cloneTr } from './clone-tr';
2
4
  import { findTable } from './find';
3
5
  import { getSelectionRangeInColumn } from './get-selection-range-in-column';
@@ -140,6 +142,7 @@ export const moveColumn = (originColumnIndex, targetColumnIndex, options = {
140
142
  if (!table) {
141
143
  return tr;
142
144
  }
145
+ const anchor = tr.selection.anchor;
143
146
  const originalColumnRanges = getSelectionRangeInColumn(originColumnIndex)(tr);
144
147
  const targetColumnRanges = getSelectionRangeInColumn(targetColumnIndex)(tr);
145
148
  const indexesOriginColumn = (_originalColumnRanges = originalColumnRanges === null || originalColumnRanges === void 0 ? void 0 : originalColumnRanges.indexes) !== null && _originalColumnRanges !== void 0 ? _originalColumnRanges : [];
@@ -151,5 +154,11 @@ export const moveColumn = (originColumnIndex, targetColumnIndex, options = {
151
154
  isValidReorder(originColumnIndex, targetColumnIndex, indexesTargetColumn, 'column');
152
155
  }
153
156
  const newTable = moveTableColumn(table, indexesOriginColumn, indexesTargetColumn, options.direction);
154
- return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
157
+ const newTr = cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
158
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
159
+ // Set selection inside a newly created table
160
+ return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
161
+ } else {
162
+ return newTr;
163
+ }
155
164
  };
@@ -1,3 +1,5 @@
1
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
3
  import { cloneTr } from './clone-tr';
2
4
  import { findTable } from './find';
3
5
  import { getSelectionRangeInRow } from './get-selection-range-in-row';
@@ -154,6 +156,7 @@ export const moveRow = (originRowIndex, targetRowIndex, options = {
154
156
  if (!table) {
155
157
  return tr;
156
158
  }
159
+ const anchor = tr.selection.anchor;
157
160
  const originalRowRanges = getSelectionRangeInRow(originRowIndex)(tr);
158
161
  const targetRowRanges = getSelectionRangeInRow(targetRowIndex)(tr);
159
162
  const indexesOriginRow = (originalRowRanges === null || originalRowRanges === void 0 ? void 0 : originalRowRanges.indexes) || [];
@@ -165,5 +168,11 @@ export const moveRow = (originRowIndex, targetRowIndex, options = {
165
168
  isValidReorder(originRowIndex, targetRowIndex, indexesTargetRow, 'row');
166
169
  }
167
170
  const newTable = moveTableRow(table, indexesOriginRow, indexesTargetRow, options.direction);
168
- return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
171
+ const newTr = cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
172
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
173
+ // Set selection inside a newly created table
174
+ return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
175
+ } else {
176
+ return newTr;
177
+ }
169
178
  };
@@ -1,3 +1,4 @@
1
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
2
  import { CellSelection } from '../cell-selection';
2
3
  import { TableMap } from '../table-map';
3
4
  import { cloneTr } from './clone-tr';
@@ -5,6 +6,8 @@ import { findCellClosestToPos, findTable, findTableClosestToPos } from './find';
5
6
  const select = type => (index, expand) => tr => {
6
7
  const table = findTable(tr.selection);
7
8
  const isRowSelection = type === 'row';
9
+ const prevSelection = tr.selection;
10
+ const isPrevRowSelection = !!prevSelection.$anchorCell && !!prevSelection.$headCell;
8
11
  if (table) {
9
12
  const map = TableMap.get(table.node);
10
13
 
@@ -14,6 +17,7 @@ const select = type => (index, expand) => tr => {
14
17
  let top = isRowSelection ? index : 0;
15
18
  let right = isRowSelection ? map.width : index + 1;
16
19
  let bottom = isRowSelection ? index + 1 : map.height;
20
+ let cellsInFirstRow = [];
17
21
  if (expand) {
18
22
  const cell = findCellClosestToPos(tr.selection.$from);
19
23
  if (!cell) {
@@ -23,12 +27,56 @@ const select = type => (index, expand) => tr => {
23
27
  if (isRowSelection) {
24
28
  top = Math.min(top, selRect.top);
25
29
  bottom = Math.max(bottom, selRect.bottom);
30
+ if (getBooleanFF('platform.editor.table-shift-click-selection-backward')) {
31
+ cellsInFirstRow = map.cellsInRect({
32
+ left,
33
+ top,
34
+ right,
35
+ bottom: top + 1
36
+ });
37
+ const targetRowCells = map.cellsInRect({
38
+ left,
39
+ top: index,
40
+ right,
41
+ bottom: index + 1
42
+ });
43
+ const isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
44
+ if (isBackwardSelection && isPrevRowSelection) {
45
+ const head = table.start + cellsInFirstRow[0];
46
+ const anchor = prevSelection.$anchorCell.pos;
47
+ const $head = tr.doc.resolve(head);
48
+ const $anchor = tr.doc.resolve(anchor);
49
+ return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
50
+ }
51
+ }
26
52
  } else {
27
53
  left = Math.min(left, selRect.left);
28
54
  right = Math.max(right, selRect.right);
55
+ if (getBooleanFF('platform.editor.table-shift-click-selection-backward')) {
56
+ cellsInFirstRow = map.cellsInRect({
57
+ left,
58
+ top,
59
+ right: left + 1,
60
+ bottom
61
+ });
62
+ const targetRowCells = map.cellsInRect({
63
+ left: index,
64
+ top,
65
+ right: index + 1,
66
+ bottom
67
+ });
68
+ const isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
69
+ if (isBackwardSelection && isPrevRowSelection) {
70
+ const head = table.start + cellsInFirstRow[0];
71
+ const anchor = prevSelection.$anchorCell.pos;
72
+ const $head = tr.doc.resolve(head);
73
+ const $anchor = tr.doc.resolve(anchor);
74
+ return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
75
+ }
76
+ }
29
77
  }
30
78
  }
31
- const cellsInFirstRow = map.cellsInRect({
79
+ cellsInFirstRow = map.cellsInRect({
32
80
  left,
33
81
  top,
34
82
  right: isRowSelection ? right : left + 1,
@@ -79,7 +79,7 @@ function shiftArrow(axis, dir) {
79
79
  var maybeTableCell = _$head.blockRange($anchor);
80
80
 
81
81
  // Make sure the selection is coming from the same cell
82
- var sameCell = ['tableCell', 'tableHeader'].includes((maybeTableCell === null || maybeTableCell === void 0 ? void 0 : (_maybeTableCell$paren = maybeTableCell.parent) === null || _maybeTableCell$paren === void 0 ? void 0 : _maybeTableCell$paren.type.name) || '');
82
+ var sameCell = ['tableCell', 'tableHeader'].includes((maybeTableCell === null || maybeTableCell === void 0 || (_maybeTableCell$paren = maybeTableCell.parent) === null || _maybeTableCell$paren === void 0 ? void 0 : _maybeTableCell$paren.type.name) || '');
83
83
  if (!sameCell) {
84
84
  return false;
85
85
  }
@@ -1,3 +1,5 @@
1
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
3
  import { cloneTr } from './clone-tr';
2
4
  import { findTable } from './find';
3
5
  import { getSelectionRangeInColumn } from './get-selection-range-in-column';
@@ -142,6 +144,7 @@ export var moveColumn = function moveColumn(originColumnIndex, targetColumnIndex
142
144
  if (!table) {
143
145
  return tr;
144
146
  }
147
+ var anchor = tr.selection.anchor;
145
148
  var originalColumnRanges = getSelectionRangeInColumn(originColumnIndex)(tr);
146
149
  var targetColumnRanges = getSelectionRangeInColumn(targetColumnIndex)(tr);
147
150
  var indexesOriginColumn = (_originalColumnRanges = originalColumnRanges === null || originalColumnRanges === void 0 ? void 0 : originalColumnRanges.indexes) !== null && _originalColumnRanges !== void 0 ? _originalColumnRanges : [];
@@ -153,6 +156,12 @@ export var moveColumn = function moveColumn(originColumnIndex, targetColumnIndex
153
156
  isValidReorder(originColumnIndex, targetColumnIndex, indexesTargetColumn, 'column');
154
157
  }
155
158
  var newTable = moveTableColumn(table, indexesOriginColumn, indexesTargetColumn, options.direction);
156
- return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
159
+ var newTr = cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
160
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
161
+ // Set selection inside a newly created table
162
+ return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
163
+ } else {
164
+ return newTr;
165
+ }
157
166
  };
158
167
  };
@@ -1,3 +1,5 @@
1
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
3
  import { cloneTr } from './clone-tr';
2
4
  import { findTable } from './find';
3
5
  import { getSelectionRangeInRow } from './get-selection-range-in-row';
@@ -156,6 +158,7 @@ export var moveRow = function moveRow(originRowIndex, targetRowIndex) {
156
158
  if (!table) {
157
159
  return tr;
158
160
  }
161
+ var anchor = tr.selection.anchor;
159
162
  var originalRowRanges = getSelectionRangeInRow(originRowIndex)(tr);
160
163
  var targetRowRanges = getSelectionRangeInRow(targetRowIndex)(tr);
161
164
  var indexesOriginRow = (originalRowRanges === null || originalRowRanges === void 0 ? void 0 : originalRowRanges.indexes) || [];
@@ -167,6 +170,12 @@ export var moveRow = function moveRow(originRowIndex, targetRowIndex) {
167
170
  isValidReorder(originRowIndex, targetRowIndex, indexesTargetRow, 'row');
168
171
  }
169
172
  var newTable = moveTableRow(table, indexesOriginRow, indexesTargetRow, options.direction);
170
- return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
173
+ var newTr = cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
174
+ if (getBooleanFF('platform.editor.table.drag-and-drop')) {
175
+ // Set selection inside a newly created table
176
+ return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
177
+ } else {
178
+ return newTr;
179
+ }
171
180
  };
172
181
  };
@@ -1,3 +1,4 @@
1
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
2
  import { CellSelection } from '../cell-selection';
2
3
  import { TableMap } from '../table-map';
3
4
  import { cloneTr } from './clone-tr';
@@ -7,6 +8,8 @@ var select = function select(type) {
7
8
  return function (tr) {
8
9
  var table = findTable(tr.selection);
9
10
  var isRowSelection = type === 'row';
11
+ var prevSelection = tr.selection;
12
+ var isPrevRowSelection = !!prevSelection.$anchorCell && !!prevSelection.$headCell;
10
13
  if (table) {
11
14
  var map = TableMap.get(table.node);
12
15
 
@@ -16,6 +19,7 @@ var select = function select(type) {
16
19
  var top = isRowSelection ? index : 0;
17
20
  var right = isRowSelection ? map.width : index + 1;
18
21
  var bottom = isRowSelection ? index + 1 : map.height;
22
+ var cellsInFirstRow = [];
19
23
  if (expand) {
20
24
  var cell = findCellClosestToPos(tr.selection.$from);
21
25
  if (!cell) {
@@ -25,12 +29,56 @@ var select = function select(type) {
25
29
  if (isRowSelection) {
26
30
  top = Math.min(top, selRect.top);
27
31
  bottom = Math.max(bottom, selRect.bottom);
32
+ if (getBooleanFF('platform.editor.table-shift-click-selection-backward')) {
33
+ cellsInFirstRow = map.cellsInRect({
34
+ left: left,
35
+ top: top,
36
+ right: right,
37
+ bottom: top + 1
38
+ });
39
+ var targetRowCells = map.cellsInRect({
40
+ left: left,
41
+ top: index,
42
+ right: right,
43
+ bottom: index + 1
44
+ });
45
+ var isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
46
+ if (isBackwardSelection && isPrevRowSelection) {
47
+ var _head = table.start + cellsInFirstRow[0];
48
+ var _anchor = prevSelection.$anchorCell.pos;
49
+ var _$head = tr.doc.resolve(_head);
50
+ var _$anchor = tr.doc.resolve(_anchor);
51
+ return cloneTr(tr.setSelection(new CellSelection(_$anchor, _$head)));
52
+ }
53
+ }
28
54
  } else {
29
55
  left = Math.min(left, selRect.left);
30
56
  right = Math.max(right, selRect.right);
57
+ if (getBooleanFF('platform.editor.table-shift-click-selection-backward')) {
58
+ cellsInFirstRow = map.cellsInRect({
59
+ left: left,
60
+ top: top,
61
+ right: left + 1,
62
+ bottom: bottom
63
+ });
64
+ var _targetRowCells = map.cellsInRect({
65
+ left: index,
66
+ top: top,
67
+ right: index + 1,
68
+ bottom: bottom
69
+ });
70
+ var _isBackwardSelection = _targetRowCells[0] < prevSelection.$head.pos;
71
+ if (_isBackwardSelection && isPrevRowSelection) {
72
+ var _head2 = table.start + cellsInFirstRow[0];
73
+ var _anchor2 = prevSelection.$anchorCell.pos;
74
+ var _$head2 = tr.doc.resolve(_head2);
75
+ var _$anchor2 = tr.doc.resolve(_anchor2);
76
+ return cloneTr(tr.setSelection(new CellSelection(_$anchor2, _$head2)));
77
+ }
78
+ }
31
79
  }
32
80
  }
33
- var cellsInFirstRow = map.cellsInRect({
81
+ cellsInFirstRow = map.cellsInRect({
34
82
  left: left,
35
83
  top: top,
36
84
  right: isRowSelection ? right : left + 1,
@@ -1,4 +1,4 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const moveColumn: (originColumnIndex: number, targetColumnIndex: number, options?: {
3
3
  tryToFit: boolean;
4
4
  direction: number;
@@ -1,4 +1,4 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const moveRow: (originRowIndex: number, targetRowIndex: number, options?: {
3
3
  tryToFit: boolean;
4
4
  direction: number;
@@ -1,5 +1,5 @@
1
- import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const selectColumn: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
4
4
  export declare const selectRow: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
5
5
  export declare const selectTable: (tr: Transaction) => Transaction;
@@ -1,4 +1,4 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const moveColumn: (originColumnIndex: number, targetColumnIndex: number, options?: {
3
3
  tryToFit: boolean;
4
4
  direction: number;
@@ -1,4 +1,4 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const moveRow: (originRowIndex: number, targetRowIndex: number, options?: {
3
3
  tryToFit: boolean;
4
4
  direction: number;
@@ -1,5 +1,5 @@
1
- import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const selectColumn: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
4
4
  export declare const selectRow: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
5
5
  export declare const selectTable: (tr: Transaction) => Transaction;