@atlaskit/editor-plugin-table 5.5.3 → 5.5.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/plugins/table/commands/index.js +12 -0
  3. package/dist/cjs/plugins/table/commands/misc.js +61 -1
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +2 -3
  5. package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +0 -3
  6. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +8 -2
  7. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +9 -2
  8. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +11 -0
  9. package/dist/cjs/plugins/table/utils/index.js +6 -0
  10. package/dist/cjs/plugins/table/utils/merged-cells.js +75 -1
  11. package/dist/es2019/plugins/table/commands/index.js +1 -1
  12. package/dist/es2019/plugins/table/commands/misc.js +46 -1
  13. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -4
  14. package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +0 -3
  15. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -3
  16. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +9 -2
  17. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +16 -1
  18. package/dist/es2019/plugins/table/utils/index.js +1 -1
  19. package/dist/es2019/plugins/table/utils/merged-cells.js +63 -1
  20. package/dist/esm/plugins/table/commands/index.js +1 -1
  21. package/dist/esm/plugins/table/commands/misc.js +61 -1
  22. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -4
  23. package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +0 -3
  24. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -3
  25. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +9 -2
  26. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +12 -1
  27. package/dist/esm/plugins/table/utils/index.js +1 -1
  28. package/dist/esm/plugins/table/utils/merged-cells.js +73 -0
  29. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  30. package/dist/types/plugins/table/commands/misc.d.ts +2 -0
  31. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  32. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  33. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  34. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  35. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  36. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +2 -0
  37. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  38. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  39. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  40. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  41. package/package.json +1 -1
  42. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +3 -3
  43. package/src/__tests__/unit/ui/RowDragControls.tsx +2 -0
  44. package/src/__tests__/unit/utils/merged-cells.ts +156 -0
  45. package/src/plugins/table/commands/index.ts +2 -0
  46. package/src/plugins/table/commands/misc.ts +78 -0
  47. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +11 -9
  48. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +0 -3
  49. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +22 -2
  50. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +21 -2
  51. package/src/plugins/table/ui/TableFloatingControls/index.tsx +12 -1
  52. package/src/plugins/table/utils/index.ts +5 -1
  53. package/src/plugins/table/utils/merged-cells.ts +82 -0
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -5,7 +6,7 @@ import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaski
5
6
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
6
7
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
7
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
8
- import { findCellClosestToPos, findTable, getCellsInColumn, getCellsInRow, getSelectionRect, isSelectionType, isTableSelected, removeTable, selectColumn as selectColumnTransform, selectionCell, selectRow as selectRowTransform, setCellAttrs } from '@atlaskit/editor-tables/utils';
9
+ import { findCellClosestToPos, findTable, getCellsInColumn, getCellsInRow, getSelectionRect, isSelectionType, isTableSelected, removeTable, selectColumns as selectColumnsTransform, selectColumn as selectColumnTransform, selectionCell, selectRows as selectRowsTransform, selectRow as selectRowTransform, setCellAttrs } from '@atlaskit/editor-tables/utils';
9
10
  import { getDecorations } from '../pm-plugins/decorations/plugin';
10
11
  import { buildColumnResizingDecorations, clearColumnResizingDecorations } from '../pm-plugins/decorations/utils';
11
12
  import { createCommand, getPluginState } from '../pm-plugins/plugin-factory';
@@ -339,6 +340,37 @@ export var selectColumn = function selectColumn(column, expand) {
339
340
  return selectColumnTransform(column, expand)(tr).setMeta('addToHistory', false);
340
341
  });
341
342
  };
