@atlaskit/editor-plugin-table 5.3.0 → 5.3.2
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/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/drag-and-drop/commands.js +36 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
- 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 +14 -1
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -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 +3 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +21 -9
- package/dist/cjs/plugins/table/utils/decoration.js +111 -19
- package/dist/cjs/plugins/table/utils/dom.js +7 -1
- package/dist/cjs/plugins/table/utils/index.js +38 -1
- package/dist/cjs/plugins/table/utils/merged-cells.js +66 -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/drag-and-drop/commands.js +35 -7
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -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 +14 -1
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -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 +49 -13
- package/dist/es2019/plugins/table/ui/consts.js +2 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +171 -15
- package/dist/es2019/plugins/table/utils/decoration.js +106 -18
- package/dist/es2019/plugins/table/utils/dom.js +2 -0
- package/dist/es2019/plugins/table/utils/index.js +4 -3
- package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
- 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/drag-and-drop/commands.js +36 -7
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -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 +14 -1
- package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -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 +11 -8
- package/dist/esm/plugins/table/ui/consts.js +2 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +21 -9
- package/dist/esm/plugins/table/utils/decoration.js +110 -18
- package/dist/esm/plugins/table/utils/dom.js +6 -0
- package/dist/esm/plugins/table/utils/index.js +4 -3
- package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
- 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/drag-and-drop/actions.d.ts +5 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +35 -2
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -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 +2 -0
- package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +4 -2
- package/dist/types/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +3 -2
- package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
- 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/drag-and-drop/actions.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -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 +35 -2
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -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 +2 -0
- package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +4 -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 +3 -2
- package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
- package/package.json +6 -2
- 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/drag-and-drop/actions.ts +6 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -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 +37 -3
- package/src/plugins/table/ui/DragHandle/index.tsx +57 -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 +54 -11
- package/src/plugins/table/ui/consts.ts +2 -0
- package/src/plugins/table/ui/ui-styles.ts +173 -14
- package/src/plugins/table/utils/decoration.ts +176 -27
- package/src/plugins/table/utils/dom.ts +8 -0
- package/src/plugins/table/utils/index.ts +5 -0
- package/src/plugins/table/utils/merged-cells.ts +67 -0
- package/tsconfig.app.json +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -40,8 +40,9 @@
|
|
|
40
40
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
41
41
|
"@atlaskit/pragmatic-drag-and-drop": "^0.23.0",
|
|
42
42
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.11.8",
|
|
43
|
+
"@atlaskit/pragmatic-drag-and-drop-react-accessibility": "^0.4.0",
|
|
43
44
|
"@atlaskit/theme": "^12.6.0",
|
|
44
|
-
"@atlaskit/tokens": "^1.
|
|
45
|
+
"@atlaskit/tokens": "^1.27.0",
|
|
45
46
|
"@atlaskit/tooltip": "^17.8.0",
|
|
46
47
|
"@babel/runtime": "^7.0.0",
|
|
47
48
|
"@emotion/react": "^11.7.1",
|
|
@@ -106,6 +107,9 @@
|
|
|
106
107
|
"platform.editor.custom-table-width": {
|
|
107
108
|
"type": "boolean"
|
|
108
109
|
},
|
|
110
|
+
"platform.editor.table.drag-and-drop": {
|
|
111
|
+
"type": "boolean"
|
|
112
|
+
},
|
|
109
113
|
"platform.editor.table-sticky-scrollbar": {
|
|
110
114
|
"type": "boolean"
|
|
111
115
|
},
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
tdEmpty,
|
|
26
26
|
tr,
|
|
27
27
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
28
|
+
import { ffTest } from '@atlassian/feature-flags-test-utils';
|
|
28
29
|
|
|
29
30
|
import tablePlugin from '../../plugins/table-plugin';
|
|
30
31
|
import {
|
|
@@ -36,7 +37,9 @@ import {
|
|
|
36
37
|
handleMouseMove,
|
|
37
38
|
handleMouseOut,
|
|
38
39
|
handleMouseOver,
|
|
40
|
+
withCellTracking,
|
|
39
41
|
} from '../../plugins/table/event-handlers';
|
|
42
|
+
import { getPluginState } from '../../plugins/table/pm-plugins/plugin-factory';
|
|
40
43
|
import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
41
44
|
import { TableCssClassName as ClassName } from '../../plugins/table/types';
|
|
42
45
|
|
|
@@ -60,7 +63,7 @@ describe('table plugin: decorations', () => {
|
|
|
60
63
|
beforeEach(() => {
|
|
61
64
|
jest.resetAllMocks();
|
|
62
65
|
});
|
|
63
|
-
it('should return true & prevent default behaviour for table wrappers: pm-table-
|
|
66
|
+
it('should return true & prevent default behaviour for table wrappers: pm-table-container', () => {
|
|
64
67
|
const { editorView } = editor(
|
|
65
68
|
doc(table()(tr(td({})(p())), tr(td({})(p())), tr(td({})(p())))),
|
|
66
69
|
);
|
|
@@ -232,3 +235,73 @@ describe('table event handlers', () => {
|
|
|
232
235
|
});
|
|
233
236
|
});
|
|
234
237
|
});
|
|
238
|
+
|
|
239
|
+
describe('withCellTracking', () => {
|
|
240
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
241
|
+
const editor = (doc: DocBuilder, isDragAndDropEnabled = false) =>
|
|
242
|
+
createEditor({
|
|
243
|
+
doc,
|
|
244
|
+
attachTo: document.body,
|
|
245
|
+
preset: new Preset<LightEditorPlugin>()
|
|
246
|
+
.add([featureFlagsPlugin, {}])
|
|
247
|
+
.add([analyticsPlugin, {}])
|
|
248
|
+
.add(contentInsertionPlugin)
|
|
249
|
+
.add(decorationsPlugin)
|
|
250
|
+
.add(widthPlugin)
|
|
251
|
+
.add(guidelinePlugin)
|
|
252
|
+
.add(gridPlugin)
|
|
253
|
+
.add(selectionPlugin)
|
|
254
|
+
.add([
|
|
255
|
+
tablePlugin,
|
|
256
|
+
{
|
|
257
|
+
dragAndDropEnabled: isDragAndDropEnabled,
|
|
258
|
+
tableOptions: { advanced: true },
|
|
259
|
+
},
|
|
260
|
+
]),
|
|
261
|
+
pluginKey,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('should fire event handler passed in', () => {
|
|
265
|
+
ffTest(
|
|
266
|
+
'platform.editor.table.drag-and-drop',
|
|
267
|
+
() => {
|
|
268
|
+
const { editorView } = editor(
|
|
269
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
270
|
+
true,
|
|
271
|
+
);
|
|
272
|
+
const eventHandlerSpy = jest.fn();
|
|
273
|
+
withCellTracking(eventHandlerSpy)(editorView, {} as any);
|
|
274
|
+
|
|
275
|
+
expect(eventHandlerSpy).toHaveBeenCalled();
|
|
276
|
+
},
|
|
277
|
+
() => {
|
|
278
|
+
const { editorView } = editor(
|
|
279
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
280
|
+
);
|
|
281
|
+
const eventHandlerSpy = jest.fn();
|
|
282
|
+
withCellTracking(eventHandlerSpy)(editorView, {} as any);
|
|
283
|
+
|
|
284
|
+
expect(eventHandlerSpy).toHaveBeenCalled();
|
|
285
|
+
},
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe('should correctly set table cell coordinates based on mouse location', () => {
|
|
290
|
+
ffTest('platform.editor.table.drag-and-drop', () => {
|
|
291
|
+
const { editorView, refs } = editor(
|
|
292
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
293
|
+
true,
|
|
294
|
+
);
|
|
295
|
+
const firstCell = editorView.domAtPos(refs['<>']);
|
|
296
|
+
|
|
297
|
+
const event = {
|
|
298
|
+
target: firstCell.node,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
withCellTracking(jest.fn())(editorView, event as any);
|
|
302
|
+
|
|
303
|
+
const pluginState = getPluginState(editorView.state);
|
|
304
|
+
expect(pluginState.hoveredCell).toEqual({ colIndex: 0, rowIndex: 0 });
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
});
|
|
@@ -9,27 +9,47 @@ import {
|
|
|
9
9
|
tdEmpty,
|
|
10
10
|
tr,
|
|
11
11
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
12
|
+
import { ffTest } from '@atlassian/feature-flags-test-utils';
|
|
12
13
|
|
|
13
14
|
import { buildColumnControlsDecorations } from '../../../../plugins/table/pm-plugins/decorations/utils';
|
|
14
15
|
import { TableDecorations } from '../../../../plugins/table/types';
|
|
15
16
|
|
|
16
17
|
describe('tables: column controls decorations', () => {
|
|
17
|
-
describe(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
describe(`should return a decorationSet with 2 ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type`, () => {
|
|
19
|
+
ffTest(
|
|
20
|
+
'platform.editor.table.drag-and-drop',
|
|
21
|
+
() => {
|
|
22
|
+
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
23
|
+
const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
|
|
24
|
+
const nextDecorationSet = buildColumnControlsDecorations({
|
|
25
|
+
decorationSet: DecorationSet.empty,
|
|
26
|
+
tr: state.tr,
|
|
27
|
+
});
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const decorations = nextDecorationSet.find(
|
|
30
|
+
undefined,
|
|
31
|
+
undefined,
|
|
32
|
+
(spec: any) => spec.key.indexOf(decorationKey) > -1,
|
|
33
|
+
);
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
expect(decorations).toHaveLength(2);
|
|
36
|
+
},
|
|
37
|
+
() => {
|
|
38
|
+
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
39
|
+
const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
|
|
40
|
+
const nextDecorationSet = buildColumnControlsDecorations({
|
|
41
|
+
decorationSet: DecorationSet.empty,
|
|
42
|
+
tr: state.tr,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const decorations = nextDecorationSet.find(
|
|
46
|
+
undefined,
|
|
47
|
+
undefined,
|
|
48
|
+
(spec: any) => spec.key.indexOf(decorationKey) > -1,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(decorations).toHaveLength(2);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
34
54
|
});
|
|
35
55
|
});
|
|
@@ -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
|
);
|