@atlaskit/editor-plugin-table 5.3.1 → 5.3.3
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 +12 -0
- package/dist/cjs/plugins/table/commands/hover.js +17 -8
- package/dist/cjs/plugins/table/commands/index.js +6 -0
- package/dist/cjs/plugins/table/commands/misc.js +1 -7
- package/dist/cjs/plugins/table/event-handlers.js +29 -2
- package/dist/cjs/plugins/table/index.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
- package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
- package/dist/cjs/plugins/table/reducer.js +2 -1
- package/dist/cjs/plugins/table/types.js +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
- package/dist/cjs/plugins/table/ui/DragPreview/index.js +39 -0
- package/dist/cjs/plugins/table/ui/Icons/DragInMotionIcon.js +55 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
- package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
- package/dist/cjs/plugins/table/ui/consts.js +2 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +18 -9
- package/dist/cjs/plugins/table/utils/decoration.js +44 -18
- package/dist/cjs/plugins/table/utils/dom.js +7 -1
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/es2019/plugins/table/commands/hover.js +12 -8
- package/dist/es2019/plugins/table/commands/index.js +1 -1
- package/dist/es2019/plugins/table/commands/misc.js +1 -7
- package/dist/es2019/plugins/table/event-handlers.js +28 -2
- package/dist/es2019/plugins/table/index.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
- package/dist/es2019/plugins/table/reducer.js +2 -1
- package/dist/es2019/plugins/table/types.js +6 -0
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/es2019/plugins/table/ui/DragPreview/index.js +33 -0
- package/dist/es2019/plugins/table/ui/Icons/DragInMotionIcon.js +47 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/es2019/plugins/table/ui/common-styles.js +47 -12
- package/dist/es2019/plugins/table/ui/consts.js +1 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +57 -14
- package/dist/es2019/plugins/table/utils/decoration.js +44 -18
- package/dist/es2019/plugins/table/utils/dom.js +2 -0
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/commands/hover.js +16 -8
- package/dist/esm/plugins/table/commands/index.js +1 -1
- package/dist/esm/plugins/table/commands/misc.js +1 -7
- package/dist/esm/plugins/table/event-handlers.js +29 -2
- package/dist/esm/plugins/table/index.js +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
- package/dist/esm/plugins/table/reducer.js +2 -1
- package/dist/esm/plugins/table/types.js +6 -0
- package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/esm/plugins/table/ui/DragPreview/index.js +32 -0
- package/dist/esm/plugins/table/ui/Icons/DragInMotionIcon.js +48 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/esm/plugins/table/ui/common-styles.js +10 -7
- package/dist/esm/plugins/table/ui/consts.js +1 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +18 -9
- package/dist/esm/plugins/table/utils/decoration.js +44 -18
- package/dist/esm/plugins/table/utils/dom.js +6 -0
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/types/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types/plugins/table/commands/index.d.ts +1 -1
- package/dist/types/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +16 -1
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types/plugins/table/ui/DragPreview/index.d.ts +6 -0
- package/dist/types/plugins/table/ui/Icons/DragInMotionIcon.d.ts +6 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +2 -2
- package/dist/types/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +16 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/ui/DragPreview/index.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/ui/Icons/DragInMotionIcon.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/package.json +5 -3
- package/src/__tests__/unit/event-handlers.ts +74 -1
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
- package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
- package/src/__tests__/unit/ui/RowControls.tsx +4 -4
- package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
- package/src/plugins/table/commands/hover.ts +16 -7
- package/src/plugins/table/commands/index.ts +1 -0
- package/src/plugins/table/commands/misc.ts +0 -5
- package/src/plugins/table/event-handlers.ts +49 -2
- package/src/plugins/table/index.tsx +1 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
- package/src/plugins/table/nodeviews/table.tsx +2 -0
- package/src/plugins/table/nodeviews/types.ts +4 -3
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
- package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
- package/src/plugins/table/pm-plugins/main.ts +9 -4
- package/src/plugins/table/reducer.ts +2 -1
- package/src/plugins/table/types.ts +14 -2
- package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
- package/src/plugins/table/ui/DragPreview/index.tsx +45 -0
- package/src/plugins/table/ui/Icons/DragInMotionIcon.tsx +60 -0
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
- package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
- package/src/plugins/table/ui/common-styles.ts +52 -11
- package/src/plugins/table/ui/consts.ts +1 -0
- package/src/plugins/table/ui/ui-styles.ts +58 -14
- package/src/plugins/table/utils/decoration.ts +75 -27
- package/src/plugins/table/utils/dom.ts +8 -0
- package/src/plugins/table/utils/index.ts +2 -0
- package/tsconfig.app.json +6 -0
|
@@ -23,6 +23,7 @@ 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';
|
|
26
27
|
|
|
27
28
|
import tablePlugin from '../../../../plugins/table';
|
|
28
29
|
import { selectColumn } from '../../../../plugins/table/commands';
|
|
@@ -53,28 +54,92 @@ describe('decorations plugin', () => {
|
|
|
53
54
|
|
|
54
55
|
// ED-8457
|
|
55
56
|
describe('when there is a selection pointer set', () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
describe('should remove the column selected decorations', () => {
|
|
58
|
+
ffTest(
|
|
59
|
+
'platform.editor.table.drag-and-drop',
|
|
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
|
+
);
|
|
60
87
|
|
|
61
|
-
|
|
88
|
+
selectColumn(1)(editorView.state, editorView.dispatch);
|
|
62
89
|
|
|
63
|
-
|
|
90
|
+
const { tr: transaction } = editorView.state;
|
|
64
91
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
transaction.setMeta('pointer', true);
|
|
93
|
+
transaction.setSelection(Selection.atStart(transaction.doc));
|
|
94
|
+
editorView.dispatch(transaction);
|
|
68
95
|
|
|
69
|
-
|
|
96
|
+
const decorationSet = getDecorations(editorView.state);
|
|
70
97
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
},
|
|
75
106
|
);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('when the hovered cell state changes', () => {
|
|
111
|
+
describe('should add column control decorations', () => {
|
|
112
|
+
ffTest('platform.editor.table.drag-and-drop', () => {
|
|
113
|
+
const pluginState = DecorationSet.empty;
|
|
114
|
+
const { editorView } = editor(
|
|
115
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
116
|
+
);
|
|
76
117
|
|
|
77
|
-
|
|
118
|
+
const transaction = editorView.state.tr.setMeta(pluginKey, {
|
|
119
|
+
type: 'HOVER_CELL',
|
|
120
|
+
data: {
|
|
121
|
+
colIndex: 0,
|
|
122
|
+
rowIndex: 0,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const oldState = handleDocOrSelectionChanged(
|
|
127
|
+
transaction,
|
|
128
|
+
pluginState,
|
|
129
|
+
editorView.state,
|
|
130
|
+
editorView.state,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
editorView.dispatch(transaction);
|
|
134
|
+
const newState = handleDocOrSelectionChanged(
|
|
135
|
+
transaction,
|
|
136
|
+
oldState,
|
|
137
|
+
editorView.state,
|
|
138
|
+
editorView.state,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
expect(oldState).not.toEqual(newState);
|
|
142
|
+
});
|
|
78
143
|
});
|
|
79
144
|
});
|
|
80
145
|
|
|
@@ -104,37 +169,76 @@ describe('decorations plugin', () => {
|
|
|
104
169
|
});
|
|
105
170
|
|
|
106
171
|
describe('when the table changed', () => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
172
|
+
describe('should re-create the column controls decorations', () => {
|
|
173
|
+
ffTest(
|
|
174
|
+
'platform.editor.table.drag-and-drop',
|
|
175
|
+
() => {
|
|
176
|
+
const { editorView } = editor(
|
|
177
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
178
|
+
);
|
|
179
|
+
const { state } = editorView;
|
|
112
180
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
181
|
+
const nextPluginState = handleDocOrSelectionChanged(
|
|
182
|
+
editorView.state.tr,
|
|
183
|
+
DecorationSet.empty,
|
|
184
|
+
editorView.state,
|
|
185
|
+
state,
|
|
186
|
+
);
|
|
119
187
|
|
|
120
|
-
|
|
121
|
-
|
|
188
|
+
const { tr: transaction } = state;
|
|
189
|
+
editorView.dispatch(addColumnAt(2)(transaction));
|
|
122
190
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
191
|
+
const newState = handleDocOrSelectionChanged(
|
|
192
|
+
transaction,
|
|
193
|
+
nextPluginState,
|
|
194
|
+
editorView.state,
|
|
195
|
+
state,
|
|
196
|
+
);
|
|
197
|
+
const expectedDecorationSet = newState;
|
|
198
|
+
const decorations = expectedDecorationSet.find(
|
|
199
|
+
undefined,
|
|
200
|
+
undefined,
|
|
201
|
+
(spec) =>
|
|
202
|
+
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
|
|
203
|
+
-1,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
expect(decorations).toHaveLength(3);
|
|
207
|
+
},
|
|
208
|
+
() => {
|
|
209
|
+
const { editorView } = editor(
|
|
210
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
211
|
+
);
|
|
212
|
+
const { state } = editorView;
|
|
213
|
+
|
|
214
|
+
const nextPluginState = handleDocOrSelectionChanged(
|
|
215
|
+
editorView.state.tr,
|
|
216
|
+
DecorationSet.empty,
|
|
217
|
+
editorView.state,
|
|
218
|
+
state,
|
|
219
|
+
);
|
|
136
220
|
|
|
137
|
-
|
|
221
|
+
const { tr: transaction } = state;
|
|
222
|
+
editorView.dispatch(addColumnAt(2)(transaction));
|
|
223
|
+
|
|
224
|
+
const newState = handleDocOrSelectionChanged(
|
|
225
|
+
transaction,
|
|
226
|
+
nextPluginState,
|
|
227
|
+
editorView.state,
|
|
228
|
+
state,
|
|
229
|
+
);
|
|
230
|
+
const expectedDecorationSet = newState;
|
|
231
|
+
const decorations = expectedDecorationSet.find(
|
|
232
|
+
undefined,
|
|
233
|
+
undefined,
|
|
234
|
+
(spec) =>
|
|
235
|
+
spec.key.indexOf(TableDecorations.COLUMN_CONTROLS_DECORATIONS) >
|
|
236
|
+
-1,
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
expect(decorations).toHaveLength(3);
|
|
240
|
+
},
|
|
241
|
+
);
|
|
138
242
|
});
|
|
139
243
|
});
|
|
140
244
|
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
4
|
+
import { IntlProvider } from 'react-intl-next';
|
|
5
|
+
|
|
6
|
+
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
7
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
8
|
+
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
9
|
+
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
10
|
+
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
11
|
+
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
12
|
+
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
13
|
+
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
14
|
+
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
15
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
16
|
+
import {
|
|
17
|
+
createProsemirrorEditorFactory,
|
|
18
|
+
Preset,
|
|
19
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
20
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
21
|
+
import {
|
|
22
|
+
doc,
|
|
23
|
+
p,
|
|
24
|
+
table,
|
|
25
|
+
tdEmpty,
|
|
26
|
+
tr,
|
|
27
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
28
|
+
|
|
29
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
30
|
+
import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
|
|
31
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
32
|
+
// import type { TablePluginState } from '../../../plugins/table/types';
|
|
33
|
+
import { TableCssClassName as ClassName } from '../../../plugins/table/types';
|
|
34
|
+
import NumberColumn from '../../../plugins/table/ui/TableFloatingControls/NumberColumn';
|
|
35
|
+
|
|
36
|
+
describe('NumberColumn', () => {
|
|
37
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
38
|
+
|
|
39
|
+
const editor = (doc: DocBuilder, tableOptions = {}) =>
|
|
40
|
+
createEditor({
|
|
41
|
+
doc,
|
|
42
|
+
preset: new Preset<LightEditorPlugin>()
|
|
43
|
+
.add([featureFlagsPlugin, {}])
|
|
44
|
+
.add([analyticsPlugin, {}])
|
|
45
|
+
.add(contentInsertionPlugin)
|
|
46
|
+
.add(widthPlugin)
|
|
47
|
+
.add(guidelinePlugin)
|
|
48
|
+
.add(selectionPlugin)
|
|
49
|
+
.add([tablePlugin, { tableOptions }]),
|
|
50
|
+
pluginKey: pluginKey,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should update plugin state for hovered cell - when drag and drop is enabled', () => {
|
|
54
|
+
const { editorView } = editor(
|
|
55
|
+
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
56
|
+
{ dragAndDropEnabled: true },
|
|
57
|
+
);
|
|
58
|
+
const ref = editorView.dom.querySelector('table');
|
|
59
|
+
|
|
60
|
+
const { container } = render(
|
|
61
|
+
<IntlProvider locale="en">
|
|
62
|
+
<NumberColumn
|
|
63
|
+
tableRef={ref!}
|
|
64
|
+
tableActive
|
|
65
|
+
editorView={editorView}
|
|
66
|
+
hoverRows={jest.fn()}
|
|
67
|
+
selectRow={jest.fn()}
|
|
68
|
+
isDragAndDropEnabled
|
|
69
|
+
/>
|
|
70
|
+
</IntlProvider>,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const firstNumberedCell = container.querySelector(
|
|
74
|
+
`.${ClassName.NUMBERED_COLUMN} > div`,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
fireEvent.mouseOver(firstNumberedCell!);
|
|
78
|
+
|
|
79
|
+
const pluginState = getPluginState(editorView.state);
|
|
80
|
+
// colIndex is not defined yet, keep undefined
|
|
81
|
+
expect(pluginState.hoveredCell).toEqual({
|
|
82
|
+
colIndex: undefined,
|
|
83
|
+
rowIndex: 0,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should render button disabled numbered column cells - when drag and drop is enabled', () => {
|
|
88
|
+
const { editorView } = editor(
|
|
89
|
+
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
90
|
+
{ dragAndDropEnabled: true },
|
|
91
|
+
);
|
|
92
|
+
const ref = editorView.dom.querySelector('table');
|
|
93
|
+
|
|
94
|
+
const { container } = render(
|
|
95
|
+
<IntlProvider locale="en">
|
|
96
|
+
<NumberColumn
|
|
97
|
+
tableRef={ref!}
|
|
98
|
+
tableActive
|
|
99
|
+
editorView={editorView}
|
|
100
|
+
hoverRows={jest.fn()}
|
|
101
|
+
selectRow={jest.fn()}
|
|
102
|
+
isDragAndDropEnabled
|
|
103
|
+
/>
|
|
104
|
+
</IntlProvider>,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const firstNumberedCells = container.querySelectorAll(
|
|
108
|
+
`.${ClassName.NUMBERED_COLUMN} > div`,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
firstNumberedCells.forEach((cell) => {
|
|
112
|
+
expect(
|
|
113
|
+
cell.classList.contains(ClassName.NUMBERED_COLUMN_BUTTON_DISABLED),
|
|
114
|
+
).toBeTruthy();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should render buttons for numbered column cells - when drag and drop is disabled', () => {
|
|
119
|
+
const { editorView } = editor(
|
|
120
|
+
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
121
|
+
{ dragAndDropEnabled: false },
|
|
122
|
+
);
|
|
123
|
+
const ref = editorView.dom.querySelector('table');
|
|
124
|
+
|
|
125
|
+
const { container } = render(
|
|
126
|
+
<IntlProvider locale="en">
|
|
127
|
+
<NumberColumn
|
|
128
|
+
tableRef={ref!}
|
|
129
|
+
tableActive
|
|
130
|
+
editorView={editorView}
|
|
131
|
+
hoverRows={jest.fn()}
|
|
132
|
+
selectRow={jest.fn()}
|
|
133
|
+
isDragAndDropEnabled={false}
|
|
134
|
+
/>
|
|
135
|
+
</IntlProvider>,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const firstNumberedCells = container.querySelectorAll(
|
|
139
|
+
`.${ClassName.NUMBERED_COLUMN} > div`,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
firstNumberedCells.forEach((cell) => {
|
|
143
|
+
expect(
|
|
144
|
+
cell.classList.contains(ClassName.NUMBERED_COLUMN_BUTTON_DISABLED),
|
|
145
|
+
).toBeFalsy();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -41,7 +41,6 @@ import { RowControls } from '../../../plugins/table/ui/TableFloatingControls/Row
|
|
|
41
41
|
|
|
42
42
|
describe('RowControls', () => {
|
|
43
43
|
const createEditor = createProsemirrorEditorFactory();
|
|
44
|
-
const fakeGetEditorFeatureFlags = jest.fn(() => ({}));
|
|
45
44
|
let originalResizeObserver: any;
|
|
46
45
|
|
|
47
46
|
beforeAll(() => {
|
|
@@ -94,7 +93,8 @@ describe('RowControls', () => {
|
|
|
94
93
|
tableRef={ref}
|
|
95
94
|
tableActive
|
|
96
95
|
editorView={editorView}
|
|
97
|
-
|
|
96
|
+
isDragAndDropEnabled={false}
|
|
97
|
+
selection={editorView.state.selection}
|
|
98
98
|
/>
|
|
99
99
|
</IntlProvider>,
|
|
100
100
|
);
|
|
@@ -116,7 +116,6 @@ describe('RowControls', () => {
|
|
|
116
116
|
tableRef={ref}
|
|
117
117
|
tableActive={false}
|
|
118
118
|
editorView={editorView}
|
|
119
|
-
getEditorFeatureFlags={fakeGetEditorFeatureFlags}
|
|
120
119
|
/>
|
|
121
120
|
</IntlProvider>,
|
|
122
121
|
);
|
|
@@ -145,7 +144,8 @@ describe('RowControls', () => {
|
|
|
145
144
|
tableRef={ref}
|
|
146
145
|
tableActive
|
|
147
146
|
editorView={editorView}
|
|
148
|
-
|
|
147
|
+
isDragAndDropEnabled={false}
|
|
148
|
+
selection={editorView.state.selection}
|
|
149
149
|
/>
|
|
150
150
|
</IntlProvider>,
|
|
151
151
|
);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { IntlProvider } from 'react-intl-next';
|
|
5
|
+
|
|
6
|
+
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
7
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
8
|
+
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
9
|
+
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
10
|
+
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
11
|
+
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
12
|
+
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
13
|
+
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
14
|
+
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
15
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
16
|
+
import {
|
|
17
|
+
createProsemirrorEditorFactory,
|
|
18
|
+
Preset,
|
|
19
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
20
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
21
|
+
import {
|
|
22
|
+
doc,
|
|
23
|
+
p,
|
|
24
|
+
table,
|
|
25
|
+
td,
|
|
26
|
+
tdEmpty,
|
|
27
|
+
tr,
|
|
28
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
29
|
+
|
|
30
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
31
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
32
|
+
import { TableCssClassName as ClassName } from '../../../plugins/table/types';
|
|
33
|
+
import { DragControls } from '../../../plugins/table/ui/TableFloatingControls/RowControls';
|
|
34
|
+
|
|
35
|
+
describe('NumberColumn', () => {
|
|
36
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
37
|
+
|
|
38
|
+
const editor = (doc: DocBuilder, tableOptions = {}) =>
|
|
39
|
+
createEditor({
|
|
40
|
+
doc,
|
|
41
|
+
preset: new Preset<LightEditorPlugin>()
|
|
42
|
+
.add([featureFlagsPlugin, {}])
|
|
43
|
+
.add([analyticsPlugin, {}])
|
|
44
|
+
.add(contentInsertionPlugin)
|
|
45
|
+
.add(widthPlugin)
|
|
46
|
+
.add(guidelinePlugin)
|
|
47
|
+
.add(selectionPlugin)
|
|
48
|
+
.add([tablePlugin, { tableOptions }]),
|
|
49
|
+
pluginKey: pluginKey,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should only render one child container if hovered cell provided', () => {
|
|
53
|
+
const { editorView } = editor(
|
|
54
|
+
doc(
|
|
55
|
+
p('text'),
|
|
56
|
+
table()(
|
|
57
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
58
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
59
|
+
tr(td({})(p('\n\n\n\n\n')), tdEmpty, tdEmpty),
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
{ dragAndDropEnabled: true },
|
|
63
|
+
);
|
|
64
|
+
const ref = editorView.dom.querySelector('table');
|
|
65
|
+
|
|
66
|
+
const { container } = render(
|
|
67
|
+
<IntlProvider locale="en">
|
|
68
|
+
<DragControls
|
|
69
|
+
tableRef={ref!}
|
|
70
|
+
tableActive
|
|
71
|
+
editorView={editorView}
|
|
72
|
+
hoveredCell={{ rowIndex: 1, colIndex: 1 }}
|
|
73
|
+
/>
|
|
74
|
+
</IntlProvider>,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const dragHandleContainer = container.querySelector(
|
|
78
|
+
`.${ClassName.ROW_CONTROLS_WITH_DRAG}`,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(dragHandleContainer?.children.length).toBe(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should not render any drag handle containers if hoveredCell is undefined', () => {
|
|
85
|
+
const { editorView } = editor(
|
|
86
|
+
doc(
|
|
87
|
+
p('text'),
|
|
88
|
+
table()(
|
|
89
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
90
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
91
|
+
tr(td({})(p('\n\n\n\n\n')), tdEmpty, tdEmpty),
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
{ dragAndDropEnabled: true },
|
|
95
|
+
);
|
|
96
|
+
const ref = editorView.dom.querySelector('table');
|
|
97
|
+
|
|
98
|
+
const { container } = render(
|
|
99
|
+
<IntlProvider locale="en">
|
|
100
|
+
<DragControls
|
|
101
|
+
tableRef={ref!}
|
|
102
|
+
tableActive
|
|
103
|
+
editorView={editorView}
|
|
104
|
+
hoveredCell={{
|
|
105
|
+
colIndex: undefined,
|
|
106
|
+
rowIndex: undefined,
|
|
107
|
+
}}
|
|
108
|
+
/>
|
|
109
|
+
</IntlProvider>,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const dragHandleContainer = container.querySelector(
|
|
113
|
+
`.${ClassName.ROW_CONTROLS_WITH_DRAG}`,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(dragHandleContainer?.children.length).toBe(0);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -37,7 +37,7 @@ import TableFloatingControls from '../../../plugins/table/ui/TableFloatingContro
|
|
|
37
37
|
|
|
38
38
|
describe('TableFloatingControls', () => {
|
|
39
39
|
const createEditor = createProsemirrorEditorFactory();
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
const preset = new Preset<LightEditorPlugin>()
|
|
42
42
|
.add([featureFlagsPlugin, {}])
|
|
43
43
|
.add([analyticsPlugin, {}])
|
|
@@ -45,7 +45,10 @@ describe('TableFloatingControls', () => {
|
|
|
45
45
|
.add(widthPlugin)
|
|
46
46
|
.add(guidelinePlugin)
|
|
47
47
|
.add(selectionPlugin)
|
|
48
|
-
.add(
|
|
48
|
+
.add([
|
|
49
|
+
tablePlugin,
|
|
50
|
+
{ tableOptions: { advanced: true }, dragAndDropEnabled: false },
|
|
51
|
+
]);
|
|
49
52
|
|
|
50
53
|
const editor = (doc: DocBuilder) =>
|
|
51
54
|
createEditor<TablePluginState, PluginKey, typeof preset>({
|
|
@@ -62,7 +65,7 @@ describe('TableFloatingControls', () => {
|
|
|
62
65
|
const { container } = render(
|
|
63
66
|
<TableFloatingControls
|
|
64
67
|
editorView={editorView}
|
|
65
|
-
|
|
68
|
+
isDragAndDropEnabled={false}
|
|
66
69
|
/>,
|
|
67
70
|
);
|
|
68
71
|
expect(container.innerHTML).toEqual('');
|
|
@@ -72,7 +75,7 @@ describe('TableFloatingControls', () => {
|
|
|
72
75
|
describe('when tableRef is defined', () => {
|
|
73
76
|
it('should render CornerControls and RowControls', () => {
|
|
74
77
|
const { editorView } = editor(
|
|
75
|
-
doc(p('text'), table()(tr(
|
|
78
|
+
doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
76
79
|
);
|
|
77
80
|
const ref = editorView.dom.querySelector('table') || undefined;
|
|
78
81
|
|
|
@@ -82,7 +85,8 @@ describe('TableFloatingControls', () => {
|
|
|
82
85
|
tableRef={ref}
|
|
83
86
|
tableActive={true}
|
|
84
87
|
editorView={editorView}
|
|
85
|
-
|
|
88
|
+
isDragAndDropEnabled={false}
|
|
89
|
+
selection={editorView.state.selection}
|
|
86
90
|
/>
|
|
87
91
|
</IntlProvider>,
|
|
88
92
|
);
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
} from '@atlaskit/editor-tables/utils';
|
|
8
8
|
|
|
9
9
|
import { createCommand } from '../pm-plugins/plugin-factory';
|
|
10
|
-
import { Cell, CellColumnPositioning
|
|
10
|
+
import type { Cell, CellColumnPositioning } from '../types';
|
|
11
|
+
import { TableDecorations } from '../types';
|
|
11
12
|
import {
|
|
12
13
|
createCellHoverDecoration,
|
|
13
14
|
createColumnLineResize,
|
|
@@ -15,13 +16,9 @@ import {
|
|
|
15
16
|
getMergedCellsPositions,
|
|
16
17
|
updatePluginStateDecorations,
|
|
17
18
|
} from '../utils';
|
|
18
|
-
// #endregion
|
|
19
19
|
|
|
20
|
-
// #region Utils
|
|
21
20
|
const makeArray = (n: number) => Array.from(Array(n).keys());
|
|
22
|
-
// #endregion
|
|
23
21
|
|
|
24
|
-
// #region Commands
|
|
25
22
|
export const hoverMergedCells = () =>
|
|
26
23
|
createCommand(
|
|
27
24
|
(state) => {
|
|
@@ -43,7 +40,7 @@ export const hoverMergedCells = () =>
|
|
|
43
40
|
const decorations = createCellHoverDecoration(mergedCells);
|
|
44
41
|
|
|
45
42
|
return {
|
|
46
|
-
type: '
|
|
43
|
+
type: 'HOVER_MERGED_CELLS',
|
|
47
44
|
data: {
|
|
48
45
|
decorationSet: updatePluginStateDecorations(
|
|
49
46
|
state,
|
|
@@ -193,4 +190,16 @@ export const hideResizeHandleLine = () =>
|
|
|
193
190
|
),
|
|
194
191
|
},
|
|
195
192
|
}));
|
|
196
|
-
|
|
193
|
+
|
|
194
|
+
export const hoverCell = (rowIndex?: number, colIndex?: number) =>
|
|
195
|
+
createCommand(
|
|
196
|
+
() => {
|
|
197
|
+
return {
|
|
198
|
+
type: 'HOVER_CELL',
|
|
199
|
+
data: {
|
|
200
|
+
hoveredCell: { rowIndex, colIndex },
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
205
|
+
);
|
|
@@ -52,11 +52,7 @@ import {
|
|
|
52
52
|
isIsolating,
|
|
53
53
|
} from '../utils/nodes';
|
|
54
54
|
import { updatePluginStateDecorations } from '../utils/update-plugin-state-decorations';
|
|
55
|
-
// #endregion
|
|
56
55
|
|
|
57
|
-
// #endregion
|
|
58
|
-
|
|
59
|
-
// #region Commands
|
|
60
56
|
export const setEditorFocus = (editorHasFocus: boolean) =>
|
|
61
57
|
createCommand({
|
|
62
58
|
type: 'SET_EDITOR_FOCUS',
|
|
@@ -588,4 +584,3 @@ export const addBoldInEmptyHeaderCells =
|
|
|
588
584
|
|
|
589
585
|
return false;
|
|
590
586
|
};
|
|
591
|
-
// #endregion
|