343
+ export var selectColumns = function selectColumns(columnIndexes) {
344
+ return createCommand(function (state) {
345
+ if (!columnIndexes) {
346
+ return false;
347
+ }
348
+ var cells = columnIndexes.map(function (column) {
349
+ return getCellsInColumn(column)(state.tr.selection);
350
+ }).flat();
351
+ if (!cells || !cells.length || cells.some(function (cell) {
352
+ return cell && typeof cell.pos !== 'number';
353
+ })) {
354
+ return false;
355
+ }
356
+ var decorations = createColumnSelectedDecoration(selectColumnsTransform(columnIndexes)(state.tr));
357
+ var decorationSet = updatePluginStateDecorations(state, decorations, TableDecorations.COLUMN_SELECTED);
358
+ var cellsInFirstColumn = getCellsInColumn(Math.min.apply(Math, _toConsumableArray(columnIndexes)))(state.tr.selection);
359
+ if (!cellsInFirstColumn || cellsInFirstColumn.length === 0) {
360
+ return false;
361
+ }
362
+ var targetCellPosition = cellsInFirstColumn[0].pos;
363
+ return {
364
+ type: 'SELECT_COLUMN',
365
+ data: {
366
+ targetCellPosition: targetCellPosition,
367
+ decorationSet: decorationSet
368
+ }
369
+ };
370
+ }, function (tr) {
371
+ return selectColumnsTransform(columnIndexes)(tr).setMeta('addToHistory', false);
372
+ });
373
+ };
342
374
  export var selectRow = function selectRow(row, expand) {
343
375
  return createCommand(function (state) {
344
376
  var targetCellPosition;
@@ -356,6 +388,34 @@ export var selectRow = function selectRow(row, expand) {
356
388
  return selectRowTransform(row, expand)(tr).setMeta('addToHistory', false);
357
389
  });
358
390
  };
391
+ export var selectRows = function selectRows(rowIndexes) {
392
+ return createCommand(function (state) {
393
+ if (rowIndexes.length === 0) {
394
+ return false;
395
+ }
396
+ var cells = rowIndexes.map(function (row) {
397
+ return getCellsInRow(row)(state.tr.selection);
398
+ }).flat();
399
+ if (!cells || !cells.length || cells.some(function (cell) {
400
+ return cell && typeof cell.pos !== 'number';
401
+ })) {
402
+ return false;
403
+ }
404
+ var cellsInFirstRow = getCellsInRow(Math.min.apply(Math, _toConsumableArray(rowIndexes)))(state.tr.selection);
405
+ if (!cellsInFirstRow || cellsInFirstRow.length === 0) {
406
+ return false;
407
+ }
408
+ var targetCellPosition = cellsInFirstRow[0].pos;
409
+ return {
410
+ type: 'SET_TARGET_CELL_POSITION',
411
+ data: {
412
+ targetCellPosition: targetCellPosition
413
+ }
414
+ };
415
+ }, function (tr) {
416
+ return selectRowsTransform(rowIndexes)(tr).setMeta('addToHistory', false);
417
+ });
418
+ };
359
419
  export var showInsertColumnButton = function showInsertColumnButton(columnIndex) {
360
420
  return createCommand(function (_) {
361
421
  return columnIndex > -1 ? {
@@ -7,8 +7,7 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
8
8
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
9
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
10
- import { findNearestCellIndexToPoint } from '../../utils';
11
- import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
10
+ import { findNearestCellIndexToPoint, hasMergedCellsInBetween } from '../../utils';
12
11
  import { getPluginState as getTablePluginState } from '../plugin-factory';
13
12
  import { pluginKey as tablePluginKey } from '../plugin-key';
14
13
  import { DragAndDropActionType } from './actions';
@@ -175,8 +174,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
175
174
  }
176
175
 
177
176
  // If the drop target index contains merged cells then we should not allow the drop to occur.
178
- var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
179
- if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
177
+ if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
180
178
  clearDropTarget(tr)(editorView.state, editorView.dispatch);
181
179
  return;
182
180
  }
@@ -184,6 +182,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
184
182
  sourceIndex = _sourceIndexes[0];
185
183
  requestAnimationFrame(function () {
186
184
  moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
185
+ editorView.focus();
187
186
  });
188
187
  }
189
188
  })
