@atlaskit/editor-plugin-table 5.5.7 → 5.5.8

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,12 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.5.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#60644](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/60644) [`513c52530ec8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/513c52530ec8) - add distribute column logic to drag menu
8
+ - Updated dependencies
9
+
3
10
  ## 5.5.7
4
11
 
5
12
  ### Patch Changes
@@ -84,7 +84,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
84
84
  var selectionRect = (0, _utils.isSelectionType)(selection, 'cell') ? (0, _utils.getSelectionRect)(selection) : (0, _utils.findCellRectClosestToPos)(selection.$from);
85
85
  var hasMergedCells = direction === 'row' ? _utils2.hasMergedCellsInRow : _utils2.hasMergedCellsInColumn;
86
86
  var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
87
- var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
87
+ var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, editorView, tableMap, index, targetCellPosition, selectionRect);
88
88
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
89
89
  menuItems = _convertToDropdownIte.menuItems,
90
90
  menuCallback = _convertToDropdownIte.menuCallback;
@@ -20,8 +20,12 @@ var _chevronDoubleUp = _interopRequireDefault(require("@atlaskit/icon/glyph/hipc
20
20
  var _commands = require("../commands");
21
21
  var _delete = require("../commands/delete");
22
22
  var _commands2 = require("../pm-plugins/drag-and-drop/commands");
23
+ var _commands3 = require("../pm-plugins/table-resizing/commands");
24
+ var _resizeState = require("../pm-plugins/table-resizing/utils/resize-state");
25
+ var _toolbar = require("../toolbar");
23
26
  var _transforms = require("../transforms");
24
27
  var _icons = require("../ui/icons");
28
+ var _index = require("./index");
25
29
  var canDecrease = function canDecrease(index) {
26
30
  var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
27
31
  return index !== undefined && index > min;
@@ -30,7 +34,15 @@ var canIncrease = function canIncrease(index) {
30
34
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
31
35
  return index !== undefined && index < max;
32
36
  };
33
- var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, tableMap, index, targetCellPosition, selectionRect) {
37
+ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
38
+ var rect = (0, _toolbar.getClosestSelectionRect)(state);
39
+ if (rect) {
40
+ var selectedColIndexes = (0, _index.getSelectedColumnIndexes)(rect);
41
+ return selectedColIndexes.length > 1;
42
+ }
43
+ return false;
44
+ };
45
+ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, editorView, tableMap, index, targetCellPosition, selectionRect) {
34
46
  var addOptions = direction === 'row' ? [{
35
47
  label: 'above',
36
48
  offset: 0,
@@ -114,8 +126,19 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
114
126
  })), [direction === 'column' ? {
115
127
  id: 'distribute_columns',
116
128
  title: 'Distribute columns',
117
- disabled: true,
118
- onClick: function onClick() {
129
+ disabled: !isDistributeColumnsEnabled(editorView.state),
130
+ onClick: function onClick(state, dispatch) {
131
+ var selectionRect = (0, _toolbar.getClosestSelectionRect)(state);
132
+ if (selectionRect) {
133
+ var newResizeState = (0, _resizeState.getNewResizeStateFromSelectedColumns)(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
134
+ if (newResizeState) {
135
+ var resizeState = newResizeState.resizeState,
136
+ table = newResizeState.table;
137
+ (0, _commands3.distributeColumnsWidths)(resizeState, table)(state, dispatch);
138
+ return true;
139
+ }
140
+ return false;
141
+ }
119
142
  return false;
120
143
  },
121
144
  icon: _layoutThreeEqual.default
@@ -75,7 +75,7 @@ export const DragMenu = ({
75
75
  const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
76
76
  const hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
77
77
  const shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
78
- const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
78
+ const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, editorView, tableMap, index, targetCellPosition, selectionRect);
79
79
  const {
80
80
  menuItems,
81
81
  menuCallback
@@ -12,11 +12,23 @@ import HipchatChevronDoubleUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-dou
12
12
  import { clearMultipleCells, insertColumn, insertRow, sortByColumn } from '../commands';
13
13
  import { deleteColumnsCommand } from '../commands/delete';
14
14
  import { moveSource } from '../pm-plugins/drag-and-drop/commands';
15
+ import { distributeColumnsWidths } from '../pm-plugins/table-resizing/commands';
16
+ import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizing/utils/resize-state';
17
+ import { getClosestSelectionRect } from '../toolbar';
15
18
  import { deleteRows } from '../transforms';
16
19
  import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
20
+ import { getSelectedColumnIndexes } from './index';
17
21
  const canDecrease = (index, min = 0) => index !== undefined && index > min;
18
22
  const canIncrease = (index, max = 0) => index !== undefined && index < max;
19
- export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, tableMap, index, targetCellPosition, selectionRect) => {
23
+ const isDistributeColumnsEnabled = state => {
24
+ const rect = getClosestSelectionRect(state);
25
+ if (rect) {
26
+ const selectedColIndexes = getSelectedColumnIndexes(rect);
27
+ return selectedColIndexes.length > 1;
28
+ }
29
+ return false;
30
+ };
31
+ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, editorView, tableMap, index, targetCellPosition, selectionRect) => {
20
32
  const addOptions = direction === 'row' ? [{
21
33
  label: 'above',
22
34
  offset: 0,
@@ -95,8 +107,21 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, t
95
107
  })), direction === 'column' ? {
96
108
  id: 'distribute_columns',
97
109
  title: 'Distribute columns',
98
- disabled: true,
99
- onClick: () => {
110
+ disabled: !isDistributeColumnsEnabled(editorView.state),
111
+ onClick: (state, dispatch) => {
112
+ const selectionRect = getClosestSelectionRect(state);
113
+ if (selectionRect) {
114
+ const newResizeState = getNewResizeStateFromSelectedColumns(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
115
+ if (newResizeState) {
116
+ const {
117
+ resizeState,
118
+ table
119
+ } = newResizeState;
120
+ distributeColumnsWidths(resizeState, table)(state, dispatch);
121
+ return true;
122
+ }
123
+ return false;
124
+ }
100
125
  return false;
101
126
  },
102
127
  icon: EditorLayoutThreeEqualIcon
@@ -76,7 +76,7 @@ export var DragMenu = function DragMenu(_ref) {
76
76
  var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
77
77
  var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
78
78
  var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
79
- var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
79
+ var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, editorView, tableMap, index, targetCellPosition, selectionRect);
80
80
  var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
81
81
  menuItems = _convertToDropdownIte.menuItems,
82
82
  menuCallback = _convertToDropdownIte.menuCallback;
@@ -13,8 +13,12 @@ import HipchatChevronDoubleUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-dou
13
13
  import { clearMultipleCells, insertColumn, insertRow, sortByColumn } from '../commands';
14
14
  import { deleteColumnsCommand } from '../commands/delete';
15
15
  import { moveSource } from '../pm-plugins/drag-and-drop/commands';
16
+ import { distributeColumnsWidths } from '../pm-plugins/table-resizing/commands';
17
+ import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizing/utils/resize-state';
18
+ import { getClosestSelectionRect } from '../toolbar';
16
19
  import { deleteRows } from '../transforms';
17
20
  import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
21
+ import { getSelectedColumnIndexes } from './index';
18
22
  var canDecrease = function canDecrease(index) {
19
23
  var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
20
24
  return index !== undefined && index > min;
@@ -23,7 +27,15 @@ var canIncrease = function canIncrease(index) {
23
27
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
24
28
  return index !== undefined && index < max;
25
29
  };
26
- export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, tableMap, index, targetCellPosition, selectionRect) {
30
+ var isDistributeColumnsEnabled = function isDistributeColumnsEnabled(state) {
31
+ var rect = getClosestSelectionRect(state);
32
+ if (rect) {
33
+ var selectedColIndexes = getSelectedColumnIndexes(rect);
34
+ return selectedColIndexes.length > 1;
35
+ }
36
+ return false;
37
+ };
38
+ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorContainerWidth, canDrag, editorView, tableMap, index, targetCellPosition, selectionRect) {
27
39
  var addOptions = direction === 'row' ? [{
28
40
  label: 'above',
29
41
  offset: 0,
@@ -107,8 +119,19 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
107
119
  })), [direction === 'column' ? {
108
120
  id: 'distribute_columns',
109
121
  title: 'Distribute columns',
110
- disabled: true,
111
- onClick: function onClick() {
122
+ disabled: !isDistributeColumnsEnabled(editorView.state),
123
+ onClick: function onClick(state, dispatch) {
124
+ var selectionRect = getClosestSelectionRect(state);
125
+ if (selectionRect) {
126
+ var newResizeState = getNewResizeStateFromSelectedColumns(selectionRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
127
+ if (newResizeState) {
128
+ var resizeState = newResizeState.resizeState,
129
+ table = newResizeState.table;
130
+ distributeColumnsWidths(resizeState, table)(state, dispatch);
131
+ return true;
132
+ }
133
+ return false;
134
+ }
112
135
  return false;
113
136
  },
114
137
  icon: EditorLayoutThreeEqualIcon
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { Command, DropdownOptionT, GetEditorContainerWidth, IconProps } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
4
  import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
4
5
  import type { TableDirection } from '../types';
5
6
  export interface DragMenuConfig extends DropdownOptionT<Command> {
@@ -7,4 +8,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
7
8
  icon?: React.ComponentType<IconProps>;
8
9
  keymap?: string;
9
10
  }
10
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
11
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, editorView: EditorView, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { Command, DropdownOptionT, GetEditorContainerWidth, IconProps } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
4
  import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
4
5
  import type { TableDirection } from '../types';
5
6
  export interface DragMenuConfig extends DropdownOptionT<Command> {
@@ -7,4 +8,4 @@ export interface DragMenuConfig extends DropdownOptionT<Command> {
7
8
  icon?: React.ComponentType<IconProps>;
8
9
  keymap?: string;
9
10
  }
10
- export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, tableMap?: TableMap, index?: number, targetCellPosition?: number, selectionRect?: Rect) => DragMenuConfig[];
11
+ export declare const getDragMenuConfig: (direction: TableDirection, getEditorContainerWidth: GetEditorContainerWidth, canDrag: boolean, editorView: EditorView, 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.5.7",
3
+ "version": "5.5.8",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -44,7 +44,7 @@
44
44
  "@atlaskit/pragmatic-drag-and-drop": "^0.25.0",
45
45
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.8.0",
46
46
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
47
- "@atlaskit/primitives": "^1.13.0",
47
+ "@atlaskit/primitives": "^1.14.0",
48
48
  "@atlaskit/theme": "^12.6.0",
49
49
  "@atlaskit/tokens": "^1.29.0",
50
50
  "@atlaskit/tooltip": "^18.0.0",
@@ -140,6 +140,7 @@ export const DragMenu = ({
140
140
  direction,
141
141
  getEditorContainerWidth,
142
142
  !!canDrag && !shouldMoveDisabled,
143
+ editorView,
143
144
  tableMap,
144
145
  index,
145
146
  targetCellPosition,
@@ -15,6 +15,7 @@ import type {
15
15
  IconProps,
16
16
  } from '@atlaskit/editor-common/types';
17
17
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
18
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
18
19
  import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
19
20
  import ArrowDownIcon from '@atlaskit/icon/glyph/arrow-down';
20
21
  import ArrowLeftIcon from '@atlaskit/icon/glyph/arrow-left';
@@ -34,6 +35,9 @@ import {
34
35
  } from '../commands';
35
36
  import { deleteColumnsCommand } from '../commands/delete';
36
37
  import { moveSource } from '../pm-plugins/drag-and-drop/commands';
38
+ import { distributeColumnsWidths } from '../pm-plugins/table-resizing/commands';
39
+ import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizing/utils/resize-state';
40
+ import { getClosestSelectionRect } from '../toolbar';
37
41
  import { deleteRows } from '../transforms';
38
42
  import type { TableDirection } from '../types';
39
43
  import {
@@ -43,11 +47,22 @@ import {
43
47
  AddRowBelowIcon,
44
48
  } from '../ui/icons';
45
49
 
50
+ import { getSelectedColumnIndexes } from './index';
51
+
46
52
  const canDecrease = (index?: number, min: number = 0) =>
47
53
  index !== undefined && index > min;
48
54
  const canIncrease = (index?: number, max: number = 0) =>
49
55
  index !== undefined && index < max;
50
56
 
57
+ const isDistributeColumnsEnabled = (state: EditorState) => {
58
+ const rect = getClosestSelectionRect(state);
59
+ if (rect) {
60
+ const selectedColIndexes = getSelectedColumnIndexes(rect);
61
+ return selectedColIndexes.length > 1;
62
+ }
63
+ return false;
64
+ };
65
+
51
66
  export interface DragMenuConfig extends DropdownOptionT<Command> {
52
67
  id: string;
53
68
  icon?: React.ComponentType<IconProps>;
@@ -58,6 +73,7 @@ export const getDragMenuConfig = (
58
73
  direction: TableDirection,
59
74
  getEditorContainerWidth: GetEditorContainerWidth,
60
75
  canDrag: boolean,
76
+ editorView: EditorView,
61
77
  tableMap?: TableMap,
62
78
  index?: number,
63
79
  targetCellPosition?: number,
@@ -163,8 +179,24 @@ export const getDragMenuConfig = (
163
179
  ? {
164
180
  id: 'distribute_columns',
165
181
  title: 'Distribute columns',
166
- disabled: true,
167
- onClick: () => {
182
+ disabled: !isDistributeColumnsEnabled(editorView.state),
183
+ onClick: (state: EditorState, dispatch?: CommandDispatch) => {
184
+ const selectionRect = getClosestSelectionRect(state);
185
+ if (selectionRect) {
186
+ const newResizeState = getNewResizeStateFromSelectedColumns(
187
+ selectionRect,
188
+ state,
189
+ editorView.domAtPos.bind(editorView),
190
+ getEditorContainerWidth,
191
+ );
192
+
193
+ if (newResizeState) {
194
+ const { resizeState, table } = newResizeState;
195
+ distributeColumnsWidths(resizeState, table)(state, dispatch);
196
+ return true;
197
+ }
198
+ return false;
199
+ }
168
200
  return false;
169
201
  },
170
202
  icon: EditorLayoutThreeEqualIcon,