@atlaskit/editor-plugin-table 5.3.13 → 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 +16 -0
- package/dist/cjs/plugins/table/event-handlers.js +6 -3
- package/dist/cjs/plugins/table/index.js +6 -4
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +3 -7
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
- package/dist/cjs/plugins/table/types.js +9 -2
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +49 -11
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +10 -5
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +57 -9
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +13 -4
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +44 -5
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +6 -4
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -13
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- 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/ui/ui-styles.js +27 -24
- package/dist/cjs/plugins/table/utils/dom.js +12 -4
- package/dist/cjs/plugins/table/utils/drag-menu.js +122 -10
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/es2019/plugins/table/event-handlers.js +5 -4
- package/dist/es2019/plugins/table/index.js +6 -4
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +3 -7
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +12 -0
- package/dist/es2019/plugins/table/types.js +9 -2
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +52 -8
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +10 -5
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +58 -7
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +10 -4
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +46 -6
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +35 -14
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/es2019/plugins/table/ui/common-styles.js +51 -3
- 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/ui/ui-styles.js +23 -1
- package/dist/es2019/plugins/table/utils/dom.js +5 -1
- package/dist/es2019/plugins/table/utils/drag-menu.js +118 -8
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/event-handlers.js +7 -4
- package/dist/esm/plugins/table/index.js +6 -4
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +3 -7
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -0
- package/dist/esm/plugins/table/types.js +9 -2
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +46 -8
- package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +10 -5
- package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +56 -8
- package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +9 -7
- package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +10 -4
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +45 -6
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +7 -5
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +36 -14
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/esm/plugins/table/ui/common-styles.js +2 -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/ui/ui-styles.js +26 -23
- package/dist/esm/plugins/table/utils/dom.js +11 -3
- package/dist/esm/plugins/table/utils/drag-menu.js +120 -8
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/types/plugins/table/types.d.ts +9 -2
- 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/FloatingInsertButton/InsertButton.d.ts +5 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- 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/ui/ui-styles.d.ts +1 -0
- package/dist/types/plugins/table/utils/dom.d.ts +4 -1
- package/dist/types/plugins/table/utils/drag-menu.d.ts +6 -3
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +9 -2
- 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/FloatingInsertButton/InsertButton.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- 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/ui/ui-styles.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +6 -3
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/package.json +2 -1
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +40 -194
- package/src/__tests__/unit/ui/RowDragControls.tsx +9 -11
- package/src/plugins/table/event-handlers.ts +15 -3
- package/src/plugins/table/index.tsx +4 -2
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +2 -9
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -3
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +9 -0
- package/src/plugins/table/types.ts +12 -2
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +73 -6
- package/src/plugins/table/ui/FloatingDragMenu/index.tsx +15 -3
- package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +82 -8
- package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +28 -5
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +19 -7
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +47 -3
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +11 -4
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +49 -18
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -0
- package/src/plugins/table/ui/common-styles.ts +57 -2
- 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/ui/ui-styles.ts +27 -1
- package/src/plugins/table/utils/dom.ts +11 -4
- package/src/plugins/table/utils/drag-menu.ts +158 -5
- package/src/plugins/table/utils/index.ts +2 -0
- package/tsconfig.app.json +3 -0
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
tdEmpty,
|
|
24
24
|
tr,
|
|
25
25
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
26
|
-
import { ffTest } from '@atlassian/feature-flags-test-utils';
|
|
27
26
|
|
|
28
27
|
import tablePlugin from '../../../../plugins/table';
|
|
29
28
|
import { selectColumn } from '../../../../plugins/table/commands';
|
|
@@ -55,141 +54,27 @@ describe('decorations plugin', () => {
|
|
|
55
54
|
// ED-8457
|
|
56
55
|
describe('when there is a selection pointer set', () => {
|
|
57
56
|
describe('should remove the column selected decorations', () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
() => {
|
|
61
|
-
const { editorView } = editor(
|
|
62
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
selectColumn(1)(editorView.state, editorView.dispatch);
|
|
66
|
-
|
|
67
|
-
const { tr: transaction } = editorView.state;
|
|
68
|
-
|
|
69
|
-
transaction.setMeta('pointer', true);
|
|
70
|
-
transaction.setSelection(Selection.atStart(transaction.doc));
|
|
71
|
-
editorView.dispatch(transaction);
|
|
72
|
-
|
|
73
|
-
const decorationSet = getDecorations(editorView.state);
|
|
74
|
-
|
|
75
|
-
const columnSelectedDecorations = decorationSet.find(
|
|
76
|
-
undefined,
|
|
77
|
-
undefined,
|
|
78
|
-
(spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(columnSelectedDecorations).toHaveLength(0);
|
|
82
|
-
},
|
|
83
|
-
() => {
|
|
84
|
-
const { editorView } = editor(
|
|
85
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
selectColumn(1)(editorView.state, editorView.dispatch);
|
|
89
|
-
|
|
90
|
-
const { tr: transaction } = editorView.state;
|
|
91
|
-
|
|
92
|
-
transaction.setMeta('pointer', true);
|
|
93
|
-
transaction.setSelection(Selection.atStart(transaction.doc));
|
|
94
|
-
editorView.dispatch(transaction);
|
|
95
|
-
|
|
96
|
-
const decorationSet = getDecorations(editorView.state);
|
|
97
|
-
|
|
98
|
-
const columnSelectedDecorations = decorationSet.find(
|
|
99
|
-
undefined,
|
|
100
|
-
undefined,
|
|
101
|
-
(spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect(columnSelectedDecorations).toHaveLength(0);
|
|
105
|
-
},
|
|
57
|
+
const { editorView } = editor(
|
|
58
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
106
59
|
);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
60
|
|
|
110
|
-
|
|
111
|
-
describe('should not add column control decorations', () => {
|
|
112
|
-
ffTest(
|
|
113
|
-
'platform.editor.table.drag-and-drop',
|
|
114
|
-
() => {
|
|
115
|
-
const pluginState = DecorationSet.empty;
|
|
116
|
-
const { editorView } = editor(
|
|
117
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
118
|
-
);
|
|
61
|
+
selectColumn(1)(editorView.state, editorView.dispatch);
|
|
119
62
|
|
|
120
|
-
|
|
121
|
-
type: 'HOVER_CELL',
|
|
122
|
-
data: {
|
|
123
|
-
colIndex: 0,
|
|
124
|
-
rowIndex: 0,
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const oldState = handleDocOrSelectionChanged(
|
|
129
|
-
transaction,
|
|
130
|
-
pluginState,
|
|
131
|
-
editorView.state,
|
|
132
|
-
editorView.state,
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
editorView.dispatch(transaction);
|
|
136
|
-
const newState = handleDocOrSelectionChanged(
|
|
137
|
-
transaction,
|
|
138
|
-
oldState,
|
|
139
|
-
editorView.state,
|
|
140
|
-
editorView.state,
|
|
141
|
-
);
|
|
63
|
+
const { tr: transaction } = editorView.state;
|
|
142
64
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
(spec) =>
|
|
147
|
-
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
|
|
148
|
-
-1,
|
|
149
|
-
);
|
|
65
|
+
transaction.setMeta('pointer', true);
|
|
66
|
+
transaction.setSelection(Selection.atStart(transaction.doc));
|
|
67
|
+
editorView.dispatch(transaction);
|
|
150
68
|
|
|
151
|
-
|
|
152
|
-
},
|
|
153
|
-
() => {
|
|
154
|
-
const pluginState = DecorationSet.empty;
|
|
155
|
-
const { editorView } = editor(
|
|
156
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const transaction = editorView.state.tr.setMeta(pluginKey, {
|
|
160
|
-
type: 'HOVER_CELL',
|
|
161
|
-
data: {
|
|
162
|
-
colIndex: 0,
|
|
163
|
-
rowIndex: 0,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
69
|
+
const decorationSet = getDecorations(editorView.state);
|
|
166
70
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
editorView.state,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
editorView.dispatch(transaction);
|
|
175
|
-
const newState = handleDocOrSelectionChanged(
|
|
176
|
-
transaction,
|
|
177
|
-
oldState,
|
|
178
|
-
editorView.state,
|
|
179
|
-
editorView.state,
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
const columnDecorations = newState.find(
|
|
183
|
-
undefined,
|
|
184
|
-
undefined,
|
|
185
|
-
(spec) =>
|
|
186
|
-
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
|
|
187
|
-
-1,
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
expect(columnDecorations).toHaveLength(2);
|
|
191
|
-
},
|
|
71
|
+
const columnSelectedDecorations = decorationSet.find(
|
|
72
|
+
undefined,
|
|
73
|
+
undefined,
|
|
74
|
+
(spec) => spec.key.indexOf(TableDecorations.COLUMN_SELECTED) > -1,
|
|
192
75
|
);
|
|
76
|
+
|
|
77
|
+
expect(columnSelectedDecorations).toHaveLength(0);
|
|
193
78
|
});
|
|
194
79
|
});
|
|
195
80
|
|
|
@@ -220,75 +105,36 @@ describe('decorations plugin', () => {
|
|
|
220
105
|
|
|
221
106
|
describe('when the table changed', () => {
|
|
222
107
|
describe('should not re-create the column controls decorations', () => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
228
|
-
);
|
|
229
|
-
const { state } = editorView;
|
|
230
|
-
|
|
231
|
-
const nextPluginState = handleDocOrSelectionChanged(
|
|
232
|
-
editorView.state.tr,
|
|
233
|
-
DecorationSet.empty,
|
|
234
|
-
editorView.state,
|
|
235
|
-
state,
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
const { tr: transaction } = state;
|
|
239
|
-
editorView.dispatch(addColumnAt(2)(transaction));
|
|
240
|
-
|
|
241
|
-
const newState = handleDocOrSelectionChanged(
|
|
242
|
-
transaction,
|
|
243
|
-
nextPluginState,
|
|
244
|
-
editorView.state,
|
|
245
|
-
state,
|
|
246
|
-
);
|
|
247
|
-
const expectedDecorationSet = newState;
|
|
248
|
-
const decorations = expectedDecorationSet.find(
|
|
249
|
-
undefined,
|
|
250
|
-
undefined,
|
|
251
|
-
(spec) =>
|
|
252
|
-
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
|
|
253
|
-
-1,
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
expect(decorations).toHaveLength(0);
|
|
257
|
-
},
|
|
258
|
-
() => {
|
|
259
|
-
const { editorView } = editor(
|
|
260
|
-
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
261
|
-
);
|
|
262
|
-
const { state } = editorView;
|
|
263
|
-
|
|
264
|
-
const nextPluginState = handleDocOrSelectionChanged(
|
|
265
|
-
editorView.state.tr,
|
|
266
|
-
DecorationSet.empty,
|
|
267
|
-
editorView.state,
|
|
268
|
-
state,
|
|
269
|
-
);
|
|
108
|
+
const { editorView } = editor(
|
|
109
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
110
|
+
);
|
|
111
|
+
const { state } = editorView;
|
|
270
112
|
|
|
271
|
-
|
|
272
|
-
|
|
113
|
+
const nextPluginState = handleDocOrSelectionChanged(
|
|
114
|
+
editorView.state.tr,
|
|
115
|
+
DecorationSet.empty,
|
|
116
|
+
editorView.state,
|
|
117
|
+
state,
|
|
118
|
+
);
|
|
273
119
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
nextPluginState,
|
|
277
|
-
editorView.state,
|
|
278
|
-
state,
|
|
279
|
-
);
|
|
280
|
-
const expectedDecorationSet = newState;
|
|
281
|
-
const decorations = expectedDecorationSet.find(
|
|
282
|
-
undefined,
|
|
283
|
-
undefined,
|
|
284
|
-
(spec) =>
|
|
285
|
-
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
|
|
286
|
-
-1,
|
|
287
|
-
);
|
|
120
|
+
const { tr: transaction } = state;
|
|
121
|
+
editorView.dispatch(addColumnAt(2)(transaction));
|
|
288
122
|
|
|
289
|
-
|
|
290
|
-
|
|
123
|
+
const newState = handleDocOrSelectionChanged(
|
|
124
|
+
transaction,
|
|
125
|
+
nextPluginState,
|
|
126
|
+
editorView.state,
|
|
127
|
+
state,
|
|
291
128
|
);
|
|
129
|
+
const expectedDecorationSet = newState;
|
|
130
|
+
const decorations = expectedDecorationSet.find(
|
|
131
|
+
undefined,
|
|
132
|
+
undefined,
|
|
133
|
+
(spec) =>
|
|
134
|
+
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) > -1,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
expect(decorations).toHaveLength(3);
|
|
292
138
|
});
|
|
293
139
|
});
|
|
294
140
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { render } from '@testing-library/react';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
4
|
import { IntlProvider } from 'react-intl-next';
|
|
5
5
|
|
|
6
6
|
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
|
|
30
30
|
import tablePlugin from '../../../plugins/table-plugin';
|
|
31
31
|
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
32
|
-
import { TableCssClassName as ClassName } from '../../../plugins/table/types';
|
|
32
|
+
// import { TableCssClassName as ClassName } from '../../../plugins/table/types';
|
|
33
33
|
import { DragControls } from '../../../plugins/table/ui/TableFloatingControls/RowControls';
|
|
34
34
|
|
|
35
35
|
describe('NumberColumn', () => {
|
|
@@ -63,7 +63,7 @@ describe('NumberColumn', () => {
|
|
|
63
63
|
);
|
|
64
64
|
const ref = editorView.dom.querySelector('table');
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
render(
|
|
67
67
|
<IntlProvider locale="en">
|
|
68
68
|
<DragControls
|
|
69
69
|
tableRef={ref!}
|
|
@@ -77,11 +77,9 @@ describe('NumberColumn', () => {
|
|
|
77
77
|
</IntlProvider>,
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
-
const
|
|
81
|
-
`.${ClassName.ROW_CONTROLS_WITH_DRAG}`,
|
|
82
|
-
);
|
|
80
|
+
const dragHandle = screen.getAllByTestId('table-floating-row-drag-handle');
|
|
83
81
|
|
|
84
|
-
expect(
|
|
82
|
+
expect(dragHandle.length).toBe(1);
|
|
85
83
|
});
|
|
86
84
|
|
|
87
85
|
it('should not render any drag handle containers if hoveredCell is undefined', () => {
|
|
@@ -98,7 +96,7 @@ describe('NumberColumn', () => {
|
|
|
98
96
|
);
|
|
99
97
|
const ref = editorView.dom.querySelector('table');
|
|
100
98
|
|
|
101
|
-
|
|
99
|
+
render(
|
|
102
100
|
<IntlProvider locale="en">
|
|
103
101
|
<DragControls
|
|
104
102
|
tableRef={ref!}
|
|
@@ -115,10 +113,10 @@ describe('NumberColumn', () => {
|
|
|
115
113
|
</IntlProvider>,
|
|
116
114
|
);
|
|
117
115
|
|
|
118
|
-
const
|
|
119
|
-
|
|
116
|
+
const dragHandle = screen.queryAllByTestId(
|
|
117
|
+
'table-floating-row-drag-handle',
|
|
120
118
|
);
|
|
121
119
|
|
|
122
|
-
expect(
|
|
120
|
+
expect(dragHandle.length).toBe(0);
|
|
123
121
|
});
|
|
124
122
|
});
|
|
@@ -55,6 +55,8 @@ import {
|
|
|
55
55
|
isCell,
|
|
56
56
|
isColumnControlsDecorations,
|
|
57
57
|
isCornerButton,
|
|
58
|
+
isDragColumnFloatingInsertDot,
|
|
59
|
+
isDragRowFloatingInsertDot,
|
|
58
60
|
isInsertRowButton,
|
|
59
61
|
isResizeHandleDecoration,
|
|
60
62
|
isRowControlsButton,
|
|
@@ -78,6 +80,12 @@ const isFocusingFloatingToolbar = (event: Event) =>
|
|
|
78
80
|
event.relatedTarget instanceof HTMLElement &&
|
|
79
81
|
event.relatedTarget.closest('[role="toolbar"]');
|
|
80
82
|
|
|
83
|
+
const isFocusingDragHandles = (event: Event) =>
|
|
84
|
+
event instanceof FocusEvent &&
|
|
85
|
+
event.relatedTarget instanceof HTMLElement &&
|
|
86
|
+
event.relatedTarget.closest('button') &&
|
|
87
|
+
event.relatedTarget.getAttribute('draggable') === 'true';
|
|
88
|
+
|
|
81
89
|
export const handleBlur = (view: EditorView, event: Event): boolean => {
|
|
82
90
|
const { state, dispatch } = view;
|
|
83
91
|
// IE version check for ED-4665
|
|
@@ -86,7 +94,8 @@ export const handleBlur = (view: EditorView, event: Event): boolean => {
|
|
|
86
94
|
browser.ie_version !== 11 &&
|
|
87
95
|
!isFocusingCalendar(event) &&
|
|
88
96
|
!isFocusingModal(event) &&
|
|
89
|
-
!isFocusingFloatingToolbar(event)
|
|
97
|
+
!isFocusingFloatingToolbar(event) &&
|
|
98
|
+
!isFocusingDragHandles(event)
|
|
90
99
|
) {
|
|
91
100
|
setEditorFocus(false)(state, dispatch);
|
|
92
101
|
}
|
|
@@ -312,7 +321,10 @@ export const handleMouseMove = (
|
|
|
312
321
|
}
|
|
313
322
|
const element = event.target;
|
|
314
323
|
|
|
315
|
-
if (
|
|
324
|
+
if (
|
|
325
|
+
isColumnControlsDecorations(element) ||
|
|
326
|
+
isDragColumnFloatingInsertDot(element)
|
|
327
|
+
) {
|
|
316
328
|
const { state, dispatch } = view;
|
|
317
329
|
const { insertColumnButtonIndex } = getPluginState(state);
|
|
318
330
|
const [startIndex, endIndex] = getColumnOrRowIndex(element);
|
|
@@ -330,7 +342,7 @@ export const handleMouseMove = (
|
|
|
330
342
|
}
|
|
331
343
|
}
|
|
332
344
|
|
|
333
|
-
if (isRowControlsButton(element)) {
|
|
345
|
+
if (isRowControlsButton(element) || isDragRowFloatingInsertDot(element)) {
|
|
334
346
|
const { state, dispatch } = view;
|
|
335
347
|
const { insertRowButtonIndex } = getPluginState(state);
|
|
336
348
|
const [startIndex, endIndex] = getColumnOrRowIndex(element);
|
|
@@ -383,8 +383,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
383
383
|
insertRowButtonIndex,
|
|
384
384
|
isHeaderColumnEnabled,
|
|
385
385
|
isHeaderRowEnabled,
|
|
386
|
-
tableWrapperTarget,
|
|
387
386
|
isDragAndDropEnabled,
|
|
387
|
+
tableWrapperTarget,
|
|
388
388
|
} = tablePluginState!;
|
|
389
389
|
|
|
390
390
|
const { allowControls } = pluginConfig;
|
|
@@ -444,6 +444,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
444
444
|
insertRowButtonIndex={insertRowButtonIndex}
|
|
445
445
|
isHeaderColumnEnabled={isHeaderColumnEnabled}
|
|
446
446
|
isHeaderRowEnabled={isHeaderRowEnabled}
|
|
447
|
+
isDragAndDropEnabled={isDragAndDropEnabled}
|
|
447
448
|
editorView={editorView}
|
|
448
449
|
mountPoint={popupsMountPoint}
|
|
449
450
|
boundariesElement={popupsBoundariesElement}
|
|
@@ -481,9 +482,10 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
481
482
|
direction={dragAndDropState?.dragMenuDirection}
|
|
482
483
|
index={dragAndDropState?.dragMenuIndex}
|
|
483
484
|
isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
|
|
485
|
+
getEditorContainerWidth={defaultGetEditorContainerWidth}
|
|
484
486
|
/>
|
|
485
487
|
)}
|
|
486
|
-
{allowControls && !isResizing && (
|
|
488
|
+
{allowControls && !isDragAndDropEnabled && !isResizing && (
|
|
487
489
|
<FloatingDeleteButton
|
|
488
490
|
editorView={editorView}
|
|
489
491
|
selection={editorView.state.selection}
|
|
@@ -40,8 +40,7 @@ export const handleDocOrSelectionChanged = (
|
|
|
40
40
|
} else if (
|
|
41
41
|
tr.docChanged ||
|
|
42
42
|
tr.selection instanceof CellSelection ||
|
|
43
|
-
changedResizing
|
|
44
|
-
tr.getMeta(tablePluginKey)?.type === 'HOVER_CELL'
|
|
43
|
+
changedResizing
|
|
45
44
|
) {
|
|
46
45
|
return buildColumnControlsDecorations({
|
|
47
46
|
decorationSet,
|
|
@@ -72,11 +71,6 @@ export const createPlugin = () => {
|
|
|
72
71
|
apply: (tr, decorationSet, oldState, newState) => {
|
|
73
72
|
let pluginState = decorationSet;
|
|
74
73
|
const meta = tr.getMeta(tablePluginKey);
|
|
75
|
-
const previousHover = tablePluginKey.getState(oldState)?.hoveredCell;
|
|
76
|
-
const newHover = tablePluginKey.getState(newState)?.hoveredCell;
|
|
77
|
-
const changedCellHover =
|
|
78
|
-
previousHover?.colIndex !== newHover?.colIndex ||
|
|
79
|
-
previousHover?.rowIndex !== newHover?.rowIndex;
|
|
80
74
|
|
|
81
75
|
if (meta && meta.data && meta.data.decorationSet) {
|
|
82
76
|
pluginState = meta.data.decorationSet;
|
|
@@ -85,8 +79,7 @@ export const createPlugin = () => {
|
|
|
85
79
|
if (
|
|
86
80
|
tr.docChanged ||
|
|
87
81
|
tr.selectionSet ||
|
|
88
|
-
tr.getMeta(tableWidthPluginKey)
|
|
89
|
-
changedCellHover
|
|
82
|
+
tr.getMeta(tableWidthPluginKey)
|
|
90
83
|
) {
|
|
91
84
|
pluginState = pluginState.map(tr.mapping, tr.doc);
|
|
92
85
|
return handleDocOrSelectionChanged(
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
findControlsHoverDecoration,
|
|
16
16
|
updateDecorations,
|
|
17
17
|
} from '../../../utils/decoration';
|
|
18
|
-
import { pluginKey as tablePluginKey } from '../../plugin-key';
|
|
19
18
|
|
|
20
19
|
import { composeDecorations } from './compose-decorations';
|
|
21
20
|
import type { DecorationTransformer } from './types';
|
|
@@ -50,10 +49,9 @@ const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
|
|
|
50
49
|
tr,
|
|
51
50
|
}): DecorationSet => {
|
|
52
51
|
const table = findTable(tr.selection);
|
|
53
|
-
const meta = tr.getMeta(tablePluginKey);
|
|
54
52
|
|
|
55
53
|
// avoid re-drawing state if dnd decorations don't need to be updated
|
|
56
|
-
if (!table
|
|
54
|
+
if (!table) {
|
|
57
55
|
return decorationSet;
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -6,6 +6,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
6
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
8
|
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
9
|
+
import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
|
|
9
10
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
10
11
|
|
|
11
12
|
import type { DraggableSourceData } from '../../types';
|
|
@@ -96,7 +97,14 @@ export const createPlugin = (
|
|
|
96
97
|
// watch for changes
|
|
97
98
|
return localId === tableNode?.attrs.localId;
|
|
98
99
|
},
|
|
100
|
+
onDragStart: ({ location }) => {
|
|
101
|
+
autoScroller.start({ input: location.current.input });
|
|
102
|
+
},
|
|
99
103
|
onDrag(event) {
|
|
104
|
+
autoScroller.updateInput({
|
|
105
|
+
input: event.location.current.input,
|
|
106
|
+
});
|
|
107
|
+
|
|
100
108
|
const data = getDraggableDataFromEvent(event);
|
|
101
109
|
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
102
110
|
if (!data) {
|
|
@@ -118,6 +126,7 @@ export const createPlugin = (
|
|
|
118
126
|
);
|
|
119
127
|
},
|
|
120
128
|
onDrop(event) {
|
|
129
|
+
autoScroller.stop();
|
|
121
130
|
const data = getDraggableDataFromEvent(event);
|
|
122
131
|
|
|
123
132
|
// If no data can be found then it's most like we do not want to perform any drop action
|
|
@@ -293,6 +293,10 @@ export const TableCssClassName = {
|
|
|
293
293
|
CONTROLS_BUTTON_OVERLAY: `${tablePrefixSelector}-controls__button-overlay`,
|
|
294
294
|
LAYOUT_BUTTON: `${tablePrefixSelector}-layout-button`,
|
|
295
295
|
|
|
296
|
+
DRAG_CONTROLS_INSERT_BUTTON: `${tablePrefixSelector}-controls__drag-insert-button`,
|
|
297
|
+
DRAG_CONTROLS_INSERT_BUTTON_INNER: `${tablePrefixSelector}-controls__drag-insert-button-inner`,
|
|
298
|
+
DRAG_CONTROLS_INSERT_BUTTON_WRAP: `${tablePrefixSelector}-controls__drag-insert-button-wrap`,
|
|
299
|
+
|
|
296
300
|
CONTROLS_INSERT_MARKER: `${tablePrefixSelector}-controls__insert-marker`,
|
|
297
301
|
CONTROLS_INSERT_COLUMN: `${tablePrefixSelector}-controls__insert-column`,
|
|
298
302
|
CONTROLS_INSERT_ROW: `${tablePrefixSelector}-controls__insert-row`,
|
|
@@ -308,8 +312,14 @@ export const TableCssClassName = {
|
|
|
308
312
|
CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
|
|
309
313
|
|
|
310
314
|
/** Controls with drag handle */
|
|
311
|
-
|
|
312
|
-
|
|
315
|
+
DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
|
|
316
|
+
DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
|
|
317
|
+
DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
|
|
318
|
+
|
|
319
|
+
DRAG_COLUMN_CONTROLS: `${tablePrefixSelector}-drag-column-controls`,
|
|
320
|
+
DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-columns-floating-insert-dot-wrapper`,
|
|
321
|
+
DRAG_COLUMN_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-columns-floating-insert-dot`,
|
|
322
|
+
|
|
313
323
|
DRAG_HANDLE_BUTTON_CONTAINER: `${tablePrefixSelector}-drag-handle-button-container`,
|
|
314
324
|
|
|
315
325
|
/** Other classes */
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react';
|
|
2
3
|
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
Command,
|
|
6
|
+
GetEditorContainerWidth,
|
|
7
|
+
} from '@atlaskit/editor-common/types';
|
|
4
8
|
import {
|
|
5
9
|
ArrowKeyNavigationType,
|
|
6
10
|
DropdownMenu,
|
|
@@ -8,10 +12,19 @@ import {
|
|
|
8
12
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
9
13
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
10
14
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
15
|
+
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
11
16
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
17
|
+
import {
|
|
18
|
+
findCellRectClosestToPos,
|
|
19
|
+
getSelectionRect,
|
|
20
|
+
isSelectionType,
|
|
21
|
+
} from '@atlaskit/editor-tables/utils';
|
|
22
|
+
import { token } from '@atlaskit/tokens';
|
|
12
23
|
|
|
24
|
+
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
13
25
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
14
26
|
import type { PluginConfig, TableDirection } from '../../types';
|
|
27
|
+
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
15
28
|
import type { DragMenuConfig } from '../../utils/drag-menu';
|
|
16
29
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
17
30
|
import { dragMenuDropdownWidth } from '../consts';
|
|
@@ -28,6 +41,7 @@ type DragMenuProps = {
|
|
|
28
41
|
boundariesElement?: HTMLElement;
|
|
29
42
|
scrollableElement?: HTMLElement;
|
|
30
43
|
pluginConfig?: PluginConfig;
|
|
44
|
+
getEditorContainerWidth: GetEditorContainerWidth;
|
|
31
45
|
};
|
|
32
46
|
|
|
33
47
|
const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
|
|
@@ -39,6 +53,19 @@ const convertToDropdownItems = (dragMenuConfig: DragMenuConfig[]) => {
|
|
|
39
53
|
content: item.title,
|
|
40
54
|
value: { name: item.id },
|
|
41
55
|
isDisabled: item.disabled,
|
|
56
|
+
elemBefore: item.icon ? (
|
|
57
|
+
<div
|
|
58
|
+
style={{
|
|
59
|
+
marginRight: token('space.negative.075', '-6px'),
|
|
60
|
+
display: 'flex',
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<item.icon label={item.title} />
|
|
64
|
+
</div>
|
|
65
|
+
) : undefined,
|
|
66
|
+
elemAfter: item.keymap ? (
|
|
67
|
+
<div css={shortcutStyle}>{item.keymap}</div>
|
|
68
|
+
) : undefined,
|
|
42
69
|
});
|
|
43
70
|
item.onClick && (menuCallback[item.id] = item.onClick);
|
|
44
71
|
});
|
|
@@ -54,10 +81,25 @@ export const DragMenu = ({
|
|
|
54
81
|
mountPoint,
|
|
55
82
|
boundariesElement,
|
|
56
83
|
scrollableElement,
|
|
84
|
+
targetCellPosition,
|
|
85
|
+
getEditorContainerWidth,
|
|
57
86
|
}: DragMenuProps) => {
|
|
58
87
|
const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
59
88
|
|
|
60
|
-
const
|
|
89
|
+
const { state, dispatch } = editorView;
|
|
90
|
+
const { selection } = state;
|
|
91
|
+
const selectionRect = isSelectionType(selection, 'cell')
|
|
92
|
+
? getSelectionRect(selection)!
|
|
93
|
+
: findCellRectClosestToPos(selection.$from);
|
|
94
|
+
|
|
95
|
+
const dragMenuConfig = getDragMenuConfig(
|
|
96
|
+
direction,
|
|
97
|
+
getEditorContainerWidth,
|
|
98
|
+
tableMap,
|
|
99
|
+
index,
|
|
100
|
+
targetCellPosition,
|
|
101
|
+
selectionRect,
|
|
102
|
+
);
|
|
61
103
|
|
|
62
104
|
const { menuItems, menuCallback } = convertToDropdownItems(dragMenuConfig);
|
|
63
105
|
|
|
@@ -66,11 +108,34 @@ export const DragMenu = ({
|
|
|
66
108
|
toggleDragMenu(false)(state, dispatch);
|
|
67
109
|
};
|
|
68
110
|
|
|
69
|
-
const
|
|
70
|
-
menuCallback[item.value.name]?.(
|
|
111
|
+
const handleMenuItemActivated = ({ item }: { item: MenuItem }) => {
|
|
112
|
+
menuCallback[item.value.name]?.(state, dispatch);
|
|
71
113
|
closeMenu();
|
|
72
114
|
};
|
|
73
115
|
|
|
116
|
+
const handleItemMouseEnter = ({ item }: { item: MenuItem }) => {
|
|
117
|
+
if (!selectionRect || !item.value.name?.startsWith('delete')) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
(item.value.name === 'delete_column'
|
|
122
|
+
? hoverColumns(getSelectedColumnIndexes(selectionRect), true)
|
|
123
|
+
: hoverRows(getSelectedRowIndexes(selectionRect), true))(state, dispatch);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleItemMouseLeave = ({ item }: { item: any }) => {
|
|
127
|
+
if (
|
|
128
|
+
[
|
|
129
|
+
'sort_column_asc',
|
|
130
|
+
'sort_column_desc',
|
|
131
|
+
'delete_column',
|
|
132
|
+
'delete_row',
|
|
133
|
+
].indexOf(item.value.name) > -1
|
|
134
|
+
) {
|
|
135
|
+
clearHoverSelection()(state, dispatch);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
74
139
|
if (!menuItems) {
|
|
75
140
|
return null;
|
|
76
141
|
}
|
|
@@ -91,7 +156,9 @@ export const DragMenu = ({
|
|
|
91
156
|
]}
|
|
92
157
|
isOpen={isOpen}
|
|
93
158
|
onOpenChange={closeMenu}
|
|
94
|
-
onItemActivated={
|
|
159
|
+
onItemActivated={handleMenuItemActivated}
|
|
160
|
+
onMouseEnter={handleItemMouseEnter}
|
|
161
|
+
onMouseLeave={handleItemMouseLeave}
|
|
95
162
|
fitWidth={dragMenuDropdownWidth}
|
|
96
163
|
boundariesElement={boundariesElement}
|
|
97
164
|
/>
|