@@ -95,9 +95,6 @@ export var FloatingInsertButton = /*#__PURE__*/function (_React$Component) {
95
95
  position: pos,
96
96
  docSize: editorView.state.doc.nodeSize,
97
97
  error: error === null || error === void 0 ? void 0 : error.toString()
98
- },
99
- nonPrivacySafeAttributes: {
100
- errorStack: error.stack || undefined
101
98
  }
102
99
  };
103
100
  dispatchAnalyticsEvent(payload);
@@ -4,7 +4,7 @@ import React, { useCallback, useMemo } from 'react';
4
4
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
5
  import { CellSelection } from '@atlaskit/editor-tables';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
7
- import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
7
+ import { clearHoverSelection, hoverCell, hoverColumns, selectColumn, selectColumns } from '../../../commands';
8
8
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
9
9
  import { TableCssClassName as ClassName } from '../../../types';
10
10
  import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
@@ -47,8 +47,14 @@ export var ColumnControls = function ColumnControls(_ref) {
47
47
  var handleClick = useCallback(function (event) {
48
48
  var state = editorView.state,
49
49
  dispatch = editorView.dispatch;
50
- selectColumn(colIndex, event.shiftKey)(state, dispatch);
51
- }, [colIndex, editorView]);
50
+ var isClickOutsideSelectedCols = selectedColIndexes.length >= 1 && !selectedColIndexes.includes(colIndex);
51
+ if (!selectedColIndexes || selectedColIndexes.length === 0 || isClickOutsideSelectedCols) {
52
+ selectColumn(colIndex, event.shiftKey)(state, dispatch);
53
+ }
54
+ if (selectedColIndexes.length > 1 && selectedColIndexes.includes(colIndex) && !event.shiftKey) {
55
+ selectColumns(selectedColIndexes)(state, dispatch);
56
+ }
57
+ }, [colIndex, selectedColIndexes, editorView]);
52
58
  var handleMouseOver = useCallback(function () {
53
59
  var state = editorView.state,
54
60
  dispatch = editorView.dispatch;
@@ -38,6 +38,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
38
38
  canDrag = _ref.canDrag,
39
39
  hoverRows = _ref.hoverRows,
40
40
  selectRow = _ref.selectRow,
41
+ selectRows = _ref.selectRows,
41
42
  updateCellHoverLocation = _ref.updateCellHoverLocation;
42
43
  var _useState = useState(false),
43
44
  _useState2 = _slicedToArray(_useState, 2),
@@ -103,8 +104,14 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
103
104
  hoverRows([rowIndex]);
104
105
  }, [hoverRows, rowIndex]);
105
106
  var handleClick = useCallback(function (e) {
106
- selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
107
- }, [rowIndex, selectRow]);
107
+ var isClickOutsideSelectedRows = selectedRowIndexes.length >= 1 && !selectedRowIndexes.includes(rowIndex);
108
+ if (!selectedRowIndexes || selectedRowIndexes.length === 0 || isClickOutsideSelectedRows) {
109
+ selectRow(rowIndex, e.shiftKey);
110
+ }
111
+ if (selectedRowIndexes.length > 1 && selectedRowIndexes.includes(rowIndex) && !e.shiftKey) {
112
+ selectRows(selectedRowIndexes);
113
+ }
114
+ }, [rowIndex, selectRow, selectRows, selectedRowIndexes]);
108
115
  var generateHandleByType = function generateHandleByType(type) {
109
116
  if (!hoveredCell) {
110
117
  return null;
@@ -12,7 +12,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
12
12
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
13
  import React, { Component } from 'react';
14
14
  import { browser } from '@atlaskit/editor-common/utils';
15
- import { hoverCell, hoverRows, selectRow } from '../../commands';
15
+ import { hoverCell, hoverRows, selectRow, selectRows } from '../../commands';
16
16
  import { TableCssClassName as ClassName } from '../../types';
17
17
  import { isSelectionUpdated } from '../../utils';
18
18
  import { CornerControls, DragCornerControls } from './CornerControls';
@@ -35,6 +35,16 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
35
35
  }
36
36
  selectRow(row, expand)(state, dispatch);
37
37
  });
