@atlaskit/editor-plugin-table 5.8.3 → 5.8.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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/ui/DragHandle/index.js +8 -3
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +103 -12
- package/dist/cjs/ui/FloatingDragMenu/index.js +2 -2
- package/dist/es2019/ui/DragHandle/index.js +10 -3
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +106 -11
- package/dist/es2019/ui/FloatingDragMenu/index.js +1 -1
- package/dist/esm/ui/DragHandle/index.js +8 -3
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +102 -11
- package/dist/esm/ui/FloatingDragMenu/index.js +1 -1
- package/dist/types/ui/DragHandle/index.d.ts +5 -1
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +7 -2
- package/dist/types/utils/drag-menu.d.ts +2 -1
- package/dist/types-ts4.5/ui/DragHandle/index.d.ts +5 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +7 -2
- package/dist/types-ts4.5/utils/drag-menu.d.ts +2 -1
- package/package.json +2 -2
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +129 -105
- package/src/ui/DragHandle/index.tsx +13 -2
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +2 -2
- package/src/ui/FloatingDragMenu/DragMenu.tsx +137 -12
- package/src/ui/FloatingDragMenu/index.tsx +1 -1
- package/src/utils/drag-menu.ts +17 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.8.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
- [#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
|
|
9
|
+
|
|
3
10
|
## 5.8.3
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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.
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_DragMenu.default, {
|
|
57
57
|
editorView: editorView,
|
|
58
58
|
isOpen: isOpen,
|
|
59
59
|
boundariesElement: boundariesElement,
|
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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:
|
|
227
|
+
content: formatMessage(messages.backgroundColor),
|
|
134
228
|
value: {
|
|
135
229
|
name: 'background'
|
|
136
230
|
},
|
|
137
231
|
elemBefore: jsx(EditorBackgroundColorIcon, {
|
|
138
|
-
label:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
6
|
+
import DragMenu from './DragMenu';
|
|
7
7
|
const FloatingDragMenu = ({
|
|
8
8
|
mountPoint,
|
|
9
9
|
boundariesElement,
|
|
@@ -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
|
-
|
|
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);
|
|
@@ -143,7 +143,7 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
143
143
|
var _getPluginState3 = getPluginState(editorView.state),
|
|
144
144
|
isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled;
|
|
145
145
|
return {
|
|
146
|
-
content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.
|
|
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
|
},
|
|
@@ -160,7 +160,7 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
|
|
|
160
160
|
var _getPluginState4 = getPluginState(editorView.state),
|
|
161
161
|
isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled;
|
|
162
162
|
return {
|
|
163
|
-
content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.
|
|
163
|
+
content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addRowBelow : messages.insertRow),
|
|
164
164
|
value: {
|
|
165
165
|
name: 'insert_row'
|
|
166
166
|
},
|