@atlaskit/editor-plugin-table 5.4.8 → 5.4.9

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,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.4.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#58068](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58068) [`3f88811fe28a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3f88811fe28a) - Disable move commands in floating menu when there are merged cells
8
+
3
9
  ## 5.4.8
4
10
 
5
11
  ### Patch Changes
@@ -81,7 +81,9 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
81
81
  dispatch = editorView.dispatch;
82
82
  var selection = state.selection;
83
83
  var selectionRect = (0, _utils.isSelectionType)(selection, 'cell') ? (0, _utils.getSelectionRect)(selection) : (0, _utils.findCellRectClosestToPos)(selection.$from);
84
- var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect);
84
+ var hasMergedCells = direction === 'row' ? _utils2.hasMergedCellsInRow : _utils2.hasMergedCellsInColumn;
85
+ var mergedCells = index !== undefined && hasMergedCells(index)(selection);
86
+ var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, mergedCells, tableMap, index, targetCellPosition, selectionRect);
85
87
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
86
88
  menuItems = _convertToDropdownIte.menuItems,
87
89
  menuCallback = _convertToDropdownIte.menuCallback;
@@ -30,7 +30,7 @@ var canIncrease = function canIncrease(index) {
30
30
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
31
31
  return index !== undefined && index < max;
32
32
  };
