@atlaskit/editor-plugin-table 5.5.2 → 5.5.4

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 (64) 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/index.js +1 -1
  5. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +22 -26
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +1 -0
  7. package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -7
  8. package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -15
  9. package/dist/cjs/plugins/table/ui/DragHandle/index.js +8 -19
  10. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +70 -36
  11. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -32
  12. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +11 -0
  13. package/dist/es2019/plugins/table/commands/index.js +1 -1
  14. package/dist/es2019/plugins/table/commands/misc.js +46 -1
  15. package/dist/es2019/plugins/table/index.js +1 -1
  16. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +25 -29
  17. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +1 -0
  18. package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -7
  19. package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -15
  20. package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -18
  21. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +71 -37
  22. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +3 -1
  23. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -32
  24. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +16 -1
  25. package/dist/esm/plugins/table/commands/index.js +1 -1
  26. package/dist/esm/plugins/table/commands/misc.js +61 -1
  27. package/dist/esm/plugins/table/index.js +1 -1
  28. package/dist/esm/plugins/table/nodeviews/TableComponent.js +22 -26
  29. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +1 -0
  30. package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -7
  31. package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -15
  32. package/dist/esm/plugins/table/ui/DragHandle/index.js +6 -17
  33. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +71 -37
  34. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -32
  35. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +12 -1
  36. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  37. package/dist/types/plugins/table/commands/misc.d.ts +2 -0
  38. package/dist/types/plugins/table/types.d.ts +1 -0
  39. package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +2 -7
  40. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +2 -1
  41. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  42. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  43. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  44. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +2 -0
  45. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
  46. package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +2 -7
  47. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
  48. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  49. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  50. package/package.json +1 -4
  51. package/src/__tests__/unit/ui/RowDragControls.tsx +2 -0
  52. package/src/plugins/table/commands/index.ts +2 -0
  53. package/src/plugins/table/commands/misc.ts +78 -0
  54. package/src/plugins/table/index.tsx +5 -7
  55. package/src/plugins/table/nodeviews/TableComponent.tsx +31 -38
  56. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +2 -0
  57. package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +5 -7
  58. package/src/plugins/table/types.ts +2 -0
  59. package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +5 -30
  60. package/src/plugins/table/ui/DragHandle/index.tsx +6 -23
  61. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +134 -49
  62. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +3 -3
  63. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +137 -44
  64. package/src/plugins/table/ui/TableFloatingControls/index.tsx +12 -1
@@ -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 ? {
@@ -204,7 +204,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
204
204
  var _options$tableResizin;
205
205
  var dispatch = _ref12.dispatch,
206
206
  dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent;
207
- return getBooleanFF('platform.editor.table.overflow-state-analytics') ? createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false) : undefined;
207
+ return createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
208
208
  }
209
209
  }, {
210
210
  name: 'tableAnalyticsPlugin',
@@ -386,10 +386,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
386
386
  this.onStickyState(currentStickyState);
387
387
  }
388
388
  eventDispatcher.on(stickyHeadersPluginKey.key, this.onStickyState);
389
- if (getBooleanFF('platform.editor.table.overflow-state-analytics')) {
390
- var initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
391
- this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
392
- }
389
+ var initialIsOveflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
390
+ this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
393
391
  }
394
392
  }, {
395
393
  key: "componentWillUnmount",
@@ -476,28 +474,26 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
476
474
  }
477
475
  this.handleTableResizingDebounced();
478
476
  }
