@atlaskit/editor-plugin-table 5.4.8 → 5.4.10

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,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.4.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#58174](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58174) [`b409282ab2b8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b409282ab2b8) - Check pasted slice is a table element before trying to access table map
8
+
9
+ ## 5.4.9
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
14
+
3
15
  ## 5.4.8
4
16
 
5
17
  ### Patch Changes
@@ -181,17 +181,21 @@ var getTableSelectionType = exports.getTableSelectionType = function getTableSel
181
181
  }
182
182
  };
183
183
  var getTableElementMoveTypeBySlice = exports.getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySlice(slice, state) {
184
- if (!slice.content.firstChild) {
184
+ var _state$schema$nodes = state.schema.nodes,
185
+ tableRow = _state$schema$nodes.tableRow,
186
+ table = _state$schema$nodes.table;
187
+
188
+ // check if copied slice is a table or table row
189
+ if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
185
190
  return;
186
191
  }
187
- var schema = state.schema;
188
192
 
189
193
  // if the slice only contains one table row, assume it's a row
190
- if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
194
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
191
195
  return 'row';
192
196
  }
193
- var table = (0, _utils2.findTable)(state.tr.selection);
194
- var map = _tableMap.TableMap.get(table.node);
197
+ var currentTable = (0, _utils2.findTable)(state.tr.selection);
198
+ var map = _tableMap.TableMap.get(currentTable.node);
195
199
  var slicedMap = _tableMap.TableMap.get(slice.content.firstChild);
196
200
  return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
197
201
  };
@@ -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)) {
@@ -183,19 +183,26 @@ export const getTableSelectionType = selection => {
183
183
  }
184
184
  };
185
185
  export const getTableElementMoveTypeBySlice = (slice, state) => {
186
- if (!slice.content.firstChild) {
187
- return;
188
- }
189
186
  const {
190
- schema
187
+ schema: {
188
+ nodes: {
189
+ tableRow,
190
+ table
191
+ }
192
+ }
191
193
  } = state;
192
194
 
195
+ // check if copied slice is a table or table row
196
+ if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
197
+ return;
198
+ }
199
+
193
200
  // if the slice only contains one table row, assume it's a row
194
- if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
201
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
195
202
  return 'row';
196
203
  }
197
- const table = findTable(state.tr.selection);
198
- const map = TableMap.get(table.node);
204
+ const currentTable = findTable(state.tr.selection);
205
+ const map = TableMap.get(currentTable.node);
199
206
  const slicedMap = TableMap.get(slice.content.firstChild);
200
207
  return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
201
208
  };
@@ -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)) {
@@ -174,17 +174,21 @@ export var getTableSelectionType = function getTableSelectionType(selection) {
174
174
  }
175
175
  };
176
176
  export var getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySlice(slice, state) {
177
- if (!slice.content.firstChild) {
177
+ var _state$schema$nodes = state.schema.nodes,
178
+ tableRow = _state$schema$nodes.tableRow,
179
+ table = _state$schema$nodes.table;
180
+
181
+ // check if copied slice is a table or table row
182
+ if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
178
183
  return;
179
184
  }
180
- var schema = state.schema;
181
185
 
182
186
  // if the slice only contains one table row, assume it's a row
183
- if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
187
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
184
188
  return 'row';
185
189
  }
186
- var table = findTable(state.tr.selection);
187
- var map = TableMap.get(table.node);
190
+ var currentTable = findTable(state.tr.selection);
191
+ var map = TableMap.get(currentTable.node);
188
192
  var slicedMap = TableMap.get(slice.content.firstChild);
189
193
  return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
190
194
  };
@@ -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.10",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -276,22 +276,31 @@ export const getTableElementMoveTypeBySlice = (
276
276
  slice: Slice,
277
277
  state: EditorState,
278
278
  ) => {
279
- if (!slice.content.firstChild) {
279
+ const {
280
+ schema: {
281
+ nodes: { tableRow, table },
282
+ },
283
+ } = state;
284
+
285
+ // check if copied slice is a table or table row
286
+ if (
287
+ !slice.content.firstChild ||
288
+ (slice.content.firstChild.type !== table &&
289
+ slice.content.firstChild.type !== tableRow)
290
+ ) {
280
291
  return;
281
292
  }
282
293
 
283
- const { schema } = state;
284
-
285
294
  // if the slice only contains one table row, assume it's a row
286
295
  if (
287
296
  slice.content.childCount === 1 &&
288
- slice.content.firstChild.type === schema.nodes.tableRow
297
+ slice.content.firstChild.type === tableRow
289
298
  ) {
290
299
  return 'row';
291
300
  }
292
301
 
293
- const table = findTable(state.tr.selection)!;
294
- const map = TableMap.get(table.node);
302
+ const currentTable = findTable(state.tr.selection)!;
303
+ const map = TableMap.get(currentTable.node);
295
304
  const slicedMap = TableMap.get(slice.content.firstChild);
296
305
 
297
306
  return map.width === slicedMap.width
@@ -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)) {