33
- var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect) {
33
+ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, hasMergedCells, tableMap, index, targetCellPosition, selectionRect) {
34
34
  var addOptions = direction === 'row' ? [{
35
35
  label: 'above',
36
36
  offset: 0,
@@ -144,7 +144,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
144
144
  return {
145
145
  id: "move_".concat(direction, "_").concat(label),
146
146
  title: "Move ".concat(direction, " ").concat(label),
147
- disabled: !canMove(index),
147
+ disabled: hasMergedCells || !canMove(index),
148
148
  icon: icon,
149
149
  onClick: function onClick(state, dispatch) {
150
150
  if (canMove(index)) {
@@ -7,7 +7,7 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
7
7
  import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
8
8
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
9
9
  import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
10
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
10
+ import { getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
11
11
  import { getDragMenuConfig } from '../../utils/drag-menu';
12
12
  import { dragMenuDropdownWidth } from '../consts';
13
13
  const groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
@@ -72,7 +72,9 @@ export const DragMenu = ({
72
72
  selection
73
73
  } = state;
74
74
  const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
75
- const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect);
75
+ const hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
76
+ const mergedCells = index !== undefined && hasMergedCells(index)(selection);
77
+ const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, mergedCells, tableMap, index, targetCellPosition, selectionRect);
76
78
  const {
77
79
  menuItems,
78
80
  menuCallback
@@ -16,7 +16,7 @@ import { deleteRows } from '../transforms';
16
16
  import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
17
17
  const canDecrease = (index, min = 0) => index !== undefined && index > min;
18
18
  const canIncrease = (index, max = 0) => index !== undefined && index < max;
19
- export const getDragMenuConfig = (direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect) => {
19
+ export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedCells, tableMap, index, targetCellPosition, selectionRect) => {
20
20
  const addOptions = direction === 'row' ? [{
21
21
  label: 'above',
22
22
  offset: 0,
@@ -129,7 +129,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, tableMap,
129
129
  }) => ({
130
130
  id: `move_${direction}_${label}`,
131
131
  title: `Move ${direction} ${label}`,
132
- disabled: !canMove(index),
132
+ disabled: hasMergedCells || !canMove(index),
133
133
  icon,
134
134
  onClick: (state, dispatch) => {
135
135
  if (canMove(index)) {
@@ -8,7 +8,7 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
8
8
  import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
9
9
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
10
10
  import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
11
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
11
+ import { getSelectedColumnIndexes, getSelectedRowIndexes, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
12
12
  import { getDragMenuConfig } from '../../utils/drag-menu';
13
13
  import { dragMenuDropdownWidth } from '../consts';
14
14
  var groupedDragMenuConfig = [['add_row_above', 'add_row_below', 'add_column_left', 'add_column_right', 'distribute_columns', 'clear_cells', 'delete_row', 'delete_column'], ['move_column_left', 'move_column_right', 'move_row_up', 'move_row_down'], ['sort_column_asc', 'sort_column_desc']];
@@ -73,7 +73,9 @@ export var DragMenu = function DragMenu(_ref) {
73
73
  dispatch = editorView.dispatch;
74
74
  var selection = state.selection;
75
75
  var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
76
- var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect);
76
+ var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
77
+ var mergedCells = index !== undefined && hasMergedCells(index)(selection);
78
+ var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, mergedCells, tableMap, index, targetCellPosition, selectionRect);
77
79
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
78
80
  menuItems = _convertToDropdownIte.menuItems,
79
81
  menuCallback = _convertToDropdownIte.menuCallback;
@@ -23,7 +23,7 @@ var canIncrease = function canIncrease(index) {
23
23
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
24
24
  return index !== undefined && index < max;
25
25
  };
26
- export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect) {
26
+ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, hasMergedCells, tableMap, index, targetCellPosition, selectionRect) {
27
27
  var addOptions = direction === 'row' ? [{
28
28
  label: 'above',
29
29
  offset: 0,
@@ -137,7 +137,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
137
137
  return {
138
138
  id: "move_".concat(direction, "_").concat(label),
139
139
  title: "Move ".concat(direction, " ").concat(label),
140
- disabled: !canMove(index),
140
+ disabled: hasMergedCells || !canMove(index),
141
141
  icon: icon,
142
142
  onClick: function onClick(state, dispatch) {
143
143
  if (canMove(index)) {
@@ -7,4 +7,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
7
7
  icon?: React.ComponentType<IconProps>;
8
8
  keymap?: string;
9
9
  }
10
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
10
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, hasMergedCells: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
@@ -7,4 +7,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
7
7
  icon?: React.ComponentType<IconProps>;
8
8
  keymap?: string;
9
9
  }
10
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
10
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, hasMergedCells: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.4.8",
3
+ "version": "5.4.9",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -26,7 +26,12 @@ import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
26
26
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
27
27
  import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
28
28
  import type { PluginConfig, TableDirection } from '../../types';
29
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
29
+ import {
30
+ getSelectedColumnIndexes,
31
+ getSelectedRowIndexes,
32
+ hasMergedCellsInColumn,
33
+ hasMergedCellsInRow,
34
+ } from '../../utils';
30
35
  import type { DragMenuConfig } from '../../utils/drag-menu';
31
36
  import { getDragMenuConfig } from '../../utils/drag-menu';
32
37
  import { dragMenuDropdownWidth } from '../consts';
@@ -123,9 +128,15 @@ export const DragMenu = ({
123
128
  ? getSelectionRect(selection)!
124
129
  : findCellRectClosestToPos(selection.$from);
125
130
 
131
+ const hasMergedCells =
132
+ direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
133
+
134
+ const mergedCells = index !== undefined && hasMergedCells(index)(selection);
135
+
126
136
  const dragMenuConfig = getDragMenuConfig(
127
137
  direction,
128
138
  getEditorContainerWidth,
139
+ mergedCells,
129
140
  tableMap,
130
141
  index,
131
142
  targetCellPosition,
@@ -57,6 +57,7 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
57
57
  export const getDragMenuConfig = (
58
58
  direction: TableDirection,
59
59
  getEditorContainerWidth: GetEditorContainerWidth,
60
+ hasMergedCells: boolean,
60
61
  tableMap?: TableMap,
61
62
  index?: number,
62
63
  targetCellPosition?: number,
@@ -95,7 +96,12 @@ export const getDragMenuConfig = (
95
96
  const moveOptions =
96
97
  direction === 'row'
97
98
  ? [
98
- { label: 'up', offset: -1, canMove: canDecrease, icon: ArrowUpIcon },
99
+ {
100
+ label: 'up',
101
+ offset: -1,
102
+ canMove: canDecrease,
103
+ icon: ArrowUpIcon,
104
+ },
99
105
  {
100
106
  label: 'down',
101
107
  offset: 1,
@@ -190,7 +196,7 @@ export const getDragMenuConfig = (
190
196
  ...moveOptions.map(({ label, offset, canMove, icon }) => ({
191
197
  id: `move_${direction}_${label}`,
192
198
  title: `Move ${direction} ${label}`,
193
- disabled: !canMove(index),
199
+ disabled: hasMergedCells || !canMove(index),
194
200
  icon,
195
201
  onClick: (state: EditorState, dispatch?: CommandDispatch) => {
196
202
  if (canMove(index)) {