479
- if (getBooleanFF('platform.editor.table.overflow-state-analytics')) {
480
- var newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
481
- var prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
482
- if (this.initialOverflowCaptureTimerId) {
483
- clearTimeout(this.initialOverflowCaptureTimerId);
484
- }
485
- if (!this.isInitialOverflowSent) {
486
- this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
487
- }
488
- if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
489
- var _this$state2;
490
- var _this$props$view = this.props.view,
491
- dispatch = _this$props$view.dispatch,
492
- tr = _this$props$view.state.tr;
493
- dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
494
- isOverflowing: newIsOverflowing,
495
- wasOverflowing: prevIsOverflowing,
496
- editorWidth: this.props.containerWidth.width || 0,
497
- width: this.node.attrs.width || 0,
498
- parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
499
- }));
500
- }
477
+ var newIsOverflowing = this.state[ShadowEvent.SHOW_BEFORE_SHADOW] || this.state[ShadowEvent.SHOW_AFTER_SHADOW];
478
+ var prevIsOverflowing = prevState[ShadowEvent.SHOW_BEFORE_SHADOW] || prevState[ShadowEvent.SHOW_AFTER_SHADOW];
479
+ if (this.initialOverflowCaptureTimerId) {
480
+ clearTimeout(this.initialOverflowCaptureTimerId);
481
+ }
482
+ if (!this.isInitialOverflowSent) {
483
+ this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
484
+ }
485
+ if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
486
+ var _this$state2;
487
+ var _this$props$view = this.props.view,
488
+ dispatch = _this$props$view.dispatch,
489
+ tr = _this$props$view.state.tr;
490
+ dispatch(tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
491
+ isOverflowing: newIsOverflowing,
492
+ wasOverflowing: prevIsOverflowing,
493
+ editorWidth: this.props.containerWidth.width || 0,
494
+ width: this.node.attrs.width || 0,
495
+ parentWidth: ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.parentWidth) || 0
496
+ }));
501
497
  }
502
498
  }
503
499
  }, {
@@ -184,6 +184,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
184
184
  sourceIndex = _sourceIndexes[0];
185
185
  requestAnimationFrame(function () {
186
186
  moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
187
+ editorView.focus();
187
188
  });
188
189
  }
189
190
  })
@@ -21,13 +21,11 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
21
21
  return false;
22
22
  }
23
23
  event.preventDefault();
24
- if (getBooleanFF('platform.editor.table.overflow-state-analytics')) {
25
- var tr = view.state.tr;
26
- tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
27
- name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED_COLUMN
28
- });
29
- dispatch(tr);
30
- }
24
+ var tr = view.state.tr;
25
+ tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
26
+ name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED_COLUMN
27
+ });
28
+ dispatch(tr);
31
29
  var mouseDownTime = event.timeStamp;
32
30
  var cell = state.doc.nodeAt(localResizeHandlePos);
33
31
  var $cell = state.doc.resolve(localResizeHandlePos);
@@ -1,24 +1,13 @@
1
1
  import React from 'react';
2
2
  import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../icons';
3
3
  export var HandleIconComponent = function HandleIconComponent(props) {
4
- var canDrag = props.canDrag,
5
- direction = props.direction,
6
- isDragMenuOpen = props.isDragMenuOpen,
4
+ var forceDefaultHandle = props.forceDefaultHandle,
7
5
  isRowHandleHovered = props.isRowHandleHovered,
8
6
  isColumnHandleHovered = props.isColumnHandleHovered,
9
- hasMergedCells = props.hasMergedCells,
10
- isCurrentRowSelected = props.isCurrentRowSelected,
11
- isCurrentColumnSelected = props.isCurrentColumnSelected,
12
- dragMenuDirection = props.dragMenuDirection;
7
+ hasMergedCells = props.hasMergedCells;
13
8
  var isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
14
- var isCurrentRowOrColumnSelected = isCurrentRowSelected || isCurrentColumnSelected;
15
- var isDragMenuOpenOnCurrentRowOrColumn = isDragMenuOpen && dragMenuDirection === direction && isCurrentRowOrColumnSelected;
16
- var isDragPossible = canDrag && !hasMergedCells;
17
- var showNormalHandle = !isDragPossible ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
18
-
19
- // hoverred handle or open drag menu
20
- if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
21
- return showNormalHandle;
9
+ if (isHandleHovered || forceDefaultHandle) {
10
+ return hasMergedCells ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
22
11
  }
23
12
  return /*#__PURE__*/React.createElement(MinimisedHandleIcon, null);
24
13
  };
@@ -6,7 +6,6 @@ import ReactDOM from 'react-dom';
6
6
  import { browser } from '@atlaskit/editor-common/utils';