38
+ _defineProperty(_assertThisInitialized(_this), "selectRows", function (rowIndexes) {
39
+ var editorView = _this.props.editorView;
40
+ var state = editorView.state,
41
+ dispatch = editorView.dispatch;
42
+ // fix for issue ED-4665
43
+ if (browser.ie_version === 11) {
44
+ editorView.dom.blur();
45
+ }
46
+ selectRows(rowIndexes)(state, dispatch);
47
+ });
38
48
  _defineProperty(_assertThisInitialized(_this), "hoverRows", function (rows, danger) {
39
49
  var _this$props$editorVie = _this.props.editorView,
40
50
  state = _this$props$editorVie.state,
@@ -198,6 +208,7 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
198
208
  tableWidth: this.state.tableWrapperWidth,
199
209
  hoverRows: this.hoverRows,
200
210
  selectRow: this.selectRow,
211
+ selectRows: this.selectRows,
201
212
  updateCellHoverLocation: this.updateCellHoverLocation,
202
213
  canDrag: canDrag
203
214
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
@@ -8,4 +8,4 @@ export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getR
8
8
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
9
9
  export { getMergedCellsPositions } from './table';
10
10
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
11
- export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
11
+ export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween } from './merged-cells';
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import { findTable, TableMap } from '@atlaskit/editor-tables';
2
3
  var hasMergedCells = function hasMergedCells(indexes, normalizeRect) {
3
4
  return function (selection) {
@@ -57,4 +58,76 @@ export var hasMergedCellsInRow = function hasMergedCellsInRow(rowIndexes) {
57
58
  bottom: y === index ? y + 1 : y
58
59
  };
59
60
  });
61
+ };
62
+ var getRect = function getRect(index, type, map) {
63
+ if (type === 'column') {
64
+ var x = Math.max(Math.min(index, map.width - 1), 0); // clamped index
65
+ return {
66
+ left: x,
67
+ right: x === index ? x + 1 : x,
68
+ top: 0,
69
+ bottom: map.height
70
+ };
71
+ } else {
72
+ var y = Math.max(Math.min(index, map.height - 1), 0); // clamped index
73
+ return {
74
+ left: 0,
75
+ right: map.width,
76
+ top: y,
77
+ bottom: y === index ? y + 1 : y
78
+ };
79
+ }
80
+ };
81
+ export var hasMergedCellsInBetween = function hasMergedCellsInBetween(indexes, type) {
82
+ return function (selection) {
83
+ var table = findTable(selection);
84
+ if (!table) {
85
+ return false;
86
+ }
87
+ var map = TableMap.get(table.node);
88
+ var cellPositions = new Set();
89
+ var mergedCells = new Set();
90
+ map.map.forEach(function (value) {
91
+ if (cellPositions.has(value)) {
92
+ mergedCells.add(value);
93
+ } else {
94
+ cellPositions.add(value);
95
+ }
96
+ });
97
+ if (!mergedCells.size) {
98
+ return false;
99
+ }
100
+ var getMergedCellsInRect = function getMergedCellsInRect(index, type) {
101
+ var rect = getRect(index, type, map);
102
+ var isValidRectangle = rect.left < rect.right && rect.top < rect.bottom;
103
+ if (!isValidRectangle) {
104
+ return [];
105
+ }
106
+ var cells = map.cellsInRect(rect);
107
+ var allCellsInRect = [];
108
+ if (type === 'column') {
109
+ allCellsInRect = map.map.filter(function (_, key) {
110
+ return key % map.width === index;
111
+ });
112
+ } else {
113
+ allCellsInRect = map.map.filter(function (_, key) {
114
+ return Math.floor(key / map.width) === index;
115
+ });
116
+ }
117
+ var mergedCell = allCellsInRect.filter(function (nodePos) {
118
+ return !cells.includes(nodePos) // cell exists in Rect but not show in the map.cellsInRect list => merged cell
119
+ ? true : mergedCells.has(nodePos); // cell includes in mergedCells => merged cell
120
+ });
121
+
122
+ return _toConsumableArray(new Set(mergedCell));
123
+ };
124
+ var mergedCellsInRectArr = indexes.map(function (index) {
125
+ return getMergedCellsInRect(index, type);
126
+ });
127
+
128
+ // Currently only support 2 indexes, but we can extend this to support more indexes in the future.
129
+ return mergedCellsInRectArr[0].some(function (cell) {
130
+ return mergedCellsInRectArr[1].includes(cell);
131
+ });
132
+ };
60
133
  };
