@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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/plugin.js +2 -2
- 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/plugin.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/plugin.js +2 -2
- 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/plugin.tsx +1 -1
- 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
|
@@ -3,9 +3,16 @@
|
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { jsx } from '@emotion/react';
|
|
6
|
+
import type {
|
|
7
|
+
IntlShape,
|
|
8
|
+
MessageDescriptor,
|
|
9
|
+
WrappedComponentProps,
|
|
10
|
+
} from 'react-intl-next';
|
|
11
|
+
import { injectIntl } from 'react-intl-next';
|
|
6
12
|
|
|
7
13
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
8
14
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
15
|
+
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
16
|
import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
|
|
10
17
|
import type {
|
|
11
18
|
Command,
|
|
@@ -27,6 +34,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
27
34
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
28
35
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
29
36
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
37
|
+
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
30
38
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
31
39
|
import {
|
|
32
40
|
findCellRectClosestToPos,
|
|
@@ -59,7 +67,10 @@ import {
|
|
|
59
67
|
hasMergedCellsInColumn,
|
|
60
68
|
hasMergedCellsInRow,
|
|
61
69
|
} from '../../utils';
|
|
62
|
-
import type {
|
|
70
|
+
import type {
|
|
71
|
+
DragMenuConfig,
|
|
72
|
+
DragMenuOptionIdType,
|
|
73
|
+
} from '../../utils/drag-menu';
|
|
63
74
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
64
75
|
import { dragMenuDropdownWidth } from '../consts';
|
|
65
76
|
|
|
@@ -86,7 +97,73 @@ type DragMenuProps = {
|
|
|
86
97
|
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
87
98
|
};
|
|
88
99
|
|
|
89
|
-
|
|
100
|
+
type PluralOptionType = 'noOfCols' | 'noOfRows' | 'noOfCells' | null;
|
|
101
|
+
interface MessageType {
|
|
102
|
+
message: MessageDescriptor;
|
|
103
|
+
plural: PluralOptionType;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const MapDragMenuOptionIdToMessage: Record<DragMenuOptionIdType, MessageType> =
|
|
107
|
+
{
|
|
108
|
+
add_row_above: {
|
|
109
|
+
message: messages.addRowAbove,
|
|
110
|
+
plural: null,
|
|
111
|
+
},
|
|
112
|
+
add_row_below: {
|
|
113
|
+
message: messages.addRowBelow,
|
|
114
|
+
plural: null,
|
|
115
|
+
},
|
|
116
|
+
add_column_left: {
|
|
117
|
+
message: messages.addColumnLeft,
|
|
118
|
+
plural: null,
|
|
119
|
+
},
|
|
120
|
+
add_column_right: {
|
|
121
|
+
message: messages.addColumnRight,
|
|
122
|
+
plural: null,
|
|
123
|
+
},
|
|
124
|
+
distribute_columns: {
|
|
125
|
+
message: messages.distributeColumns,
|
|
126
|
+
plural: 'noOfCols',
|
|
127
|
+
},
|
|
128
|
+
clear_cells: {
|
|
129
|
+
message: messages.clearCells,
|
|
130
|
+
plural: 'noOfCells',
|
|
131
|
+
},
|
|
132
|
+
delete_row: {
|
|
133
|
+
message: messages.removeRows,
|
|
134
|
+
plural: 'noOfRows',
|
|
135
|
+
},
|
|
136
|
+
delete_column: {
|
|
137
|
+
message: messages.removeColumns,
|
|
138
|
+
plural: 'noOfCols',
|
|
139
|
+
},
|
|
140
|
+
move_column_left: {
|
|
141
|
+
message: messages.moveColumnLeft,
|
|
142
|
+
plural: 'noOfCols',
|
|
143
|
+
},
|
|
144
|
+
move_column_right: {
|
|
145
|
+
message: messages.moveColumnRight,
|
|
146
|
+
plural: 'noOfCols',
|
|
147
|
+
},
|
|
148
|
+
move_row_up: {
|
|
149
|
+
message: messages.moveRowUp,
|
|
150
|
+
plural: 'noOfRows',
|
|
151
|
+
},
|
|
152
|
+
move_row_down: {
|
|
153
|
+
message: messages.moveRowDown,
|
|
154
|
+
plural: 'noOfRows',
|
|
155
|
+
},
|
|
156
|
+
sort_column_asc: {
|
|
157
|
+
message: messages.sortColumnIncreasing,
|
|
158
|
+
plural: null,
|
|
159
|
+
},
|
|
160
|
+
sort_column_desc: {
|
|
161
|
+
message: messages.sortColumnDecreasing,
|
|
162
|
+
plural: null,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const groupedDragMenuConfig: DragMenuOptionIdType[][] = [
|
|
90
167
|
[
|
|
91
168
|
'add_row_above',
|
|
92
169
|
'add_row_below',
|
|
@@ -101,7 +178,11 @@ const groupedDragMenuConfig = [
|
|
|
101
178
|
['sort_column_asc', 'sort_column_desc'],
|
|
102
179
|
];
|
|
103
180
|
|
|
104
|
-
const convertToDropdownItems = (
|
|
181
|
+
const convertToDropdownItems = (
|
|
182
|
+
dragMenuConfig: DragMenuConfig[],
|
|
183
|
+
formatMessage: IntlShape['formatMessage'],
|
|
184
|
+
selectionRect?: Rect,
|
|
185
|
+
) => {
|
|
105
186
|
let menuItemsArr: MenuItem[][] = [...Array(groupedDragMenuConfig.length)].map(
|
|
106
187
|
() => [],
|
|
107
188
|
);
|
|
@@ -114,9 +195,38 @@ const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
|
|
|
114
195
|
if (menuGroupIndex === -1) {
|
|
115
196
|
return;
|
|
116
197
|
}
|
|
198
|
+
|
|
199
|
+
const isPlural = Boolean(MapDragMenuOptionIdToMessage[item.id]?.plural);
|
|
200
|
+
let plural = 0;
|
|
201
|
+
|
|
202
|
+
if (isPlural && selectionRect) {
|
|
203
|
+
const { top, bottom, right, left } = selectionRect;
|
|
204
|
+
switch (
|
|
205
|
+
MapDragMenuOptionIdToMessage[item.id].plural as PluralOptionType
|
|
206
|
+
) {
|
|
207
|
+
case 'noOfCols': {
|
|
208
|
+
plural = right - left;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case 'noOfRows': {
|
|
212
|
+
plural = bottom - top;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
case 'noOfCells': {
|
|
216
|
+
plural = Math.max(right - left, bottom - top);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const options = isPlural ? { 0: plural } : undefined;
|
|
223
|
+
|
|
117
224
|
menuItemsArr[menuGroupIndex].push({
|
|
118
225
|
key: item.id,
|
|
119
|
-
content:
|
|
226
|
+
content: formatMessage(
|
|
227
|
+
MapDragMenuOptionIdToMessage[item.id].message,
|
|
228
|
+
options,
|
|
229
|
+
),
|
|
120
230
|
value: { name: item.id },
|
|
121
231
|
isDisabled: item.disabled,
|
|
122
232
|
elemBefore: item.icon ? (
|
|
@@ -125,7 +235,12 @@ const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
|
|
|
125
235
|
display: 'flex',
|
|
126
236
|
}}
|
|
127
237
|
>
|
|
128
|
-
<item.icon
|
|
238
|
+
<item.icon
|
|
239
|
+
label={formatMessage(
|
|
240
|
+
MapDragMenuOptionIdToMessage[item.id].message,
|
|
241
|
+
options,
|
|
242
|
+
)}
|
|
243
|
+
/>
|
|
129
244
|
</div>
|
|
130
245
|
) : undefined,
|
|
131
246
|
elemAfter: item.keymap ? (
|
|
@@ -156,7 +271,8 @@ export const DragMenu = ({
|
|
|
156
271
|
canDrag,
|
|
157
272
|
editorAnalyticsAPI,
|
|
158
273
|
pluginConfig,
|
|
159
|
-
|
|
274
|
+
intl: { formatMessage },
|
|
275
|
+
}: DragMenuProps & WrappedComponentProps) => {
|
|
160
276
|
const { state, dispatch } = editorView;
|
|
161
277
|
const { selection } = state;
|
|
162
278
|
const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
@@ -188,7 +304,11 @@ export const DragMenu = ({
|
|
|
188
304
|
editorAnalyticsAPI,
|
|
189
305
|
);
|
|
190
306
|
|
|
191
|
-
const { menuItems, menuCallback } = convertToDropdownItems(
|
|
307
|
+
const { menuItems, menuCallback } = convertToDropdownItems(
|
|
308
|
+
dragMenuConfig,
|
|
309
|
+
formatMessage,
|
|
310
|
+
selectionRect,
|
|
311
|
+
);
|
|
192
312
|
|
|
193
313
|
const handleSubMenuRef = (ref: HTMLDivElement | null) => {
|
|
194
314
|
const parent = closestElement(
|
|
@@ -226,10 +346,13 @@ export const DragMenu = ({
|
|
|
226
346
|
node?.attrs?.background || '#ffffff',
|
|
227
347
|
);
|
|
228
348
|
return {
|
|
229
|
-
content:
|
|
349
|
+
content: formatMessage(messages.backgroundColor),
|
|
230
350
|
value: { name: 'background' },
|
|
231
351
|
elemBefore: (
|
|
232
|
-
<EditorBackgroundColorIcon
|
|
352
|
+
<EditorBackgroundColorIcon
|
|
353
|
+
label={formatMessage(messages.backgroundColor)}
|
|
354
|
+
size="medium"
|
|
355
|
+
/>
|
|
233
356
|
),
|
|
234
357
|
elemAfter: (
|
|
235
358
|
<div
|
|
@@ -274,7 +397,7 @@ export const DragMenu = ({
|
|
|
274
397
|
const createhHeaderRowColumnMenuItem = (direction: TableDirection) => {
|
|
275
398
|
return direction === 'column'
|
|
276
399
|
? ({
|
|
277
|
-
content:
|
|
400
|
+
content: formatMessage(messages.headerColumn),
|
|
278
401
|
value: { name: 'header_column' },
|
|
279
402
|
elemAfter: (
|
|
280
403
|
<div css={toggleStyles}>
|
|
@@ -287,7 +410,7 @@ export const DragMenu = ({
|
|
|
287
410
|
),
|
|
288
411
|
} as MenuItem)
|
|
289
412
|
: ({
|
|
290
|
-
content:
|
|
413
|
+
content: formatMessage(messages.headerRow),
|
|
291
414
|
value: { name: 'header_row' },
|
|
292
415
|
elemAfter: (
|
|
293
416
|
<div css={toggleStyles}>
|
|
@@ -303,7 +426,7 @@ export const DragMenu = ({
|
|
|
303
426
|
|
|
304
427
|
const createRowNumbersMenuItem = () => {
|
|
305
428
|
return {
|
|
306
|
-
content:
|
|
429
|
+
content: formatMessage(messages.rowNumbers),
|
|
307
430
|
value: { name: 'row_numbers' },
|
|
308
431
|
elemAfter: (
|
|
309
432
|
<div css={toggleStyles}>
|
|
@@ -464,3 +587,5 @@ export const DragMenu = ({
|
|
|
464
587
|
/>
|
|
465
588
|
);
|
|
466
589
|
};
|
|
590
|
+
|
|
591
|
+
export default injectIntl(DragMenu);
|
|
@@ -15,7 +15,7 @@ import type { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
|
15
15
|
import type { PluginConfig, TableDirection } from '../../types';
|
|
16
16
|
import { dragMenuDropdownWidth } from '../consts';
|
|
17
17
|
|
|
18
|
-
import
|
|
18
|
+
import DragMenu from './DragMenu';
|
|
19
19
|
|
|
20
20
|
export interface Props {
|
|
21
21
|
editorView: EditorView;
|
package/src/utils/drag-menu.ts
CHANGED
|
@@ -71,8 +71,24 @@ const isDistributeColumnsEnabled = (state: EditorState) => {
|
|
|
71
71
|
return false;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
+
export type DragMenuOptionIdType =
|
|
75
|
+
| 'add_row_above'
|
|
76
|
+
| 'add_row_below'
|
|
77
|
+
| 'add_column_left'
|
|
78
|
+
| 'add_column_right'
|
|
79
|
+
| 'distribute_columns'
|
|
80
|
+
| 'clear_cells'
|
|
81
|
+
| 'delete_row'
|
|
82
|
+
| 'delete_column'
|
|
83
|
+
| 'move_column_left'
|
|
84
|
+
| 'move_column_right'
|
|
85
|
+
| 'move_row_up'
|
|
86
|
+
| 'move_row_down'
|
|
87
|
+
| 'sort_column_asc'
|
|
88
|
+
| 'sort_column_desc';
|
|
89
|
+
|
|
74
90
|
export interface DragMenuConfig extends DropdownOptionT<Command> {
|
|
75
|
-
id:
|
|
91
|
+
id: DragMenuOptionIdType;
|
|
76
92
|
icon?: React.ComponentType<IconProps>;
|
|
77
93
|
keymap?: string;
|
|
78
94
|
}
|