7
7
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
8
8
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
9
- import { getPluginState as getDragDropPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
10
9
  import { getPluginState } from '../../pm-plugins/plugin-factory';
11
10
  import { TableCssClassName as ClassName } from '../../types';
12
11
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
@@ -19,6 +18,8 @@ export var DragHandle = function DragHandle(_ref) {
19
18
  _ref$appearance = _ref.appearance,
20
19
  appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
21
20
  indexes = _ref.indexes,
21
+ _ref$forceDefaultHand = _ref.forceDefaultHandle,
22
+ forceDefaultHandle = _ref$forceDefaultHand === void 0 ? false : _ref$forceDefaultHand,
22
23
  previewWidth = _ref.previewWidth,
23
24
  previewHeight = _ref.previewHeight,
24
25
  onMouseOver = _ref.onMouseOver,
@@ -35,30 +36,18 @@ export var DragHandle = function DragHandle(_ref) {
35
36
  setPreviewContainer = _useState2[1];
36
37
  var _getPluginState = getPluginState(editorView.state),
37
38
  hoveredColumns = _getPluginState.hoveredColumns,
38
- hoveredRows = _getPluginState.hoveredRows,
39
- hoveredCell = _getPluginState.hoveredCell;
40
- var _getDragDropPluginSta = getDragDropPluginState(editorView.state),
41
- dragMenuDirection = _getDragDropPluginSta.dragMenuDirection,
42
- isDragMenuOpen = _getDragDropPluginSta.isDragMenuOpen,
43
- dragMenuIndex = _getDragDropPluginSta.dragMenuIndex;
39
+ hoveredRows = _getPluginState.hoveredRows;
44
40
  var selection = editorView.state.selection;
45
- var isCurrentRowSelected = isDragMenuOpen && direction === 'row' && hoveredCell.rowIndex === dragMenuIndex;
46
- var isCurrentColumnSelected = isDragMenuOpen && direction === 'column' && hoveredCell.colIndex === dragMenuIndex;
47
41
  var isRowHandleHovered = direction === 'row' && hoveredRows.length > 0;
48
42
  var isColumnHandleHovered = direction === 'column' && hoveredColumns.length > 0;
49
43
  var hasMergedCells = useMemo(function () {
50
44
  return direction === 'row' ? hasMergedCellsInRow(indexes[0])(selection) : hasMergedCellsInColumn(indexes[0])(selection);
51
45
  }, [indexes, direction, selection]);
52
46
  var handleIconProps = {
53
- canDrag: _canDrag,
54
- hasMergedCells: hasMergedCells,
55
- direction: direction,
56
- isDragMenuOpen: isDragMenuOpen,
57
- isRowHandleHovered: isRowHandleHovered,
47
+ forceDefaultHandle: forceDefaultHandle,
58
48
  isColumnHandleHovered: isColumnHandleHovered,
59
- isCurrentRowSelected: isCurrentRowSelected,
60
- isCurrentColumnSelected: isCurrentColumnSelected,
61
- dragMenuDirection: dragMenuDirection
49
+ isRowHandleHovered: isRowHandleHovered,
50
+ hasMergedCells: hasMergedCells
62
51
  };
63
52
  useEffect(function () {
64
53
  var dragHandleDivRefCurrent = dragHandleDivRef.current;
@@ -1,8 +1,10 @@
1
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
+
1
3
  import React, { useCallback, useMemo } from 'react';
2
4
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
5
  import { CellSelection } from '@atlaskit/editor-tables';
4
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
- import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
7
+ import { clearHoverSelection, hoverCell, hoverColumns, selectColumn, selectColumns } from '../../../commands';
6
8
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
7
9
  import { TableCssClassName as ClassName } from '../../../types';
8
10
  import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
@@ -18,7 +20,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
18
20
  return [];
19
21
  };
20
22
  export var ColumnControls = function ColumnControls(_ref) {
21
- var _colWidths$map$join, _rowHeights$, _rowHeights$reduce, _colWidths;
23
+ var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
22
24
  var editorView = _ref.editorView,
23
25
  tableActive = _ref.tableActive,
24
26
  tableRef = _ref.tableRef,
@@ -39,21 +41,20 @@ export var ColumnControls = function ColumnControls(_ref) {
39
41
  var columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
40
42
  var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
41
43
  var selectedColIndexes = getSelectedColumns(editorView.state.selection);
42
- var gridColumnPosition = useMemo(function () {
43
- // if more than one row is selected, ensure the handle spans over the selected range
44
- if (selectedColIndexes.includes(colIndex)) {
45
- return "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
46
- }
47
- return "".concat(colIndex + 1, " / span 1");
48
- }, [colIndex, selectedColIndexes]);
49
44
  var firstRow = tableRef.querySelector('tr');
50
45
  var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
51
46
  var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
52
47
  var handleClick = useCallback(function (event) {
53
48
  var state = editorView.state,
54
49
  dispatch = editorView.dispatch;
55
- selectColumn(colIndex, event.shiftKey)(state, dispatch);
56
- }, [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]);
57
58
  var handleMouseOver = useCallback(function () {
58
59
  var state = editorView.state,
59
60
  dispatch = editorView.dispatch;
@@ -97,6 +98,64 @@ export var ColumnControls = function ColumnControls(_ref) {
97
98
  var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
98
99
  return sum + cur;
99
100
  }, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
101
+ var generateHandleByType = function generateHandleByType(type) {
102
+ var _colWidths;
103
+ if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
104
+ return null;
105
+ }
106
+ var isHover = type === 'hover';
107
+ var isColumnsSelected = selectedColIndexes.length > 0;
108
+ var showCondition = isHover ? isColumnsSelected && !selectedColIndexes.includes(colIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedColIndexes.length < (colWidths === null || colWidths === void 0 ? void 0 : colWidths.length) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
109
+ if (!showCondition) {
110
+ return null;
111
+ }
112
+ var gridColumnPosition = "".concat(colIndex + 1, " / span 1");
113
+ var selectedColumnPosition = "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
114
+ var hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
115
+ var currentSelectionApprearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
116
+ var istSelecting = isColumnsSelected && !isHover;
117
+
118
+ // this indexes are used to calculate the drag and drop source
119
+ var indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
120
+ return showCondition && /*#__PURE__*/React.createElement("div", {
121
+ key: type,
122
+ style: {
123
+ gridColumn: istSelecting ? selectedColumnPosition : gridColumnPosition,
124
+ display: 'flex',
125
+ justifyContent: 'center',
126
+ alignItems: 'center',
127
+ height: 'fit-content',
128
+ placeSelf: 'center',
129
+ zIndex: 99
130
+ },
131
+ "data-column-control-index": hoveredCell.colIndex,
132
+ "data-testid": isHover ? 'table-floating-column-control-hover' : 'table-floating-column-control'
133
+ }, /*#__PURE__*/React.createElement(DragHandle, {
134
+ direction: "column",
135
+ tableLocalId: localId || '',
136
+ indexes: indexes,
137
+ forceDefaultHandle: isHover ? false : isColumnsSelected,
138
+ previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
139
+ previewHeight: previewHeight,
140
+ appearance: istSelecting ? currentSelectionApprearance : hoveredAppearance,
141
+ onClick: handleClick,
142
+ onMouseOver: handleMouseOver,
143
+ onMouseOut: handleMouseOut,
144
+ onMouseUp: handleMouseUp,
145
+ editorView: editorView,
146
+ canDrag: canDrag
147
+ }));
148
+ };
149
+ var columnHandles = function columnHandles(hoveredCell) {
150
+ if (!hoveredCell) {
151
+ return null;
152
+ }
153
+ if (hoveredCell.colIndex === undefined) {
154
+ return generateHandleByType('selected');
155
+ }
156
+ var sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
157
+ return hoveredCell.colIndex < selectedColIndexes[0] ? sortedHandles : sortedHandles.reverse();
158
+ };
100
159
  return /*#__PURE__*/React.createElement("div", {
101
160
  className: ClassName.DRAG_COLUMN_CONTROLS,
102
161
  onMouseMove: handleMouseMove
@@ -125,31 +184,6 @@ export var ColumnControls = function ColumnControls(_ref) {
125
184
  right: '0'
126
185
  } : {}
127
186
  }));
128
- }), tableActive && !isResizing && isTableHovered && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
129
- style: {
130
- gridColumn: gridColumnPosition,
131
- display: 'flex',
132
- justifyContent: 'center',
133
- alignItems: 'center',
134
- height: 'fit-content',
135
- placeSelf: 'center',
136
- zIndex: 99
137
- },
138
- "data-column-control-index": hoveredCell.colIndex,
139
- "data-testid": "table-floating-column-control"
140
- }, /*#__PURE__*/React.createElement(DragHandle, {
141
- direction: "column",
142
- tableLocalId: localId || '',
143
- indexes: colIndexes,
144
- previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
145
- previewHeight: previewHeight,
146
- appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
147
- onClick: handleClick,
148
- onMouseOver: handleMouseOver,
149
- onMouseOut: handleMouseOut,
150
- onMouseUp: handleMouseUp,
151
- editorView: editorView,
152
- canDrag: canDrag
153
- }))));
187
+ }), tableActive && isTableHovered && !isResizing && columnHandles(hoveredCell)));
154
188
  };
