@atlaskit/editor-plugin-table 5.3.14 → 5.3.15
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 +6 -0
- package/dist/cjs/plugins/table/index.js +2 -1
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +49 -11
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +5 -2
- package/dist/cjs/plugins/table/ui/icons/AddColLeftIcon.js +44 -0
- package/dist/cjs/plugins/table/ui/icons/AddColRightIcon.js +44 -0
- package/dist/cjs/plugins/table/ui/icons/AddRowAboveIcon.js +45 -0
- package/dist/cjs/plugins/table/ui/icons/AddRowBelowIcon.js +40 -0
- package/dist/cjs/plugins/table/ui/icons/index.js +29 -1
- package/dist/cjs/plugins/table/utils/drag-menu.js +122 -10
- package/dist/es2019/plugins/table/index.js +2 -1
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +52 -8
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +5 -2
- package/dist/es2019/plugins/table/ui/icons/AddColLeftIcon.js +35 -0
- package/dist/es2019/plugins/table/ui/icons/AddColRightIcon.js +35 -0
- package/dist/es2019/plugins/table/ui/icons/AddRowAboveIcon.js +36 -0
- package/dist/es2019/plugins/table/ui/icons/AddRowBelowIcon.js +31 -0
- package/dist/es2019/plugins/table/ui/icons/index.js +5 -1
- package/dist/es2019/plugins/table/utils/drag-menu.js +118 -8
- package/dist/esm/plugins/table/index.js +2 -1
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +46 -8
- package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +5 -2
- package/dist/esm/plugins/table/ui/icons/AddColLeftIcon.js +37 -0
- package/dist/esm/plugins/table/ui/icons/AddColRightIcon.js +37 -0
- package/dist/esm/plugins/table/ui/icons/AddRowAboveIcon.js +38 -0
- package/dist/esm/plugins/table/ui/icons/AddRowBelowIcon.js +33 -0
- package/dist/esm/plugins/table/ui/icons/index.js +5 -1
- package/dist/esm/plugins/table/utils/drag-menu.js +120 -8
- package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
- package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
- package/dist/types/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
- package/dist/types/plugins/table/ui/icons/index.d.ts +4 -0
- package/dist/types/plugins/table/utils/drag-menu.d.ts +6 -3
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
- package/dist/types-ts4.5/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +4 -0
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +6 -3
- package/package.json +1 -1
- package/src/plugins/table/index.tsx +1 -0
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +73 -6
- package/src/plugins/table/ui/FloatingDragMenu/index.tsx +5 -0
- package/src/plugins/table/ui/icons/AddColLeftIcon.tsx +43 -0
- package/src/plugins/table/ui/icons/AddColRightIcon.tsx +43 -0
- package/src/plugins/table/ui/icons/AddRowAboveIcon.tsx +42 -0
- package/src/plugins/table/ui/icons/AddRowBelowIcon.tsx +36 -0
- package/src/plugins/table/ui/icons/index.ts +4 -0
- package/src/plugins/table/utils/drag-menu.ts +158 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { token } from '@atlaskit/tokens';
|
|
4
|
+
|
|
5
|
+
export const AddRowBelowIcon = () => (
|
|
6
|
+
<svg
|
|
7
|
+
width="24"
|
|
8
|
+
height="24"
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
fill="none"
|
|
11
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
12
|
+
>
|
|
13
|
+
<mask
|
|
14
|
+
id="path-1-inside-1_920_47112"
|
|
15
|
+
fill={token('color.border.inverse', '#FFFFFF')}
|
|
16
|
+
>
|
|
17
|
+
<rect x="6" y="4" width="12" height="8" rx="0.5" />
|
|
18
|
+
</mask>
|
|
19
|
+
<rect
|
|
20
|
+
x="6"
|
|
21
|
+
y="4"
|
|
22
|
+
width="12"
|
|
23
|
+
height="8"
|
|
24
|
+
rx="0.5"
|
|
25
|
+
stroke="currentColor"
|
|
26
|
+
strokeWidth="4"
|
|
27
|
+
mask="url(#path-1-inside-1_920_47112)"
|
|
28
|
+
/>
|
|
29
|
+
<path
|
|
30
|
+
fillRule="evenodd"
|
|
31
|
+
clipRule="evenodd"
|
|
32
|
+
d="M13 15V13.99C12.9974 13.7265 12.8908 13.4747 12.7036 13.2893C12.5163 13.104 12.2635 13 12 13C11.444 13 11 13.444 11 13.99V15H10C9.73478 15 9.48043 15.1054 9.29289 15.2929C9.10536 15.4804 9 15.7348 9 16C9 16.2652 9.10536 16.5196 9.29289 16.7071C9.48043 16.8946 9.73478 17 10 17H11V18.01C11.0026 18.2735 11.1092 18.5253 11.2964 18.7107C11.4837 18.896 11.7365 19 12 19C12.556 19 13 18.556 13 18.01V17H14C14.2652 17 14.5196 16.8946 14.7071 16.7071C14.8946 16.5196 15 16.2652 15 16C15 15.7348 14.8946 15.4804 14.7071 15.2929C14.5196 15.1054 14.2652 15 14 15H13Z"
|
|
33
|
+
fill="currentColor"
|
|
34
|
+
/>
|
|
35
|
+
</svg>
|
|
36
|
+
);
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export { DragHandleIcon } from './DragHandleIcon';
|
|
2
2
|
export { DragInMotionIcon } from './DragInMotionIcon';
|
|
3
|
+
export { AddRowAboveIcon } from './AddRowAboveIcon';
|
|
4
|
+
export { AddRowBelowIcon } from './AddRowBelowIcon';
|
|
5
|
+
export { AddColLeftIcon } from './AddColLeftIcon';
|
|
6
|
+
export { AddColRightIcon } from './AddColRightIcon';
|
|
@@ -1,13 +1,47 @@
|
|
|
1
|
+
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
2
|
+
import {
|
|
3
|
+
addColumnAfter,
|
|
4
|
+
addColumnBefore,
|
|
5
|
+
addRowAfter,
|
|
6
|
+
addRowBefore,
|
|
7
|
+
backspace,
|
|
8
|
+
tooltip,
|
|
9
|
+
} from '@atlaskit/editor-common/keymaps';
|
|
1
10
|
import type {
|
|
2
11
|
Command,
|
|
3
12
|
CommandDispatch,
|
|
4
13
|
DropdownOptionT,
|
|
14
|
+
GetEditorContainerWidth,
|
|
15
|
+
IconProps,
|
|
5
16
|
} from '@atlaskit/editor-common/types';
|
|
6
17
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import type { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
18
|
+
import type { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
|
|
19
|
+
import ArrowDownIcon from '@atlaskit/icon/glyph/arrow-down';
|
|
20
|
+
import ArrowLeftIcon from '@atlaskit/icon/glyph/arrow-left';
|
|
21
|
+
import ArrowRightIcon from '@atlaskit/icon/glyph/arrow-right';
|
|
22
|
+
import ArrowUpIcon from '@atlaskit/icon/glyph/arrow-up';
|
|
23
|
+
import CrossCircleIcon from '@atlaskit/icon/glyph/cross-circle';
|
|
24
|
+
import EditorLayoutThreeEqualIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
|
|
25
|
+
import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
26
|
+
import HipchatChevronDoubleDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-double-down';
|
|
27
|
+
import HipchatChevronDoubleUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-double-up';
|
|
8
28
|
|
|
29
|
+
import {
|
|
30
|
+
clearMultipleCells,
|
|
31
|
+
insertColumn,
|
|
32
|
+
insertRow,
|
|
33
|
+
sortByColumn,
|
|
34
|
+
} from '../commands';
|
|
35
|
+
import { deleteColumnsCommand } from '../commands/delete';
|
|
9
36
|
import { moveSource } from '../pm-plugins/drag-and-drop/commands';
|
|
37
|
+
import { deleteRows } from '../transforms';
|
|
10
38
|
import type { TableDirection } from '../types';
|
|
39
|
+
import {
|
|
40
|
+
AddColLeftIcon,
|
|
41
|
+
AddColRightIcon,
|
|
42
|
+
AddRowAboveIcon,
|
|
43
|
+
AddRowBelowIcon,
|
|
44
|
+
} from '../ui/icons';
|
|
11
45
|
|
|
12
46
|
const canDecrease = (index?: number, min: number = 0) =>
|
|
13
47
|
index !== undefined && index > min;
|
|
@@ -16,39 +50,148 @@ const canIncrease = (index?: number, max: number = 0) =>
|
|
|
16
50
|
|
|
17
51
|
export interface DragMenuConfig extends DropdownOptionT<Command> {
|
|
18
52
|
id: string;
|
|
53
|
+
icon?: React.ComponentType<IconProps>;
|
|
54
|
+
keymap?: string;
|
|
19
55
|
}
|
|
20
56
|
|
|
21
57
|
export const getDragMenuConfig = (
|
|
22
58
|
direction: TableDirection,
|
|
59
|
+
getEditorContainerWidth: GetEditorContainerWidth,
|
|
23
60
|
tableMap?: TableMap,
|
|
24
61
|
index?: number,
|
|
62
|
+
targetCellPosition?: number,
|
|
63
|
+
selectionRect?: Rect,
|
|
25
64
|
): DragMenuConfig[] => {
|
|
65
|
+
const addOptions =
|
|
66
|
+
direction === 'row'
|
|
67
|
+
? [
|
|
68
|
+
{
|
|
69
|
+
label: 'above',
|
|
70
|
+
offset: 0,
|
|
71
|
+
icon: AddRowAboveIcon,
|
|
72
|
+
keymap: addRowBefore,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
label: 'below',
|
|
76
|
+
offset: 1,
|
|
77
|
+
icon: AddRowBelowIcon,
|
|
78
|
+
keymap: addRowAfter,
|
|
79
|
+
},
|
|
80
|
+
]
|
|
81
|
+
: [
|
|
82
|
+
{
|
|
83
|
+
label: 'left',
|
|
84
|
+
offset: 0,
|
|
85
|
+
icon: AddColLeftIcon,
|
|
86
|
+
keymap: addColumnBefore,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: 'right',
|
|
90
|
+
offset: 1,
|
|
91
|
+
icon: AddColRightIcon,
|
|
92
|
+
keymap: addColumnAfter,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
26
95
|
const moveOptions =
|
|
27
96
|
direction === 'row'
|
|
28
97
|
? [
|
|
29
|
-
{ label: 'up', offset: -1, canMove: canDecrease },
|
|
98
|
+
{ label: 'up', offset: -1, canMove: canDecrease, icon: ArrowUpIcon },
|
|
30
99
|
{
|
|
31
100
|
label: 'down',
|
|
32
101
|
offset: 1,
|
|
33
102
|
canMove: (index?: number) =>
|
|
34
103
|
canIncrease(index, (tableMap?.height ?? 0) - 1),
|
|
104
|
+
icon: ArrowDownIcon,
|
|
35
105
|
},
|
|
36
106
|
]
|
|
37
107
|
: [
|
|
38
|
-
{
|
|
108
|
+
{
|
|
109
|
+
label: 'left',
|
|
110
|
+
offset: -1,
|
|
111
|
+
canMove: canDecrease,
|
|
112
|
+
icon: ArrowLeftIcon,
|
|
113
|
+
},
|
|
39
114
|
{
|
|
40
115
|
label: 'right',
|
|
41
116
|
offset: 1,
|
|
42
117
|
canMove: (index?: number) =>
|
|
43
118
|
canIncrease(index, (tableMap?.width ?? 0) - 1),
|
|
119
|
+
icon: ArrowRightIcon,
|
|
44
120
|
},
|
|
45
121
|
];
|
|
46
122
|
|
|
123
|
+
const sortOptions =
|
|
124
|
+
direction === 'column'
|
|
125
|
+
? [
|
|
126
|
+
{
|
|
127
|
+
label: 'increasing',
|
|
128
|
+
order: SortOrder.ASC,
|
|
129
|
+
icon: HipchatChevronDoubleUpIcon,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
label: 'decreasing',
|
|
133
|
+
order: SortOrder.DESC,
|
|
134
|
+
icon: HipchatChevronDoubleDownIcon,
|
|
135
|
+
},
|
|
136
|
+
]
|
|
137
|
+
: [];
|
|
47
138
|
return [
|
|
48
|
-
...
|
|
139
|
+
...addOptions.map(({ label, offset, icon, keymap }) => ({
|
|
140
|
+
id: `add_${direction}_${label}`,
|
|
141
|
+
title: `Add ${direction} ${label}`,
|
|
142
|
+
icon,
|
|
143
|
+
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
144
|
+
if (direction === 'row') {
|
|
145
|
+
insertRow(index! + offset, true)(state, dispatch);
|
|
146
|
+
} else {
|
|
147
|
+
insertColumn(getEditorContainerWidth)(index! + offset)(
|
|
148
|
+
state,
|
|
149
|
+
dispatch,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
},
|
|
154
|
+
keymap: keymap && tooltip(keymap),
|
|
155
|
+
})),
|
|
156
|
+
direction === 'column'
|
|
157
|
+
? {
|
|
158
|
+
id: 'distribute_columns',
|
|
159
|
+
title: 'Distribute columns',
|
|
160
|
+
disabled: true,
|
|
161
|
+
onClick: () => {
|
|
162
|
+
return false;
|
|
163
|
+
},
|
|
164
|
+
icon: EditorLayoutThreeEqualIcon,
|
|
165
|
+
}
|
|
166
|
+
: undefined,
|
|
167
|
+
{
|
|
168
|
+
id: 'clear_cells',
|
|
169
|
+
title: 'Clear cells',
|
|
170
|
+
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
171
|
+
clearMultipleCells(targetCellPosition)(state, dispatch);
|
|
172
|
+
return true;
|
|
173
|
+
},
|
|
174
|
+
icon: CrossCircleIcon,
|
|
175
|
+
keymap: tooltip(backspace),
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: `delete_${direction}`,
|
|
179
|
+
title: `Delete ${direction}`,
|
|
180
|
+
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
181
|
+
if (direction === 'row') {
|
|
182
|
+
dispatch?.(deleteRows(selectionRect!, false)(state.tr));
|
|
183
|
+
} else {
|
|
184
|
+
deleteColumnsCommand(selectionRect!)(state, dispatch);
|
|
185
|
+
}
|
|
186
|
+
return true;
|
|
187
|
+
},
|
|
188
|
+
icon: RemoveIcon,
|
|
189
|
+
},
|
|
190
|
+
...moveOptions.map(({ label, offset, canMove, icon }) => ({
|
|
49
191
|
id: `move_${direction}_${label}`,
|
|
50
192
|
title: `Move ${direction} ${label}`,
|
|
51
193
|
disabled: !canMove(index),
|
|
194
|
+
icon,
|
|
52
195
|
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
53
196
|
if (canMove(index)) {
|
|
54
197
|
moveSource(
|
|
@@ -61,5 +204,15 @@ export const getDragMenuConfig = (
|
|
|
61
204
|
return false;
|
|
62
205
|
},
|
|
63
206
|
})),
|
|
64
|
-
|
|
207
|
+
|
|
208
|
+
...sortOptions.map(({ label, order, icon }) => ({
|
|
209
|
+
id: `sort_column_${order}`,
|
|
210
|
+
title: `Sort ${label}`,
|
|
211
|
+
icon,
|
|
212
|
+
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
213
|
+
sortByColumn(index!, order)(state, dispatch);
|
|
214
|
+
return true;
|
|
215
|
+
},
|
|
216
|
+
})),
|
|
217
|
+
].filter(Boolean) as DragMenuConfig[];
|
|
65
218
|
};
|