@atlaskit/editor-plugin-table 5.8.3 → 5.8.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 (30) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugin.js +2 -2
  3. package/dist/cjs/ui/DragHandle/index.js +8 -3
  4. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  5. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +103 -12
  6. package/dist/cjs/ui/FloatingDragMenu/index.js +2 -2
  7. package/dist/es2019/plugin.js +2 -2
  8. package/dist/es2019/ui/DragHandle/index.js +10 -3
  9. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  10. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +106 -11
  11. package/dist/es2019/ui/FloatingDragMenu/index.js +1 -1
  12. package/dist/esm/plugin.js +2 -2
  13. package/dist/esm/ui/DragHandle/index.js +8 -3
  14. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  15. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +102 -11
  16. package/dist/esm/ui/FloatingDragMenu/index.js +1 -1
  17. package/dist/types/ui/DragHandle/index.d.ts +5 -1
  18. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -2
  19. package/dist/types/utils/drag-menu.d.ts +2 -1
  20. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +5 -1
  21. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -2
  22. package/dist/types-ts4.5/utils/drag-menu.d.ts +2 -1
  23. package/package.json +2 -2
  24. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +129 -105
  25. package/src/plugin.tsx +1 -1
  26. package/src/ui/DragHandle/index.tsx +13 -2
  27. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +2 -2
  28. package/src/ui/FloatingDragMenu/DragMenu.tsx +137 -12
  29. package/src/ui/FloatingDragMenu/index.tsx +1 -1
  30. package/src/utils/drag-menu.ts +17 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.8.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#67238](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/67238) [`40533849b2ec`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/40533849b2ec) - [ED-21835] Change EditorAPI type to always union with undefined
8
+
9
+ ## 5.8.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#67113](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/67113) [`7160ae19d9e5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7160ae19d9e5) - [ux] Adds localisation for table drag handle menu options
14
+ - [#66456](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66456) [`f67ea3106bb9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f67ea3106bb9) - Add support for i18n for drag handles
15
+
3
16
  ## 5.8.3
4
17
 
5
18
  ### Patch Changes
@@ -57,11 +57,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
57
57
  current: null
58
58
  };
59
59
  var defaultGetEditorContainerWidth = function defaultGetEditorContainerWidth() {
60
- var _document$body$offset, _document, _api$width$sharedStat;
60
+ var _document$body$offset, _document, _api$width$sharedStat, _api$width;
61
61
  var defaultState = {
62
62
  width: (_document$body$offset = (_document = document) === null || _document === void 0 || (_document = _document.body) === null || _document === void 0 ? void 0 : _document.offsetWidth) !== null && _document$body$offset !== void 0 ? _document$body$offset : 500
63
63
  };
64
- return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : api.width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
64
+ return (_api$width$sharedStat = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
65
65
  };
66
66
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
67
67
  return {
@@ -11,6 +11,8 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _classnames2 = _interopRequireDefault(require("classnames"));
13
13
  var _reactDom = _interopRequireDefault(require("react-dom"));
14
+ var _reactIntlNext = require("react-intl-next");
15
+ var _messages = require("@atlaskit/editor-common/messages");
14
16
  var _utils = require("@atlaskit/editor-common/utils");
15
17
  var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
16
18
  var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview");
@@ -21,7 +23,7 @@ var _DragPreview = require("../DragPreview");
21
23
  var _HandleIconComponent = require("./HandleIconComponent");
22
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
- var DragHandle = exports.DragHandle = function DragHandle(_ref) {
26
+ var DragHandleComponent = function DragHandleComponent(_ref) {
25
27
  var isDragMenuTarget = _ref.isDragMenuTarget,
26
28
  tableLocalId = _ref.tableLocalId,
27
29
  _ref$direction = _ref.direction,
@@ -39,7 +41,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
39
41
  onClick = _ref.onClick,
40
42
  editorView = _ref.editorView,
41
43
  _ref$canDrag = _ref.canDrag,
42
- _canDrag = _ref$canDrag === void 0 ? false : _ref$canDrag;
44
+ _canDrag = _ref$canDrag === void 0 ? false : _ref$canDrag,
45
+ formatMessage = _ref.intl.formatMessage;
43
46
  var dragHandleDivRef = (0, _react.useRef)(null);
44
47
  var _useState = (0, _react.useState)(null),
45
48
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -124,6 +127,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
124
127
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
125
128
  },
126
129
  "data-testid": "table-drag-handle-button",
130
+ "aria-label": formatMessage(direction === 'row' ? _messages.tableMessages.rowDragHandle : _messages.tableMessages.columnDragHandle),
127
131
  onMouseOver: onMouseOver,
128
132
  onMouseOut: onMouseOut,
129
133
  onMouseUp: function onMouseUp(e) {
@@ -142,4 +146,5 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
142
146
  width: previewWidth,
143
147
  height: previewHeight
144
148
  }), previewContainer));