@@ -2,7 +2,7 @@ export { hoverColumns, hoverRows, hoverTable, hoverCell, hoverMergedCells, clear
2
2
  export { insertColumn, insertRow, createTable } from './insert';
3
3
  export { getNextLayout, toggleContextualMenu, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout, } from './toggle';
4
4
  export { clearMultipleCells } from './clear';
5
- export { autoSizeTable, convertFirstRowToHeader, deleteTable, hideInsertColumnOrRowButton, moveCursorBackward, selectColumn, selectRow, setCellAttr, setEditorFocus, setMultipleCellAttrs, setTableRef, showInsertColumnButton, showInsertRowButton, transformSliceToAddTableHeaders, triggerUnlessTableHeader, addBoldInEmptyHeaderCells, addResizeHandleDecorations, } from './misc';
5
+ export { autoSizeTable, convertFirstRowToHeader, deleteTable, hideInsertColumnOrRowButton, moveCursorBackward, selectColumn, selectColumns, selectRow, selectRows, setCellAttr, setEditorFocus, setMultipleCellAttrs, setTableRef, showInsertColumnButton, showInsertRowButton, transformSliceToAddTableHeaders, triggerUnlessTableHeader, addBoldInEmptyHeaderCells, addResizeHandleDecorations, } from './misc';
6
6
  export { sortByColumn } from './sort';
7
7
  export { goToNextCell } from './go-to-next-cell';
8
8
  export { removeDescendantNodes } from './referentiality';
@@ -20,7 +20,9 @@ export declare const convertFirstRowToHeader: (schema: Schema) => (tr: Transacti
20
20
  export declare const moveCursorBackward: Command;
21
21
  export declare const setMultipleCellAttrs: (attrs: Object, targetCellPosition?: number) => Command;
22
22
  export declare const selectColumn: (column: number, expand?: boolean) => Command;
23
+ export declare const selectColumns: (columnIndexes: number[]) => Command;
23
24
  export declare const selectRow: (row: number, expand?: boolean) => Command;
25
+ export declare const selectRows: (rowIndexes: number[]) => Command;
24
26
  export declare const showInsertColumnButton: (columnIndex: number) => Command;
25
27
  export declare const showInsertRowButton: (rowIndex: number) => Command;
26
28
  export declare const hideInsertColumnOrRowButton: () => Command;
@@ -16,6 +16,7 @@ type DragControlsProps = {
16
16
  canDrag?: boolean;
17
17
  hoverRows: (rows: number[], danger?: boolean) => void;
18
18
  selectRow: (row: number, expand: boolean) => void;
19
+ selectRows: (rowIndexes: number[]) => void;
19
20
  updateCellHoverLocation: (rowIndex: number) => void;
20
21
  };
21
22
  export declare const DragControls: React.FC<import("react-intl-next").WithIntlProps<DragControlsProps & WrappedComponentProps<"intl">>> & {
@@ -42,6 +42,7 @@ export default class TableFloatingControls extends Component<Props, State> {
42
42
  componentWillUnmount(): void;
43
43
  render(): JSX.Element | null;
44
44
  private selectRow;
45
+ private selectRows;
45
46
  private hoverRows;
46
47
  private updateCellHoverLocation;
47
48
  }
@@ -9,4 +9,4 @@ export type { RowParams } from './row-controls';
9
9
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
10
10
  export { getMergedCellsPositions } from './table';
11
11
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
12
- export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
12
+ export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, } from './merged-cells';
@@ -1,3 +1,6 @@
1
1
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ type MergeType = 'row' | 'column';
2
3
  export declare const hasMergedCellsInColumn: (columnIndexes: number | number[]) => (selection: Selection) => boolean;
3
4
  export declare const hasMergedCellsInRow: (rowIndexes: number | number[]) => (selection: Selection) => boolean;
5
+ export declare const hasMergedCellsInBetween: (indexes: number[], type: MergeType) => (selection: Selection) => boolean;
6
+ export {};
@@ -2,7 +2,7 @@ export { hoverColumns, hoverRows, hoverTable, hoverCell, hoverMergedCells, clear
2
2
  export { insertColumn, insertRow, createTable } from './insert';
3
3
  export { getNextLayout, toggleContextualMenu, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout, } from './toggle';
4
4
  export { clearMultipleCells } from './clear';
5
- export { autoSizeTable, convertFirstRowToHeader, deleteTable, hideInsertColumnOrRowButton, moveCursorBackward, selectColumn, selectRow, setCellAttr, setEditorFocus, setMultipleCellAttrs, setTableRef, showInsertColumnButton, showInsertRowButton, transformSliceToAddTableHeaders, triggerUnlessTableHeader, addBoldInEmptyHeaderCells, addResizeHandleDecorations, } from './misc';
5
+ export { autoSizeTable, convertFirstRowToHeader, deleteTable, hideInsertColumnOrRowButton, moveCursorBackward, selectColumn, selectColumns, selectRow, selectRows, setCellAttr, setEditorFocus, setMultipleCellAttrs, setTableRef, showInsertColumnButton, showInsertRowButton, transformSliceToAddTableHeaders, triggerUnlessTableHeader, addBoldInEmptyHeaderCells, addResizeHandleDecorations, } from './misc';
6
6
  export { sortByColumn } from './sort';
7
7
  export { goToNextCell } from './go-to-next-cell';
8
8
  export { removeDescendantNodes } from './referentiality';
@@ -20,7 +20,9 @@ export declare const convertFirstRowToHeader: (schema: Schema) => (tr: Transacti
20
20
  export declare const moveCursorBackward: Command;
21
21
  export declare const setMultipleCellAttrs: (attrs: Object, targetCellPosition?: number) => Command;
22
22
  export declare const selectColumn: (column: number, expand?: boolean) => Command;
23
+ export declare const selectColumns: (columnIndexes: number[]) => Command;
23
24
  export declare const selectRow: (row: number, expand?: boolean) => Command;
25
+ export declare const selectRows: (rowIndexes: number[]) => Command;
24
26
  export declare const showInsertColumnButton: (columnIndex: number) => Command;
25
27
  export declare const showInsertRowButton: (rowIndex: number) => Command;
26
28
  export declare const hideInsertColumnOrRowButton: () => Command;
@@ -16,6 +16,7 @@ type DragControlsProps = {
16
16
  canDrag?: boolean;
17
17
  hoverRows: (rows: number[], danger?: boolean) => void;
18
18
  selectRow: (row: number, expand: boolean) => void;
19
+ selectRows: (rowIndexes: number[]) => void;
19
20
  updateCellHoverLocation: (rowIndex: number) => void;
20
21
  };
21
22
  export declare const DragControls: React.FC<import("react-intl-next").WithIntlProps<DragControlsProps & WrappedComponentProps<"intl">>> & {
@@ -42,6 +42,7 @@ export default class TableFloatingControls extends Component<Props, State> {
42
42
  componentWillUnmount(): void;
43
43
  render(): JSX.Element | null;
44
44
  private selectRow;
45
+ private selectRows;
45
46
  private hoverRows;
46
47
  private updateCellHoverLocation;
47
48
  }
@@ -9,4 +9,4 @@ export type { RowParams } from './row-controls';
9
9
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
10
10
  export { getMergedCellsPositions } from './table';
11
11
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
12
- export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
12
+ export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, } from './merged-cells';
@@ -1,3 +1,6 @@
1
1
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ type MergeType = 'row' | 'column';
2
3
  export declare const hasMergedCellsInColumn: (columnIndexes: number | number[]) => (selection: Selection) => boolean;
3
4
  export declare const hasMergedCellsInRow: (rowIndexes: number | number[]) => (selection: Selection) => boolean;
5
+ export declare const hasMergedCellsInBetween: (indexes: number[], type: MergeType) => (selection: Selection) => boolean;
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.5.3",
3
+ "version": "5.5.5",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -144,9 +144,9 @@ describe('Floating Insert Button when findDomRefAtPos fails', () => {
144
144
  docSize: 46,
145
145
  error: 'Error: Error message from mock',
146
146
  }),
147
- nonPrivacySafeAttributes: expect.objectContaining({
148
- errorStack: 'stack trace',
149
- }),
147
+ });
148
+ expect(createAnalyticsEvent).not.toHaveBeenCalledWith({
149
+ nonPrivacySafeAttributes: expect.any(Object),
150
150
  });
151
151
  });