155
189
  export default ColumnControls;
@@ -1,4 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
3
+
2
4
  import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
3
5
  import { injectIntl } from 'react-intl-next';
4
6
  import { CellSelection } from '@atlaskit/editor-tables';
@@ -36,6 +38,7 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
36
38
  canDrag = _ref.canDrag,
37
39
  hoverRows = _ref.hoverRows,
38
40
  selectRow = _ref.selectRow,
41
+ selectRows = _ref.selectRows,
39
42
  updateCellHoverLocation = _ref.updateCellHoverLocation;
40
43
  var _useState = useState(false),
41
44
  _useState2 = _slicedToArray(_useState, 2),
@@ -77,13 +80,6 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
77
80
  toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
78
81
  }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
79
82
  var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
80
- var gridRowPosition = useMemo(function () {
81
- // if more than one row is selected, ensure the handle spans over the selected range
82
- if (selectedRowIndexes.includes(rowIndex)) {
83
- return "".concat(selectedRowIndexes[0] + 1, " / span ").concat(selectedRowIndexes.length);
84
- }
85
- return "".concat(rowIndex + 1, " / span 1");
86
- }, [rowIndex, selectedRowIndexes]);
87
83
  var handleMouseOut = useCallback(function () {
88
84
  if (tableActive) {
89
85
  var state = editorView.state,
@@ -108,8 +104,69 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
108
104
  hoverRows([rowIndex]);
109
105
  }, [hoverRows, rowIndex]);
110
106
  var handleClick = useCallback(function (e) {
111
- selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
112
- }, [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]);
115
+ var generateHandleByType = function generateHandleByType(type) {
116
+ if (!hoveredCell) {
117
+ return null;
118
+ }
119
+ var isHover = type === 'hover';
120
+ var isRowsSelected = selectedRowIndexes.length > 0;
121
+ var showCondition = isHover ? isRowsSelected && !selectedRowIndexes.includes(rowIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedRowIndexes.length < rowHeights.length && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
122
+ if (!showCondition) {
123
+ return null;
124
+ }
125
+ var gridRowPosition = "".concat(rowIndex + 1, " / span 1");
126
+
127
+ // if more than one row is selected, ensure the handle spans over the selected range
128
+ var selectedRowPosition = "".concat(selectedRowIndexes[0] + 1, " / span ").concat(selectedRowIndexes.length);
129
+ var hoveredAppearance = selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
130
+ var currentSelectionAppearance = isRowsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
131
+ var isSelecting = isRowsSelected && !isHover;
132
+ var indexes = isRowsSelected ? isHover ? rowIndexes : selectedRowIndexes : rowIndexes;
133
+ return showCondition && /*#__PURE__*/React.createElement("div", {
134
+ key: type,
135
+ style: {
136
+ gridRow: isSelecting ? selectedRowPosition : gridRowPosition,
137
+ gridColumn: '2',
138
+ // DragHandle uses `transform: rotate(90)`, which doesn't affect its parent (this div) causing the width of this element to be the true height of the drag handle
139
+ width: '9px',
140
+ position: 'relative',
141
+ right: '-0.5px'
142
+ },
143
+ "data-testid": isHover ? 'table-floating-row-drag-handle-hover' : 'table-floating-row-drag-handle'
144
+ }, /*#__PURE__*/React.createElement(DragHandle, {
145
+ direction: "row",
146
+ tableLocalId: currentNodeLocalId,
147
+ indexes: indexes,
148
+ forceDefaultHandle: isHover ? false : isRowsSelected,
149
+ previewWidth: tableWidth,
150
+ previewHeight: rowHeights[rowIndex],
151
+ appearance: isSelecting ? currentSelectionAppearance : hoveredAppearance,
152
+ onClick: handleClick,
153
+ onMouseOver: handleMouseOver,
154
+ onMouseOut: handleMouseOut,
155
+ onMouseUp: onMouseUp,
156
+ editorView: editorView,
157
+ canDrag: canDrag
158
+ }));
159
+ };
160
+ var rowHandles = function rowHandles(hoveredCell) {
161
+ if (!hoveredCell) {
162
+ return null;
163
+ }
164
+ if (hoveredCell.rowIndex === undefined) {
165
+ return generateHandleByType('selected');
166
+ }
167
+ var sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
168
+ return hoveredCell.rowIndex < selectedRowIndexes[0] ? sortedHandles : sortedHandles.reverse();
169
+ };
113
170
  return /*#__PURE__*/React.createElement("div", {
114
171
  className: ClassName.DRAG_ROW_CONTROLS,
115
172
  style: {
@@ -149,28 +206,6 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
149
206
  left: "var(--ds-space-negative-100, -8px)"
150
207
  }
151
208
  }));
152
- }), !isResizing && isTableHovered && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
153
- style: {
154
- gridRow: gridRowPosition,
155
- gridColumn: '2',
156
- // DragHandle uses `transform: rotate(90)`, which doesn't affect its parent (this div) causing the width of this element to be the true height of the drag handle
157
- width: '9px',
158
- position: 'relative',
159
- right: '-0.5px'
160
- },
161
- "data-testid": "table-floating-row-drag-handle"
162
- }, /*#__PURE__*/React.createElement(DragHandle, {
163
- tableLocalId: currentNodeLocalId,
164
- indexes: rowIndexes,
165
- previewWidth: tableWidth,
166
- previewHeight: rowHeights[rowIndex],
167
- appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
168
- onClick: handleClick,
169
- onMouseOver: handleMouseOver,
170
- onMouseOut: handleMouseOut,
171
- onMouseUp: onMouseUp,
172
- editorView: editorView,
173
- canDrag: canDrag
174
- })));
209
+ }), tableActive && isTableHovered && !isResizing && Number.isFinite(rowIndex) && rowHandles(hoveredCell));
175
210
  };