145
- };
149
+ };
150
+ var DragHandle = exports.DragHandle = (0, _reactIntlNext.injectIntl)(DragHandleComponent);
@@ -148,7 +148,7 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
148
148
  var _getPluginState3 = (0, _pluginFactory.getPluginState)(editorView.state),
149
149
  isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled;
150
150
  return {
151
- content: formatMessage(isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? _messages.tableMessages.addColumn : _messages.tableMessages.insertColumn),
151
+ content: formatMessage(isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? _messages.tableMessages.addColumnRight : _messages.tableMessages.insertColumn),
152
152
  value: {
153
153
  name: 'insert_column'
154
154
  },
@@ -165,7 +165,7 @@ var ContextualMenu = exports.ContextualMenu = /*#__PURE__*/function (_Component)
165
165
  var _getPluginState4 = (0, _pluginFactory.getPluginState)(editorView.state),
166
166
  isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled;
167
167
  return {
168
- content: formatMessage(isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? _messages.tableMessages.addRow : _messages.tableMessages.insertRow),
168
+ content: formatMessage(isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? _messages.tableMessages.addRowBelow : _messages.tableMessages.insertRow),
169
169
  value: {
170
170
  name: 'insert_row'
171
171
  },
@@ -4,12 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.DragMenu = void 0;
7
+ exports.default = exports.DragMenu = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _react = require("react");
11
11
  var _react2 = require("@emotion/react");
12
+ var _reactIntlNext = require("react-intl-next");
12
13
  var _analytics = require("@atlaskit/editor-common/analytics");
14
+ var _messages = require("@atlaskit/editor-common/messages");
13
15
  var _styles = require("@atlaskit/editor-common/styles");
14
16
  var _uiColor = require("@atlaskit/editor-common/ui-color");
15
17
  var _uiMenu = require("@atlaskit/editor-common/ui-menu");
@@ -34,22 +36,109 @@ var _styles2 = require("./styles");
34
36
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
35
37
  /** @jsx jsx */
36
38
 
39
+ var MapDragMenuOptionIdToMessage = {
40
+ add_row_above: {
41
+ message: _messages.tableMessages.addRowAbove,
42
+ plural: null
43
+ },
44
+ add_row_below: {
45
+ message: _messages.tableMessages.addRowBelow,
46
+ plural: null
47
+ },
48
+ add_column_left: {
49
+ message: _messages.tableMessages.addColumnLeft,
50
+ plural: null
51
+ },
52
+ add_column_right: {
53
+ message: _messages.tableMessages.addColumnRight,
54
+ plural: null
55
+ },
56
+ distribute_columns: {
57
+ message: _messages.tableMessages.distributeColumns,
58
+ plural: 'noOfCols'
59
+ },
60
+ clear_cells: {
61
+ message: _messages.tableMessages.clearCells,
62
+ plural: 'noOfCells'
63
+ },
64
+ delete_row: {
65
+ message: _messages.tableMessages.removeRows,
66
+ plural: 'noOfRows'
67
+ },
68
+ delete_column: {
69
+ message: _messages.tableMessages.removeColumns,
70
+ plural: 'noOfCols'
71
+ },
72
+ move_column_left: {
73
+ message: _messages.tableMessages.moveColumnLeft,
74
+ plural: 'noOfCols'
75
+ },
76
+ move_column_right: {
77
+ message: _messages.tableMessages.moveColumnRight,
78
+ plural: 'noOfCols'
79
+ },
80
+ move_row_up: {
81
+ message: _messages.tableMessages.moveRowUp,
82
+ plural: 'noOfRows'
83
+ },
84
+ move_row_down: {
85
+ message: _messages.tableMessages.moveRowDown,
86
+ plural: 'noOfRows'
87
+ },
88
+ sort_column_asc: {
89
+ message: _messages.tableMessages.sortColumnIncreasing,
90
+ plural: null
91
+ },
92
+ sort_column_desc: {
93
+ message: _messages.tableMessages.sortColumnDecreasing,
94
+ plural: null
95
+ }
96
+ };
37
97
  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']];
38
- var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig) {
98
+ var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect) {
39
99
  var menuItemsArr = (0, _toConsumableArray2.default)(Array(groupedDragMenuConfig.length)).map(function () {
40
100
  return [];
41
101
  });
42
102
  var menuCallback = {};
43
103
  dragMenuConfig.forEach(function (item) {
104
+ var _MapDragMenuOptionIdT;
44
105
  var menuGroupIndex = groupedDragMenuConfig.findIndex(function (group) {
45
106
  return group.includes(item.id);
46
107
  });
47
108
  if (menuGroupIndex === -1) {
48
109
  return;
49
110
  }
111
+ var isPlural = Boolean((_MapDragMenuOptionIdT = MapDragMenuOptionIdToMessage[item.id]) === null || _MapDragMenuOptionIdT === void 0 ? void 0 : _MapDragMenuOptionIdT.plural);
112
+ var plural = 0;
113
+ if (isPlural && selectionRect) {
114
+ var top = selectionRect.top,
115
+ bottom = selectionRect.bottom,
116
+ right = selectionRect.right,
117
+ left = selectionRect.left;
118
+ switch (MapDragMenuOptionIdToMessage[item.id].plural) {
119
+ case 'noOfCols':
120
+ {
121
+ plural = right - left;
122
+ break;
123
+ }
124
+ case 'noOfRows':
125
+ {
126
+ plural = bottom - top;
127
+ break;
128
+ }
129
+ case 'noOfCells':
130
+ {
131
+ plural = Math.max(right - left, bottom - top);
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ var options = isPlural ? {
137
+ 0: plural
138
+ } : undefined;
50
139
  menuItemsArr[menuGroupIndex].push({
51
140
  key: item.id,
52
- content: item.title,
141
+ content: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options),
53
142
  value: {
54
143
  name: item.id
55
144
  },
@@ -59,7 +148,7 @@ var convertToDropdownItems = function convertToDropdownItems(dragMenuConfig) {
59
148
  display: 'flex'
60
149
  }
61
150
  }, (0, _react2.jsx)(item.icon, {
62
- label: item.title
151
+ label: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options)
63
152
  })) : undefined,
64
153
  elemAfter: item.keymap ? (0, _react2.jsx)("div", {
65
154
  css: _shortcut.shortcutStyle
@@ -93,7 +182,8 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
93
182
  getEditorContainerWidth = _ref.getEditorContainerWidth,
94
183
  canDrag = _ref.canDrag,
95
184
  editorAnalyticsAPI = _ref.editorAnalyticsAPI,
96
- pluginConfig = _ref.pluginConfig;
185
+ pluginConfig = _ref.pluginConfig,
186
+ formatMessage = _ref.intl.formatMessage;
97
187
  var state = editorView.state,
98
188
  dispatch = editorView.dispatch;
99
189
  var selection = state.selection;
@@ -108,7 +198,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
108
198
  var hasMergedCellsInTable = (0, _utils3.getMergedCellsPositions)(state.tr).length > 0;
109
199
  var allowBackgroundColor = (_pluginConfig$allowBa = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.allowBackgroundColor) !== null && _pluginConfig$allowBa !== void 0 ? _pluginConfig$allowBa : false;
110
200
  var dragMenuConfig = (0, _dragMenu.getDragMenuConfig)(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, hasMergedCellsInTable, editorView, tableMap, index, targetCellPosition, selectionRect, editorAnalyticsAPI);
111
- var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
201
+ var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect),
112
202
  menuItems = _convertToDropdownIte.menuItems,
113
203
  menuCallback = _convertToDropdownIte.menuCallback;
114
204
  var handleSubMenuRef = function handleSubMenuRef(ref) {
@@ -138,12 +228,12 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
138
228
  var node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
139
229
  var background = (0, _editorPalette.hexToEditorBackgroundPaletteColor)((node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
140
230
  return {
141
- content: 'Background color',
231
+ content: formatMessage(_messages.tableMessages.backgroundColor),
142
232
  value: {
143
233
  name: 'background'
144
234
  },
145
235
  elemBefore: (0, _react2.jsx)(_backgroundColor.default, {
146
- label: 'background color',
236
+ label: formatMessage(_messages.tableMessages.backgroundColor),
147
237
  size: "medium"
148
238
  }),
149
239
  elemAfter: (0, _react2.jsx)("div", {
@@ -178,7 +268,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
178
268
  };
179
269
  var createhHeaderRowColumnMenuItem = function createhHeaderRowColumnMenuItem(direction) {
180
270
  return direction === 'column' ? {
181
- content: 'Header column',
271
+ content: formatMessage(_messages.tableMessages.headerColumn),
182
272
  value: {
183
273
  name: 'header_column'
184
274
  },
@@ -190,7 +280,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
190
280
  isChecked: (0, _utils3.checkIfHeaderColumnEnabled)(selection)
191
281
  }))
192
282
  } : {
193
- content: 'Header row',
283
+ content: formatMessage(_messages.tableMessages.headerRow),
194
284
  value: {
195
285
  name: 'header_row'
196
286
  },
@@ -205,7 +295,7 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
205
295
  };
206
296
  var createRowNumbersMenuItem = function createRowNumbersMenuItem() {
207
297
  return {
208
- content: 'Row numbers',
298
+ content: formatMessage(_messages.tableMessages.rowNumbers),
209
299
  value: {
210
300
  name: 'row_numbers'
211
301
  },
@@ -333,4 +423,5 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
333
423
  hasSeparator: true
334
424
  }
335
425
  });
336
- };
426
+ };
427
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(DragMenu);
@@ -10,7 +10,7 @@ var _ui = require("@atlaskit/editor-common/ui");
10
10
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
11
11
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
12
12
  var _consts = require("../consts");
13
- var _DragMenu = require("./DragMenu");
13
+ var _DragMenu = _interopRequireDefault(require("./DragMenu"));
14
14
  var FloatingDragMenu = function FloatingDragMenu(_ref) {
15
15
  var mountPoint = _ref.mountPoint,
16
16
  boundariesElement = _ref.boundariesElement,
@@ -53,7 +53,7 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
53
53
  forcePlacement: true,
54
54
  offset: offset,
55
55
  stick: true
56
- }, /*#__PURE__*/_react.default.createElement(_DragMenu.DragMenu, {
56
+ }, /*#__PURE__*/_react.default.createElement(_DragMenu.default, {
57
57
  editorView: editorView,
58
58
  isOpen: isOpen,
59
59
  boundariesElement: boundariesElement,
@@ -49,11 +49,11 @@ const tablesPlugin = ({
49
49
  current: null
50
50
  };
51
51
  const defaultGetEditorContainerWidth = () => {
52
- var _document$body$offset, _document, _document$body, _api$width$sharedStat;
52
+ var _document$body$offset, _document, _document$body, _api$width$sharedStat, _api$width;
53
53
  const defaultState = {
54
54
  width: (_document$body$offset = (_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.offsetWidth) !== null && _document$body$offset !== void 0 ? _document$body$offset : 500
55
55
  };
56
- return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : api.width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
56
+ return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
57
57
  };
58
58
  const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
59
59
  return {
@@ -1,6 +1,8 @@
1
1
  import React, { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import classnames from 'classnames';
3
3
  import ReactDOM from 'react-dom';
4
+ import { injectIntl } from 'react-intl-next';
5
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
6
  import { browser } from '@atlaskit/editor-common/utils';
5
7
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
8
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
@@ -9,7 +11,7 @@ import { TableCssClassName as ClassName } from '../../types';
9
11
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
10
12
  import { DragPreview } from '../DragPreview';
11
13
  import { HandleIconComponent } from './HandleIconComponent';
12
- export const DragHandle = ({
14
+ const DragHandleComponent = ({
13
15
  isDragMenuTarget,
14
16
  tableLocalId,
15
17
  direction = 'row',
@@ -23,7 +25,10 @@ export const DragHandle = ({
23
25
  onMouseUp,
24
26
  onClick,
25
27
  editorView,
26
- canDrag = false
28
+ canDrag = false,
29
+ intl: {
30
+ formatMessage
31
+ }
27
32
  }) => {
28
33
  const dragHandleDivRef = useRef(null);
29
34
  const [previewContainer, setPreviewContainer] = useState(null);
@@ -110,6 +115,7 @@ export const DragHandle = ({
110
115
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
111
116
  },
112
117
  "data-testid": "table-drag-handle-button",
118
+ "aria-label": formatMessage(direction === 'row' ? messages.rowDragHandle : messages.columnDragHandle),
113
119
  onMouseOver: onMouseOver,
114
120
  onMouseOut: onMouseOut,
115
121
  onMouseUp: e => {
@@ -128,4 +134,5 @@ export const DragHandle = ({
128
134
  width: previewWidth,
129
135
  height: previewHeight
130
136
  }), previewContainer));
131
- };
137
+ };
138
+ export const DragHandle = injectIntl(DragHandleComponent);
@@ -143,7 +143,7 @@ export class ContextualMenu extends Component {
143
143
  isDragAndDropEnabled
144
144
  } = getPluginState(editorView.state);
145
145
  return {
146
- content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addColumn : messages.insertColumn),
146
+ content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addColumnRight : messages.insertColumn),
147
147
  value: {
148
148
  name: 'insert_column'
149
149
  },
@@ -164,7 +164,7 @@ export class ContextualMenu extends Component {
164
164
  isDragAndDropEnabled
165
165
  } = getPluginState(editorView.state);
166
166
  return {
167
- content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addRow : messages.insertRow),
167
+ content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addRowBelow : messages.insertRow),
168
168
  value: {
169
169
  name: 'insert_row'
170
170
  },
@@ -2,7 +2,9 @@
2
2
  /** @jsx jsx */
3
3
  import { useState } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
+ import { injectIntl } from 'react-intl-next';
5
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
8
  import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
7
9
  import { backgroundPaletteTooltipMessages, cellBackgroundColorPalette, ColorPalette } from '@atlaskit/editor-common/ui-color';
8
10
  import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
@@ -24,18 +26,107 @@ import { checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColum
24
26
  import { getDragMenuConfig } from '../../utils/drag-menu';
25
27
  import { dragMenuDropdownWidth } from '../consts';
26
28
  import { cellColourPreviewStyles, dragMenuBackgroundColorStyles, toggleStyles } from './styles';
29
+ const MapDragMenuOptionIdToMessage = {
30
+ add_row_above: {
31
+ message: messages.addRowAbove,
32
+ plural: null
33
+ },
34
+ add_row_below: {
35
+ message: messages.addRowBelow,
36
+ plural: null
37
+ },
38
+ add_column_left: {
39
+ message: messages.addColumnLeft,
40
+ plural: null
41
+ },
42
+ add_column_right: {
43
+ message: messages.addColumnRight,
44
+ plural: null
45
+ },
46
+ distribute_columns: {
47
+ message: messages.distributeColumns,
48
+ plural: 'noOfCols'
49
+ },
50
+ clear_cells: {
51
+ message: messages.clearCells,
52
+ plural: 'noOfCells'
53
+ },
54
+ delete_row: {
55
+ message: messages.removeRows,
56
+ plural: 'noOfRows'
57
+ },
58
+ delete_column: {
59
+ message: messages.removeColumns,
60
+ plural: 'noOfCols'
61
+ },
62
+ move_column_left: {
63
+ message: messages.moveColumnLeft,
64
+ plural: 'noOfCols'
65
+ },
66
+ move_column_right: {
67
+ message: messages.moveColumnRight,
68
+ plural: 'noOfCols'
69
+ },
70
+ move_row_up: {
71
+ message: messages.moveRowUp,
72
+ plural: 'noOfRows'
73
+ },
74
+ move_row_down: {
75
+ message: messages.moveRowDown,
76
+ plural: 'noOfRows'
77
+ },
78
+ sort_column_asc: {
79
+ message: messages.sortColumnIncreasing,
80
+ plural: null
81
+ },
82
+ sort_column_desc: {
83
+ message: messages.sortColumnDecreasing,
84
+ plural: null
85
+ }
86
+ };
27
87
  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']];
28
- const convertToDropdownItems = dragMenuConfig => {
88
+ const convertToDropdownItems = (dragMenuConfig, formatMessage, selectionRect) => {
29
89
  let menuItemsArr = [...Array(groupedDragMenuConfig.length)].map(() => []);
30
90
  let menuCallback = {};
31
91
  dragMenuConfig.forEach(item => {
92
+ var _MapDragMenuOptionIdT;
32
93
  const menuGroupIndex = groupedDragMenuConfig.findIndex(group => group.includes(item.id));
33
94
  if (menuGroupIndex === -1) {
34
95
  return;
35
96
  }
97
+ const isPlural = Boolean((_MapDragMenuOptionIdT = MapDragMenuOptionIdToMessage[item.id]) === null || _MapDragMenuOptionIdT === void 0 ? void 0 : _MapDragMenuOptionIdT.plural);
98
+ let plural = 0;
99
+ if (isPlural && selectionRect) {
100
+ const {
101
+ top,
102
+ bottom,
103
+ right,
104
+ left
105
+ } = selectionRect;
106
+ switch (MapDragMenuOptionIdToMessage[item.id].plural) {
107
+ case 'noOfCols':
108
+ {
109
+ plural = right - left;
110
+ break;
111
+ }
112
+ case 'noOfRows':
113
+ {
114
+ plural = bottom - top;
115
+ break;
116
+ }
117
+ case 'noOfCells':
118
+ {
119
+ plural = Math.max(right - left, bottom - top);
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ const options = isPlural ? {
125
+ 0: plural
126
+ } : undefined;
36
127
  menuItemsArr[menuGroupIndex].push({
37
128
  key: item.id,
38
- content: item.title,
129
+ content: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options),
39
130
  value: {
40
131
  name: item.id
41
132
  },
@@ -45,7 +136,7 @@ const convertToDropdownItems = dragMenuConfig => {
45
136
  display: 'flex'
46
137
  }
47
138
  }, jsx(item.icon, {
48
- label: item.title
139
+ label: formatMessage(MapDragMenuOptionIdToMessage[item.id].message, options)
49
140
  })) : undefined,
50
141
  elemAfter: item.keymap ? jsx("div", {
51
142
  css: shortcutStyle
@@ -77,7 +168,10 @@ export const DragMenu = ({
77
168
  getEditorContainerWidth,
78
169
  canDrag,
79
170
  editorAnalyticsAPI,
80
- pluginConfig
171
+ pluginConfig,
172
+ intl: {
173
+ formatMessage
174
+ }
81
175
  }) => {
82
176
  var _pluginConfig$allowBa;
83
177
  const {
@@ -98,7 +192,7 @@ export const DragMenu = ({
98
192
  const {
99
193
  menuItems,
100
194
  menuCallback
101
- } = convertToDropdownItems(dragMenuConfig);
195
+ } = convertToDropdownItems(dragMenuConfig, formatMessage, selectionRect);
102
196
  const handleSubMenuRef = ref => {
103
197
  const parent = closestElement(editorView.dom, '.fabric-editor-popup-scroll-parent');
104
198
  if (!(parent && ref)) {
@@ -130,12 +224,12 @@ export const DragMenu = ({
130
224
  const node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
131
225
  const background = hexToEditorBackgroundPaletteColor((node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
132
226
  return {
133
- content: 'Background color',
227
+ content: formatMessage(messages.backgroundColor),
134
228
  value: {
135
229
  name: 'background'
136
230
  },
137
231
  elemBefore: jsx(EditorBackgroundColorIcon, {
138
- label: 'background color',
232
+ label: formatMessage(messages.backgroundColor),
139
233
  size: "medium"
140
234
  }),
141
235
  elemAfter: jsx("div", {
@@ -170,7 +264,7 @@ export const DragMenu = ({
170
264
  };
171
265
  const createhHeaderRowColumnMenuItem = direction => {
172
266
  return direction === 'column' ? {
173
- content: 'Header column',
267
+ content: formatMessage(messages.headerColumn),
174
268
  value: {
175
269
  name: 'header_column'
176
270
  },
@@ -182,7 +276,7 @@ export const DragMenu = ({
182
276
  isChecked: checkIfHeaderColumnEnabled(selection)
183
277
  }))
184
278
  } : {
185
- content: 'Header row',
279
+ content: formatMessage(messages.headerRow),
186
280
  value: {
187
281
  name: 'header_row'
188
282
  },
@@ -197,7 +291,7 @@ export const DragMenu = ({
197
291
  };
198
292
  const createRowNumbersMenuItem = () => {
199
293
  return {
200
- content: 'Row numbers',
294
+ content: formatMessage(messages.rowNumbers),
201
295
  value: {
202
296
  name: 'row_numbers'
203
297
  },
@@ -331,4 +425,5 @@ export const DragMenu = ({
331
425
  hasSeparator: true
332
426
  }
333
427
  });
334
- };
428
+ };
429
+ export default injectIntl(DragMenu);
@@ -3,7 +3,7 @@ import { Popup } from '@atlaskit/editor-common/ui';
3
3
  import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
5
  import { dragMenuDropdownWidth } from '../consts';
6
- import { DragMenu } from './DragMenu';
6
+ import DragMenu from './DragMenu';
7
7
  const FloatingDragMenu = ({
8
8
  mountPoint,
9
9
  boundariesElement,
@@ -50,11 +50,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
50
50
  current: null
51
51
  };
52
52
  var defaultGetEditorContainerWidth = function defaultGetEditorContainerWidth() {
53
- var _document$body$offset, _document, _api$width$sharedStat;
53
+ var _document$body$offset, _document, _api$width$sharedStat, _api$width;
54
54
  var defaultState = {
55
55
  width: (_document$body$offset = (_document = document) === null || _document === void 0 || (_document = _document.body) === null || _document === void 0 ? void 0 : _document.offsetWidth) !== null && _document$body$offset !== void 0 ? _document$body$offset : 500
56
56
  };
57
- return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : api.width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
57
+ return (_api$width$sharedStat = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
58
58
  };
59
59
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
60
60
  return {
@@ -3,6 +3,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import React, { useEffect, useMemo, useRef, useState } from 'react';
4
4
  import classnames from 'classnames';
5
5
  import ReactDOM from 'react-dom';
6
+ import { injectIntl } from 'react-intl-next';
7
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
8
  import { browser } from '@atlaskit/editor-common/utils';
7
9
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
8
10
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
@@ -11,7 +13,7 @@ import { TableCssClassName as ClassName } from '../../types';
11
13
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
12
14
  import { DragPreview } from '../DragPreview';
13
15
  import { HandleIconComponent } from './HandleIconComponent';
14
- export var DragHandle = function DragHandle(_ref) {
16
+ var DragHandleComponent = function DragHandleComponent(_ref) {
15
17
  var isDragMenuTarget = _ref.isDragMenuTarget,
16
18
  tableLocalId = _ref.tableLocalId,
17
19
  _ref$direction = _ref.direction,
@@ -29,7 +31,8 @@ export var DragHandle = function DragHandle(_ref) {
29
31
  onClick = _ref.onClick,
30
32
  editorView = _ref.editorView,
31
33
  _ref$canDrag = _ref.canDrag,
32
- _canDrag = _ref$canDrag === void 0 ? false : _ref$canDrag;
34
+ _canDrag = _ref$canDrag === void 0 ? false : _ref$canDrag,
35
+ formatMessage = _ref.intl.formatMessage;
33
36
  var dragHandleDivRef = useRef(null);
34
37
  var _useState = useState(null),
35
38
  _useState2 = _slicedToArray(_useState, 2),
@@ -114,6 +117,7 @@ export var DragHandle = function DragHandle(_ref) {
114
117
  transform: direction === 'column' ? 'none' : 'rotate(90deg)'
115
118
  },
116
119
  "data-testid": "table-drag-handle-button",
120
+ "aria-label": formatMessage(direction === 'row' ? messages.rowDragHandle : messages.columnDragHandle),
117
121
  onMouseOver: onMouseOver,
118
122
  onMouseOut: onMouseOut,
119
123
  onMouseUp: function onMouseUp(e) {
@@ -132,4 +136,5 @@ export var DragHandle = function DragHandle(_ref) {
132
136
  width: previewWidth,
133
137
  height: previewHeight
134
138
  }), previewContainer));
135
- };
139
+ };
140
+ export var DragHandle = injectIntl(DragHandleComponent);