152
152
 
@@ -74,6 +74,7 @@ describe('NumberColumn', () => {
74
74
  isTableHovered={true}
75
75
  hoverRows={jest.fn()}
76
76
  selectRow={jest.fn()}
77
+ selectRows={jest.fn()}
77
78
  updateCellHoverLocation={jest.fn()}
78
79
  tableWidth={760}
79
80
  />
@@ -111,6 +112,7 @@ describe('NumberColumn', () => {
111
112
  }}
112
113
  hoverRows={jest.fn()}
113
114
  selectRow={jest.fn()}
115
+ selectRows={jest.fn()}
114
116
  updateCellHoverLocation={jest.fn()}
115
117
  tableWidth={760}
116
118
  />
@@ -0,0 +1,156 @@
1
+ import type { DocBuilder } from '@atlaskit/editor-common/types';
2
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
3
+ import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
5
+ import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
6
+ import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
7
+ import { widthPlugin } from '@atlaskit/editor-plugin-width';
8
+ // eslint-disable-next-line import/no-extraneous-dependencies
9
+ import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
10
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
11
+ import {
12
+ createProsemirrorEditorFactory,
13
+ Preset,
14
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
15
+ // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
16
+ import {
17
+ doc,
18
+ p,
19
+ table,
20
+ td,
21
+ tdEmpty,
22
+ tr,
23
+ } from '@atlaskit/editor-test-helpers/doc-builder';
24
+
25
+ import tablePlugin from '../../../plugins/table-plugin';
26
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
27
+ import { hasMergedCellsInBetween } from '../../../plugins/table/utils';
28
+
29
+ describe('table merge cells logic', () => {
30
+ const createEditor = createProsemirrorEditorFactory();
31
+
32
+ const editor = (doc: DocBuilder) =>
33
+ createEditor({
34
+ doc,
35
+ preset: new Preset<LightEditorPlugin>()
36
+ .add([analyticsPlugin, {}])
37
+ .add(contentInsertionPlugin)
38
+ .add(widthPlugin)
39
+ .add(guidelinePlugin)
40
+ .add(selectionPlugin)
41
+ .add(tablePlugin),
42
+ pluginKey,
43
+ });
44
+
45
+ describe('#hasMergedCellsInBetween', () => {
46
+ describe('when first and second columns are merged', () => {
47
+ const { editorView } = editor(
48
+ doc(
49
+ table()(
50
+ tr(td({ colspan: 2 })(p('')), tdEmpty, tdEmpty),
51
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
52
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
53
+ ),
54
+ ),
55
+ );
56
+
57
+ it('should return false when pass indexs [-1, 0]', () => {
58
+ expect(
59
+ hasMergedCellsInBetween(
60
+ [-1, 0],
61
+ 'column',
62
+ )(editorView.state.selection),
63
+ ).toEqual(false);
64
+ });
65
+
66
+ it('should return true when pass indexs [0,1]', () => {
67
+ expect(
68
+ hasMergedCellsInBetween([0, 1], 'column')(editorView.state.selection),
69
+ ).toEqual(true);
70
+ });
71
+
72
+ it('should return false when pass indexs [1,2]', () => {
73
+ expect(
74
+ hasMergedCellsInBetween([1, 2], 'column')(editorView.state.selection),
75
+ ).toEqual(false);
76
+ });
77
+ });
78
+
79
+ describe('when second and third columns are merged', () => {
80
+ const { editorView } = editor(
81
+ doc(
82
+ table()(
83
+ tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
84
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
85
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
86
+ ),
87
+ ),
88
+ );
89
+ it('should return false when pass indexs [0,1]', () => {
90
+ expect(
91
+ hasMergedCellsInBetween([0, 1], 'column')(editorView.state.selection),
92
+ ).toEqual(false);
93
+ });
94
+
95
+ it('should return true when pass indexs [1,2]', () => {
96
+ expect(
97
+ hasMergedCellsInBetween([1, 2], 'column')(editorView.state.selection),
98
+ ).toEqual(true);
99
+ });
100
+ });
101
+
102
+ describe('when first and second rows are merged', () => {
103
+ const { editorView } = editor(
104
+ doc(
105
+ table()(
106
+ tr(td({ rowspan: 2 })(p('')), tdEmpty, tdEmpty, tdEmpty),
107
+ tr(tdEmpty, tdEmpty, tdEmpty),
108
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
109
+ ),
110
+ ),
111
+ );
112
+
113
+ it('should return false when pass indexs [-1, 0]', () => {
114
+ expect(
115
+ hasMergedCellsInBetween([-1, 0], 'row')(editorView.state.selection),
116
+ ).toEqual(false);
117
+ });
118
+
119
+ it('should return true when pass indexs [0,1]', () => {
120
+ expect(
121
+ hasMergedCellsInBetween([0, 1], 'row')(editorView.state.selection),
122
+ ).toEqual(true);
123
+ });
124
+
125
+ it('should return false when pass indexs [1,2]', () => {
126
+ expect(
127
+ hasMergedCellsInBetween([1, 2], 'row')(editorView.state.selection),
128
+ ).toEqual(false);
129
+ });
130
+ });
131
+
132
+ describe('when second and third rows are merged', () => {
133
+ const { editorView } = editor(
134
+ doc(
135
+ table()(
136
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
137
+ tr(td({ rowspan: 2 })(p('')), tdEmpty, tdEmpty),
138
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
139
+ ),
140
+ ),
141
+ );
142
+
143
+ it('should return false when pass indexs [0,1]', () => {
144
+ expect(
145
+ hasMergedCellsInBetween([0, 1], 'row')(editorView.state.selection),
146
+ ).toEqual(false);
147
+ });
148
+
149
+ it('should return true when pass indexs [1,2]', () => {
150
+ expect(
151
+ hasMergedCellsInBetween([1, 2], 'row')(editorView.state.selection),
152
+ ).toEqual(true);
153
+ });
154
+ });
155
+ });
156
+ });
@@ -26,7 +26,9 @@ export {
26
26
  hideInsertColumnOrRowButton,
27
27
  moveCursorBackward,
28
28
  selectColumn,
29
+ selectColumns,
29
30
  selectRow,
31
+ selectRows,
30
32
  setCellAttr,
31
33
  setEditorFocus,
32
34
  setMultipleCellAttrs,