@atlaskit/editor-tables 2.8.3 → 2.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-tables
2
2
 
3
+ ## 2.8.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#109026](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/109026)
8
+ [`05e5c3f595ae0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/05e5c3f595ae0) -
9
+ [ux] [ED-26076] Fixed bug where selecting from parent cell to nested table cell caused a cell
10
+ selection instead of a partial text selection.
11
+
12
+ ## 2.8.4
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 2.8.3
4
19
 
5
20
  ### Patch Changes
@@ -9,6 +9,7 @@ exports.handleTripleClick = handleTripleClick;
9
9
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
10
10
  var _model = require("@atlaskit/editor-prosemirror/model");
11
11
  var _state = require("@atlaskit/editor-prosemirror/state");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _cellSelection = require("../cell-selection");
13
14
  var _utils = require("../utils");
14
15
  var _cells = require("../utils/cells");
@@ -205,13 +206,20 @@ function handleMouseDown(view, event, dragAndDropEnabled) {
205
206
  }
206
207
  function move(event) {
207
208
  var anchor = _pluginKey.tableEditingKey.getState(view.state);
209
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
210
+ var currDOMCell = domInCell(view, event.target);
211
+ var isCurrCellInsideNestedTable = isInsideNestedTable(view, event);
212
+ var isStartCellInsideNestedTable = isInsideNestedTable(view, startEvent);
213
+ var isBothCellsInSameTable = isCurrCellInsideNestedTable === isStartCellInsideNestedTable;
208
214
  var $moveAnchor;
215
+ var oldIfStatement = currDOMCell !== startDOMCell;
216
+ var newIfStatement = currDOMCell !== startDOMCell && isBothCellsInSameTable;
217
+ var checkCellsAreDifferent = (0, _platformFeatureFlags.fg)('platform_editor_cell_selection_with_nested_tables') ? newIfStatement : oldIfStatement;
209
218
  if (anchor != null) {
210
219
  // Continuing an existing cross-cell selection
211
220
  $moveAnchor = view.state.doc.resolve(anchor);
212
221
  // Ignored via go/ees005
213
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
214
- } else if (domInCell(view, event.target) !== startDOMCell) {
222
+ } else if (checkCellsAreDifferent) {
215
223
  // Moving out of the initial cell -- start a new cell selection
216
224
  $moveAnchor = cellUnderMouse(view, startEvent);
217
225
  if (!$moveAnchor) {
@@ -275,4 +283,21 @@ function cellUnderMouse(view, event) {
275
283
  return null;
276
284
  }
277
285
  return (0, _cells.cellAround)(view.state.doc.resolve(mousePos.pos));
286
+ }
287
+ function isInsideNestedTable(view, event) {
288
+ var mousePos = view.posAtCoords({
289
+ left: event.clientX,
290
+ top: event.clientY
291
+ });
292
+ if (!mousePos) {
293
+ return false;
294
+ }
295
+ var pos = view.state.doc.resolve(mousePos.pos);
296
+ var table = (0, _utils.findTableClosestToPos)(pos);
297
+ if (!table) {
298
+ return false;
299
+ }
300
+ var parent = view.state.doc.resolve(table.pos).parent;
301
+ var nodeTypes = view.state.schema.nodes;
302
+ return [nodeTypes.tableHeader, nodeTypes.tableCell].includes(parent.type);
278
303
  }
@@ -55,10 +55,7 @@ if (typeof WeakMap !== 'undefined') {
55
55
  return _cache[cachePos++] = value;
56
56
  };
57
57
  }
58
- var Rect = exports.Rect = /*#__PURE__*/(0, _createClass2.default)(
59
- // Ignored via go/ees005
60
- // eslint-disable-next-line @typescript-eslint/max-params
61
- function Rect(left, top, right, bottom) {
58
+ var Rect = exports.Rect = /*#__PURE__*/(0, _createClass2.default)(function Rect(left, top, right, bottom) {
62
59
  (0, _classCallCheck2.default)(this, Rect);
63
60
  this.left = left;
64
61
  this.top = top;
@@ -83,8 +80,6 @@ var tableNewColumnMinWidth = exports.tableNewColumnMinWidth = 140;
83
80
  // be able to do that, positions saved in the map are relative to the
84
81
  // start of the table, rather than the start of the document.
85
82
  var TableMap = exports.TableMap = /*#__PURE__*/function () {
86
- // Ignored via go/ees005
87
- // eslint-disable-next-line @typescript-eslint/max-params
88
83
  function TableMap(width, height, map, problems, mapByColumn, mapByRow) {
89
84
  (0, _classCallCheck2.default)(this, TableMap);
90
85
  // The width of the table
@@ -108,9 +108,6 @@ var cloneColumn = exports.cloneColumn = function cloneColumn(state, originColumn
108
108
  return newTr;
109
109
  };
110
110
  };
111
-
112
- // Ignored via go/ees005
113
- // eslint-disable-next-line @typescript-eslint/max-params
114
111
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
115
112
  var newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
116
113
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
@@ -116,8 +116,6 @@ var cloneRow = exports.cloneRow = function cloneRow(state, originRowIndex, targe
116
116
  * This ensures the row node cell type correctly reflect what they should be.
117
117
  * @returns A copy of the rowNode
118
118
  */
119
- // Ignored via go/ees005
120
- // eslint-disable-next-line @typescript-eslint/max-params
121
119
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
122
120
  var content = [];
123
121
  rowNode.forEach(function (node, offset, index) {
@@ -208,8 +208,6 @@ function clipCells(_ref, newWidth, newHeight) {
208
208
 
209
209
  // Make sure a table has at least the given width and height. Return
210
210
  // true if something was changed.
211
- // Ignored via go/ees005
212
- // eslint-disable-next-line @typescript-eslint/max-params
213
211
  function growTable(tr, map, table, start, width, height, mapFrom) {
214
212
  var schema = tr.doc.type.schema;
215
213
  var types = (0, _tableNodeTypes.tableNodeTypes)(schema);
@@ -271,8 +269,6 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
271
269
  // Make sure the given line (left, top) to (right, top) doesn't cross
272
270
  // any rowspan cells by splitting cells that cross it. Return true if
273
271
  // something changed.
274
- // Ignored via go/ees005
275
- // eslint-disable-next-line @typescript-eslint/max-params
276
272
  function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
277
273
  if (top === 0 || top === map.height) {
278
274
  return false;
@@ -309,8 +305,6 @@ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
309
305
  // Make sure the given line (left, top) to (left, bottom) doesn't
310
306
  // cross any colspan cells by splitting cells that cross it. Return
311
307
  // true if something changed.
312
- // Ignored via go/ees005
313
- // eslint-disable-next-line @typescript-eslint/max-params
314
308
  function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
315
309
  if (left === 0 || left === map.width) {
316
310
  return false;
@@ -338,14 +332,8 @@ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
338
332
  }
339
333
  return found;
340
334
  }
341
-
342
- // Ignored via go/ees005
343
- // eslint-disable-next-line @typescript-eslint/max-params
344
335
  function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabled, headerColumnEnabled) {
345
336
  var schema = state.schema;
346
-
347
- // Ignored via go/ees005
348
- // eslint-disable-next-line @typescript-eslint/max-params
349
337
  var setMarkup = function setMarkup(tr, row, col, headerEnabled) {
350
338
  var cellPos = tableStart + tableMap.positionAt(row, col, table);
351
339
  var cell = tr.doc.nodeAt(cellPos);
@@ -372,8 +360,6 @@ function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabl
372
360
 
373
361
  // Insert the given set of cells (as returned by `pastedCells`) into a
374
362
  // table, at the position pointed at by rect.
375
- // Ignored via go/ees005
376
- // eslint-disable-next-line @typescript-eslint/max-params
377
363
  function insertCells(state, dispatch, tableStart, rect, cells) {
378
364
  var table = state.doc;
379
365
  var newRect = (0, _selectionRect.selectedRect)(state);
@@ -16,8 +16,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  // Helper for iterating through the nodes in a document that changed
17
17
  // compared to the given previous document. Useful for avoiding
18
18
  // duplicate work on each transaction.
19
- // Ignored via go/ees005
20
- // eslint-disable-next-line @typescript-eslint/max-params
21
19
  function changedDescendants(old, cur, offsetStart, f) {
22
20
  var offset = offsetStart;
23
21
  var oldSize = old.childCount;
@@ -67,8 +65,6 @@ function fixTables(state, oldState, reportFixedTable) {
67
65
  // : (EditorState, Node, number, ?Transaction) → ?Transaction
68
66
  // Fix the given table, if necessary. Will append to the transaction
69
67
  // it was given, if non-null, or create a new one if necessary.
70
- // Ignored via go/ees005
71
- // eslint-disable-next-line @typescript-eslint/max-params
72
68
  function fixTable(state, table, tablePos, transaction, reportFixedTable) {
73
69
  var tr = transaction;
74
70
  var map = _tableMap.TableMap.get(table);
@@ -242,9 +242,6 @@ var moveColumn = exports.moveColumn = function moveColumn(state, originColumnInd
242
242
  return newTr;
243
243
  };
244
244
  };
245
-
246
- // Ignored via go/ees005
247
- // eslint-disable-next-line @typescript-eslint/max-params
248
245
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
249
246
  var newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
250
247
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
@@ -268,8 +268,6 @@ var moveRow = exports.moveRow = function moveRow(state, originRowIndex, targetRo
268
268
  * This ensures the row node cell type correctly reflect what they should be.
269
269
  * @returns A copy of the rowNode
270
270
  */
271
- // Ignored via go/ees005
272
- // eslint-disable-next-line @typescript-eslint/max-params
273
271
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
274
272
  var content = [];
275
273
  rowNode.forEach(function (node, offset, index) {
@@ -95,10 +95,7 @@ var convertArrayOfRowsToTableNode = exports.convertArrayOfRowsToTableNode = func
95
95
  var newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
96
96
  return newTable;
97
97
  };
98
- var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOrigin, indexesTarget, directionOverride
99
- // Ignored via go/ees005
100
- // eslint-disable-next-line @typescript-eslint/max-params
101
- ) {
98
+ var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOrigin, indexesTarget, directionOverride) {
102
99
  var direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
103
100
  var rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
104
101
  var positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
@@ -163,27 +160,18 @@ var convertTableNodeToArrayOfRows = exports.convertTableNodeToArrayOfRows = func
163
160
  }
164
161
  return rows;
165
162
  };
166
- var moveTableRow = exports.moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction
167
- // Ignored via go/ees005
168
- // eslint-disable-next-line @typescript-eslint/max-params
169
- ) {
163
+ var moveTableRow = exports.moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction) {
170
164
  var rows = convertTableNodeToArrayOfRows(table.node);
171
165
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
172
166
  return convertArrayOfRowsToTableNode(table.node, rows);
173
167
  };
174
- var moveTableColumn = exports.moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction
175
- // Ignored via go/ees005
176
- // eslint-disable-next-line @typescript-eslint/max-params
177
- ) {
168
+ var moveTableColumn = exports.moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction) {
178
169
  var rows = transpose(convertTableNodeToArrayOfRows(table.node));
179
170
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
180
171
  rows = transpose(rows);
181
172
  return convertArrayOfRowsToTableNode(table.node, rows);
182
173
  };
183
- var isValidReorder = exports.isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type
184
- // Ignored via go/ees005
185
- // eslint-disable-next-line @typescript-eslint/max-params
186
- ) {
174
+ var isValidReorder = exports.isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type) {
187
175
  var direction = originIndex > targetIndex ? -1 : 1;
188
176
  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.");
189
177
  if (direction === 1) {
@@ -4,8 +4,9 @@
4
4
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { Slice } from '@atlaskit/editor-prosemirror/model';
6
6
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
7
8
  import { CellSelection } from '../cell-selection';
8
- import { tableNodeTypes } from '../utils';
9
+ import { findTableClosestToPos, tableNodeTypes } from '../utils';
9
10
  import { cellAround, nextCell } from '../utils/cells';
10
11
  import { inSameTable } from '../utils/tables';
11
12
  import { tableEditingKey } from './plugin-key';
@@ -204,13 +205,20 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
204
205
  }
205
206
  function move(event) {
206
207
  const anchor = tableEditingKey.getState(view.state);
208
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
209
+ const currDOMCell = domInCell(view, event.target);
210
+ const isCurrCellInsideNestedTable = isInsideNestedTable(view, event);
211
+ const isStartCellInsideNestedTable = isInsideNestedTable(view, startEvent);
212
+ const isBothCellsInSameTable = isCurrCellInsideNestedTable === isStartCellInsideNestedTable;
207
213
  let $moveAnchor;
214
+ const oldIfStatement = currDOMCell !== startDOMCell;
215
+ const newIfStatement = currDOMCell !== startDOMCell && isBothCellsInSameTable;
216
+ const checkCellsAreDifferent = fg('platform_editor_cell_selection_with_nested_tables') ? newIfStatement : oldIfStatement;
208
217
  if (anchor != null) {
209
218
  // Continuing an existing cross-cell selection
210
219
  $moveAnchor = view.state.doc.resolve(anchor);
211
220
  // Ignored via go/ees005
212
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
213
- } else if (domInCell(view, event.target) !== startDOMCell) {
221
+ } else if (checkCellsAreDifferent) {
214
222
  // Moving out of the initial cell -- start a new cell selection
215
223
  $moveAnchor = cellUnderMouse(view, startEvent);
216
224
  if (!$moveAnchor) {
@@ -276,4 +284,21 @@ function cellUnderMouse(view, event) {
276
284
  return null;
277
285
  }
278
286
  return cellAround(view.state.doc.resolve(mousePos.pos));
287
+ }
288
+ function isInsideNestedTable(view, event) {
289
+ const mousePos = view.posAtCoords({
290
+ left: event.clientX,
291
+ top: event.clientY
292
+ });
293
+ if (!mousePos) {
294
+ return false;
295
+ }
296
+ const pos = view.state.doc.resolve(mousePos.pos);
297
+ const table = findTableClosestToPos(pos);
298
+ if (!table) {
299
+ return false;
300
+ }
301
+ const parent = view.state.doc.resolve(table.pos).parent;
302
+ const nodeTypes = view.state.schema.nodes;
303
+ return [nodeTypes.tableHeader, nodeTypes.tableCell].includes(parent.type);
279
304
  }
@@ -45,8 +45,6 @@ if (typeof WeakMap !== 'undefined') {
45
45
  };
46
46
  }
47
47
  export class Rect {
48
- // Ignored via go/ees005
49
- // eslint-disable-next-line @typescript-eslint/max-params
50
48
  constructor(left, top, right, bottom) {
51
49
  this.left = left;
52
50
  this.top = top;
@@ -72,8 +70,6 @@ export const tableNewColumnMinWidth = 140;
72
70
  // be able to do that, positions saved in the map are relative to the
73
71
  // start of the table, rather than the start of the document.
74
72
  export class TableMap {
75
- // Ignored via go/ees005
76
- // eslint-disable-next-line @typescript-eslint/max-params
77
73
  constructor(width, height, map, problems, mapByColumn, mapByRow) {
78
74
  // The width of the table
79
75
  // The table's height
@@ -15,10 +15,7 @@ export const cloneColumn = (state, originColumnIndex, targetColumnIndex, targetD
15
15
  tryToFit: false,
16
16
  direction: 0,
17
17
  selectAfterClone: false
18
- }
19
- // Ignored via go/ees005
20
- // eslint-disable-next-line @typescript-eslint/max-params
21
- ) => tr => {
18
+ }) => tr => {
22
19
  var _originalColumnRanges, _targetColumnRanges$i;
23
20
  const table = findTable(tr.selection);
24
21
  if (!table) {
@@ -101,9 +98,6 @@ export const cloneColumn = (state, originColumnIndex, targetColumnIndex, targetD
101
98
  }
102
99
  return newTr;
103
100
  };
104
-
105
- // Ignored via go/ees005
106
- // eslint-disable-next-line @typescript-eslint/max-params
107
101
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
108
102
  const newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
109
103
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
@@ -15,10 +15,7 @@ export const cloneRow = (state, originRowIndex, targetRowIndex, targetDirection,
15
15
  tryToFit: false,
16
16
  direction: 0,
17
17
  selectAfterClone: false
18
- }
19
- // Ignored via go/ees005
20
- // eslint-disable-next-line @typescript-eslint/max-params
21
- ) => tr => {
18
+ }) => tr => {
22
19
  const table = findTable(tr.selection);
23
20
  if (!table) {
24
21
  return tr;
@@ -97,8 +94,6 @@ export const cloneRow = (state, originRowIndex, targetRowIndex, targetDirection,
97
94
  * This ensures the row node cell type correctly reflect what they should be.
98
95
  * @returns A copy of the rowNode
99
96
  */
100
- // Ignored via go/ees005
101
- // eslint-disable-next-line @typescript-eslint/max-params
102
97
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
103
98
  const content = [];
104
99
  rowNode.forEach((node, offset, index) => {
@@ -203,8 +203,6 @@ export function clipCells({
203
203
 
204
204
  // Make sure a table has at least the given width and height. Return
205
205
  // true if something was changed.
206
- // Ignored via go/ees005
207
- // eslint-disable-next-line @typescript-eslint/max-params
208
206
  function growTable(tr, map, table, start, width, height, mapFrom) {
209
207
  const {
210
208
  schema
@@ -268,8 +266,6 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
268
266
  // Make sure the given line (left, top) to (right, top) doesn't cross
269
267
  // any rowspan cells by splitting cells that cross it. Return true if
270
268
  // something changed.
271
- // Ignored via go/ees005
272
- // eslint-disable-next-line @typescript-eslint/max-params
273
269
  function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
274
270
  if (top === 0 || top === map.height) {
275
271
  return false;
@@ -309,8 +305,6 @@ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
309
305
  // Make sure the given line (left, top) to (left, bottom) doesn't
310
306
  // cross any colspan cells by splitting cells that cross it. Return
311
307
  // true if something changed.
312
- // Ignored via go/ees005
313
- // eslint-disable-next-line @typescript-eslint/max-params
314
308
  function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
315
309
  if (left === 0 || left === map.width) {
316
310
  return false;
@@ -338,16 +332,10 @@ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
338
332
  }
339
333
  return found;
340
334
  }
341
-
342
- // Ignored via go/ees005
343
- // eslint-disable-next-line @typescript-eslint/max-params
344
335
  function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabled, headerColumnEnabled) {
345
336
  const {
346
337
  schema
347
338
  } = state;
348
-
349
- // Ignored via go/ees005
350
- // eslint-disable-next-line @typescript-eslint/max-params
351
339
  const setMarkup = (tr, row, col, headerEnabled) => {
352
340
  const cellPos = tableStart + tableMap.positionAt(row, col, table);
353
341
  const cell = tr.doc.nodeAt(cellPos);
@@ -374,8 +362,6 @@ function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabl
374
362
 
375
363
  // Insert the given set of cells (as returned by `pastedCells`) into a
376
364
  // table, at the position pointed at by rect.
377
- // Ignored via go/ees005
378
- // eslint-disable-next-line @typescript-eslint/max-params
379
365
  export function insertCells(state, dispatch, tableStart, rect, cells) {
380
366
  let table = state.doc;
381
367
  const newRect = selectedRect(state);
@@ -5,8 +5,6 @@ import { tableNodeTypes } from './table-node-types';
5
5
  // Helper for iterating through the nodes in a document that changed
6
6
  // compared to the given previous document. Useful for avoiding
7
7
  // duplicate work on each transaction.
8
- // Ignored via go/ees005
9
- // eslint-disable-next-line @typescript-eslint/max-params
10
8
  function changedDescendants(old, cur, offsetStart, f) {
11
9
  let offset = offsetStart;
12
10
  const oldSize = old.childCount;
@@ -56,8 +54,6 @@ export function fixTables(state, oldState, reportFixedTable) {
56
54
  // : (EditorState, Node, number, ?Transaction) → ?Transaction
57
55
  // Fix the given table, if necessary. Will append to the transaction
58
56
  // it was given, if non-null, or create a new one if necessary.
59
- // Ignored via go/ees005
60
- // eslint-disable-next-line @typescript-eslint/max-params
61
57
  export function fixTable(state, table, tablePos, transaction, reportFixedTable) {
62
58
  let tr = transaction;
63
59
  const map = TableMap.get(table);
@@ -140,10 +140,7 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
140
140
  tryToFit: false,
141
141
  direction: 0,
142
142
  selectAfterMove: false
143
- }
144
- // Ignored via go/ees005
145
- // eslint-disable-next-line @typescript-eslint/max-params
146
- ) => tr => {
143
+ }) => tr => {
147
144
  var _originalColumnRanges, _targetColumnRanges$i;
148
145
  const table = findTable(tr.selection);
149
146
  if (!table) {
@@ -235,9 +232,6 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
235
232
  }
236
233
  return newTr;
237
234
  };
238
-
239
- // Ignored via go/ees005
240
- // eslint-disable-next-line @typescript-eslint/max-params
241
235
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
242
236
  const newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
243
237
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
@@ -155,10 +155,7 @@ export const moveRow = (state, originRowIndex, targetRowIndex, options = {
155
155
  tryToFit: false,
156
156
  direction: 0,
157
157
  selectAfterMove: false
158
- }
159
- // Ignored via go/ees005
160
- // eslint-disable-next-line @typescript-eslint/max-params
161
- ) => tr => {
158
+ }) => tr => {
162
159
  const table = findTable(tr.selection);
163
160
  if (!table) {
164
161
  return tr;
@@ -251,8 +248,6 @@ export const moveRow = (state, originRowIndex, targetRowIndex, options = {
251
248
  * This ensures the row node cell type correctly reflect what they should be.
252
249
  * @returns A copy of the rowNode
253
250
  */
254
- // Ignored via go/ees005
255
- // eslint-disable-next-line @typescript-eslint/max-params
256
251
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
257
252
  const content = [];
258
253
  rowNode.forEach((node, offset, index) => {
@@ -88,10 +88,7 @@ export const convertArrayOfRowsToTableNode = (tableNode, arrayOfNodes) => {
88
88
  const newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
89
89
  return newTable;
90
90
  };
91
- const moveRowInArrayOfRows = (arrayOfNodes, indexesOrigin, indexesTarget, directionOverride
92
- // Ignored via go/ees005
93
- // eslint-disable-next-line @typescript-eslint/max-params
94
- ) => {
91
+ const moveRowInArrayOfRows = (arrayOfNodes, indexesOrigin, indexesTarget, directionOverride) => {
95
92
  const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
96
93
  const rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
97
94
  const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
@@ -156,27 +153,18 @@ export const convertTableNodeToArrayOfRows = tableNode => {
156
153
  }
157
154
  return rows;
158
155
  };
159
- export const moveTableRow = (table, indexesOrigin, indexesTarget, direction
160
- // Ignored via go/ees005
161
- // eslint-disable-next-line @typescript-eslint/max-params
162
- ) => {
156
+ export const moveTableRow = (table, indexesOrigin, indexesTarget, direction) => {
163
157
  let rows = convertTableNodeToArrayOfRows(table.node);
164
158
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
165
159
  return convertArrayOfRowsToTableNode(table.node, rows);
166
160
  };
167
- export const moveTableColumn = (table, indexesOrigin, indexesTarget, direction
168
- // Ignored via go/ees005
169
- // eslint-disable-next-line @typescript-eslint/max-params
170
- ) => {
161
+ export const moveTableColumn = (table, indexesOrigin, indexesTarget, direction) => {
171
162
  let rows = transpose(convertTableNodeToArrayOfRows(table.node));
172
163
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
173
164
  rows = transpose(rows);
174
165
  return convertArrayOfRowsToTableNode(table.node, rows);
175
166
  };
176
- export const isValidReorder = (originIndex, targetIndex, targets, type
177
- // Ignored via go/ees005
178
- // eslint-disable-next-line @typescript-eslint/max-params
179
- ) => {
167
+ export const isValidReorder = (originIndex, targetIndex, targets, type) => {
180
168
  const direction = originIndex > targetIndex ? -1 : 1;
181
169
  const errorMessage = `Target position is invalid, you can't move the ${type} ${originIndex} to ${targetIndex}, the target can't be split. You could use tryToFit option.`;
182
170
  if (direction === 1) {
@@ -4,8 +4,9 @@
4
4
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { Slice } from '@atlaskit/editor-prosemirror/model';
6
6
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
7
8
  import { CellSelection } from '../cell-selection';
8
- import { tableNodeTypes } from '../utils';
9
+ import { findTableClosestToPos, tableNodeTypes } from '../utils';
9
10
  import { cellAround, nextCell } from '../utils/cells';
10
11
  import { inSameTable } from '../utils/tables';
11
12
  import { tableEditingKey } from './plugin-key';
@@ -197,13 +198,20 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
197
198
  }
198
199
  function move(event) {
199
200
  var anchor = tableEditingKey.getState(view.state);
201
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
202
+ var currDOMCell = domInCell(view, event.target);
203
+ var isCurrCellInsideNestedTable = isInsideNestedTable(view, event);
204
+ var isStartCellInsideNestedTable = isInsideNestedTable(view, startEvent);
205
+ var isBothCellsInSameTable = isCurrCellInsideNestedTable === isStartCellInsideNestedTable;
200
206
  var $moveAnchor;
207
+ var oldIfStatement = currDOMCell !== startDOMCell;
208
+ var newIfStatement = currDOMCell !== startDOMCell && isBothCellsInSameTable;
209
+ var checkCellsAreDifferent = fg('platform_editor_cell_selection_with_nested_tables') ? newIfStatement : oldIfStatement;
201
210
  if (anchor != null) {
202
211
  // Continuing an existing cross-cell selection
203
212
  $moveAnchor = view.state.doc.resolve(anchor);
204
213
  // Ignored via go/ees005
205
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
206
- } else if (domInCell(view, event.target) !== startDOMCell) {
214
+ } else if (checkCellsAreDifferent) {
207
215
  // Moving out of the initial cell -- start a new cell selection
208
216
  $moveAnchor = cellUnderMouse(view, startEvent);
209
217
  if (!$moveAnchor) {
@@ -267,4 +275,21 @@ function cellUnderMouse(view, event) {
267
275
  return null;
268
276
  }
269
277
  return cellAround(view.state.doc.resolve(mousePos.pos));
278
+ }
279
+ function isInsideNestedTable(view, event) {
280
+ var mousePos = view.posAtCoords({
281
+ left: event.clientX,
282
+ top: event.clientY
283
+ });
284
+ if (!mousePos) {
285
+ return false;
286
+ }
287
+ var pos = view.state.doc.resolve(mousePos.pos);
288
+ var table = findTableClosestToPos(pos);
289
+ if (!table) {
290
+ return false;
291
+ }
292
+ var parent = view.state.doc.resolve(table.pos).parent;
293
+ var nodeTypes = view.state.schema.nodes;
294
+ return [nodeTypes.tableHeader, nodeTypes.tableCell].includes(parent.type);
270
295
  }
@@ -48,10 +48,7 @@ if (typeof WeakMap !== 'undefined') {
48
48
  return _cache[cachePos++] = value;
49
49
  };
50
50
  }
51
- export var Rect = /*#__PURE__*/_createClass(
52
- // Ignored via go/ees005
53
- // eslint-disable-next-line @typescript-eslint/max-params
54
- function Rect(left, top, right, bottom) {
51
+ export var Rect = /*#__PURE__*/_createClass(function Rect(left, top, right, bottom) {
55
52
  _classCallCheck(this, Rect);
56
53
  this.left = left;
57
54
  this.top = top;
@@ -76,8 +73,6 @@ export var tableNewColumnMinWidth = 140;
76
73
  // be able to do that, positions saved in the map are relative to the
77
74
  // start of the table, rather than the start of the document.
78
75
  export var TableMap = /*#__PURE__*/function () {
79
- // Ignored via go/ees005
80
- // eslint-disable-next-line @typescript-eslint/max-params
81
76
  function TableMap(width, height, map, problems, mapByColumn, mapByRow) {
82
77
  _classCallCheck(this, TableMap);
83
78
  // The width of the table
@@ -101,9 +101,6 @@ export var cloneColumn = function cloneColumn(state, originColumnIndex, targetCo
101
101
  return newTr;
102
102
  };
103
103
  };
104
-
105
- // Ignored via go/ees005
106
- // eslint-disable-next-line @typescript-eslint/max-params
107
104
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
108
105
  var newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
109
106
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
@@ -109,8 +109,6 @@ export var cloneRow = function cloneRow(state, originRowIndex, targetRowIndex, t
109
109
  * This ensures the row node cell type correctly reflect what they should be.
110
110
  * @returns A copy of the rowNode
111
111
  */
112
- // Ignored via go/ees005
113
- // eslint-disable-next-line @typescript-eslint/max-params
114
112
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
115
113
  var content = [];
116
114
  rowNode.forEach(function (node, offset, index) {
@@ -201,8 +201,6 @@ export function clipCells(_ref, newWidth, newHeight) {
201
201
 
202
202
  // Make sure a table has at least the given width and height. Return
203
203
  // true if something was changed.
204
- // Ignored via go/ees005
205
- // eslint-disable-next-line @typescript-eslint/max-params
206
204
  function growTable(tr, map, table, start, width, height, mapFrom) {
207
205
  var schema = tr.doc.type.schema;
208
206
  var types = tableNodeTypes(schema);
@@ -264,8 +262,6 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
264
262
  // Make sure the given line (left, top) to (right, top) doesn't cross
265
263
  // any rowspan cells by splitting cells that cross it. Return true if
266
264
  // something changed.
267
- // Ignored via go/ees005
268
- // eslint-disable-next-line @typescript-eslint/max-params
269
265
  function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
270
266
  if (top === 0 || top === map.height) {
271
267
  return false;
@@ -302,8 +298,6 @@ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
302
298
  // Make sure the given line (left, top) to (left, bottom) doesn't
303
299
  // cross any colspan cells by splitting cells that cross it. Return
304
300
  // true if something changed.
305
- // Ignored via go/ees005
306
- // eslint-disable-next-line @typescript-eslint/max-params
307
301
  function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
308
302
  if (left === 0 || left === map.width) {
309
303
  return false;
@@ -331,14 +325,8 @@ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
331
325
  }
332
326
  return found;
333
327
  }
334
-
335
- // Ignored via go/ees005
336
- // eslint-disable-next-line @typescript-eslint/max-params
337
328
  function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabled, headerColumnEnabled) {
338
329
  var schema = state.schema;
339
-
340
- // Ignored via go/ees005
341
- // eslint-disable-next-line @typescript-eslint/max-params
342
330
  var setMarkup = function setMarkup(tr, row, col, headerEnabled) {
343
331
  var cellPos = tableStart + tableMap.positionAt(row, col, table);
344
332
  var cell = tr.doc.nodeAt(cellPos);
@@ -365,8 +353,6 @@ function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabl
365
353
 
366
354
  // Insert the given set of cells (as returned by `pastedCells`) into a
367
355
  // table, at the position pointed at by rect.
368
- // Ignored via go/ees005
369
- // eslint-disable-next-line @typescript-eslint/max-params
370
356
  export function insertCells(state, dispatch, tableStart, rect, cells) {
371
357
  var table = state.doc;
372
358
  var newRect = selectedRect(state);
@@ -8,8 +8,6 @@ import { tableNodeTypes } from './table-node-types';
8
8
  // Helper for iterating through the nodes in a document that changed
9
9
  // compared to the given previous document. Useful for avoiding
10
10
  // duplicate work on each transaction.
11
- // Ignored via go/ees005
12
- // eslint-disable-next-line @typescript-eslint/max-params
13
11
  function changedDescendants(old, cur, offsetStart, f) {
14
12
  var offset = offsetStart;
15
13
  var oldSize = old.childCount;
@@ -59,8 +57,6 @@ export function fixTables(state, oldState, reportFixedTable) {
59
57
  // : (EditorState, Node, number, ?Transaction) → ?Transaction
60
58
  // Fix the given table, if necessary. Will append to the transaction
61
59
  // it was given, if non-null, or create a new one if necessary.
62
- // Ignored via go/ees005
63
- // eslint-disable-next-line @typescript-eslint/max-params
64
60
  export function fixTable(state, table, tablePos, transaction, reportFixedTable) {
65
61
  var tr = transaction;
66
62
  var map = TableMap.get(table);
@@ -235,9 +235,6 @@ export var moveColumn = function moveColumn(state, originColumnIndex, targetColu
235
235
  return newTr;
236
236
  };
237
237
  };
238
-
239
- // Ignored via go/ees005
240
- // eslint-disable-next-line @typescript-eslint/max-params
241
238
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
242
239
  var newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
243
240
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
@@ -262,8 +262,6 @@ export var moveRow = function moveRow(state, originRowIndex, targetRowIndex) {
262
262
  * This ensures the row node cell type correctly reflect what they should be.
263
263
  * @returns A copy of the rowNode
264
264
  */
265
- // Ignored via go/ees005
266
- // eslint-disable-next-line @typescript-eslint/max-params
267
265
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
268
266
  var content = [];
269
267
  rowNode.forEach(function (node, offset, index) {
@@ -90,10 +90,7 @@ export var convertArrayOfRowsToTableNode = function convertArrayOfRowsToTableNod
90
90
  var newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
91
91
  return newTable;
92
92
  };
93
- var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOrigin, indexesTarget, directionOverride
94
- // Ignored via go/ees005
95
- // eslint-disable-next-line @typescript-eslint/max-params
96
- ) {
93
+ var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOrigin, indexesTarget, directionOverride) {
97
94
  var direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
98
95
  var rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
99
96
  var positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
@@ -158,27 +155,18 @@ export var convertTableNodeToArrayOfRows = function convertTableNodeToArrayOfRow
158
155
  }
159
156
  return rows;
160
157
  };
161
- export var moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction
162
- // Ignored via go/ees005
163
- // eslint-disable-next-line @typescript-eslint/max-params
164
- ) {
158
+ export var moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction) {
165
159
  var rows = convertTableNodeToArrayOfRows(table.node);
166
160
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
167
161
  return convertArrayOfRowsToTableNode(table.node, rows);
168
162
  };
169
- export var moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction
170
- // Ignored via go/ees005
171
- // eslint-disable-next-line @typescript-eslint/max-params
172
- ) {
163
+ export var moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction) {
173
164
  var rows = transpose(convertTableNodeToArrayOfRows(table.node));
174
165
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
175
166
  rows = transpose(rows);
176
167
  return convertArrayOfRowsToTableNode(table.node, rows);
177
168
  };
178
- export var isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type
179
- // Ignored via go/ees005
180
- // eslint-disable-next-line @typescript-eslint/max-params
181
- ) {
169
+ export var isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type) {
182
170
  var direction = originIndex > targetIndex ? -1 : 1;
183
171
  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.");
184
172
  if (direction === 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "A package that contains common classes and utility functions for editor tables",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@atlaskit/editor-prosemirror": "6.2.1",
31
- "@atlaskit/platform-feature-flags": "^0.3.0",
31
+ "@atlaskit/platform-feature-flags": "^1.0.0",
32
32
  "@babel/runtime": "^7.0.0"
33
33
  },
34
34
  "techstack": {
@@ -51,6 +51,9 @@
51
51
  "platform-feature-flags": {
52
52
  "platform_editor_table_fix_move_column": {
53
53
  "type": "boolean"
54
+ },
55
+ "platform_editor_cell_selection_with_nested_tables": {
56
+ "type": "boolean"
54
57
  }
55
58
  },
56
59
  "af:exports": {