176
211
  export var DragControls = injectIntl(DragControlsComponent);
@@ -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, {
@@ -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;
@@ -421,3 +421,4 @@ export interface DraggableData {
421
421
  targetClosestEdge: Edge;
422
422
  direction: 1 | -1;
423
423
  }
424
+ export type HandleTypes = 'hover' | 'selected';
@@ -1,14 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  type HandleIconProps = {
3
- canDrag: boolean;
4
- hasMergedCells: boolean;
5
- direction: 'row' | 'column';
6
- isDragMenuOpen: boolean | undefined;
3
+ forceDefaultHandle: boolean;
7
4
  isRowHandleHovered: boolean;
8
5
  isColumnHandleHovered: boolean;
9
- isCurrentRowSelected: boolean;
10
- isCurrentColumnSelected: boolean;
11
- dragMenuDirection: 'row' | 'column' | undefined;
6
+ hasMergedCells: boolean;
12
7
  };
13
8
  export declare const HandleIconComponent: (props: HandleIconProps) => JSX.Element;
14
9
  export {};
@@ -5,6 +5,7 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
5
5
  type DragHandleProps = {
6
6
  tableLocalId: string;
7
7
  indexes: number[];
8
+ forceDefaultHandle?: boolean;
8
9
  previewWidth?: number;
9
10
  previewHeight?: number;
10
11
  direction?: TableDirection;
@@ -16,5 +17,5 @@ type DragHandleProps = {
16
17
  editorView: EditorView;
17
18
  canDrag?: boolean;
18
19
  };
19
- export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, canDrag, }: DragHandleProps) => JSX.Element;
20
+ export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, forceDefaultHandle, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, canDrag, }: DragHandleProps) => JSX.Element;
20
21
  export {};