@atlaskit/editor-plugin-table 0.0.6 → 0.0.8
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 +17 -0
- package/dist/cjs/plugins/table/event-handlers.js +7 -6
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/cjs/plugins/table/toolbar.js +0 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -4
- package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/event-handlers.js +8 -7
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/es2019/plugins/table/toolbar.js +1 -2
- package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/event-handlers.js +8 -7
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/esm/plugins/table/toolbar.js +1 -2
- package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/esm/plugins/table/utils/column-controls.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/package.json +10 -3
- package/src/__tests__/unit/analytics.ts +737 -0
- package/src/__tests__/unit/collab.ts +76 -0
- package/src/__tests__/unit/commands/sort.ts +230 -0
- package/src/__tests__/unit/copy-paste.ts +686 -0
- package/src/__tests__/unit/event-handlers/index.ts +106 -0
- package/src/__tests__/unit/event-handlers.ts +202 -0
- package/src/__tests__/unit/fix-tables.ts +156 -0
- package/src/__tests__/unit/floating-toolbar.ts +95 -0
- package/src/__tests__/unit/handlers.ts +81 -0
- package/src/__tests__/unit/hover-selection.ts +277 -0
- package/src/__tests__/unit/index-with-fake-timers.ts +107 -0
- package/src/__tests__/unit/index.ts +986 -0
- package/src/__tests__/unit/keymap.ts +602 -0
- package/src/__tests__/unit/layout.ts +196 -0
- package/src/__tests__/unit/nodeviews/cell.ts +167 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
- package/src/__tests__/unit/sort-column.ts +512 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
- package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
- package/src/__tests__/unit/transforms/merging.ts +374 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
- package/src/__tests__/unit/ui/RowControls.tsx +301 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
- package/src/__tests__/unit/undo-redo.ts +202 -0
- package/src/__tests__/unit/utils/dom.ts +286 -0
- package/src/__tests__/unit/utils/nodes.ts +59 -0
- package/src/__tests__/unit/utils/row-controls.ts +176 -0
- package/src/__tests__/unit/utils/table.ts +93 -0
- package/src/__tests__/unit/utils.ts +652 -0
- package/src/plugins/table/__tests__/unit/commands/insert.ts +2 -2
- package/src/plugins/table/__tests__/unit/commands.ts +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/TableComponent.tsx +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/table.ts +1 -0
- package/src/plugins/table/event-handlers.ts +5 -6
- package/src/plugins/table/nodeviews/table.tsx +7 -0
- package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
- package/src/plugins/table/nodeviews/types.ts +1 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
- package/src/plugins/table/toolbar.ts +0 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/TableFloatingControls/CornerControls/index.tsx +19 -1
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +16 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
- package/src/plugins/table/utils/column-controls.ts +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProsemirrorEditorFactory,
|
|
3
|
+
Preset,
|
|
4
|
+
LightEditorPlugin,
|
|
5
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
6
|
+
import {
|
|
7
|
+
doc,
|
|
8
|
+
table,
|
|
9
|
+
tr,
|
|
10
|
+
tdEmpty,
|
|
11
|
+
tdCursor,
|
|
12
|
+
DocBuilder,
|
|
13
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
14
|
+
import { TablePluginState } from '../../../plugins/table/types';
|
|
15
|
+
import { whenTableInFocus } from '../../../plugins/table/event-handlers';
|
|
16
|
+
import { setDragging } from '../../../plugins/table/pm-plugins/table-resizing/commands';
|
|
17
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
18
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
19
|
+
import { PluginKey } from 'prosemirror-state';
|
|
20
|
+
|
|
21
|
+
describe('event-handlers', () => {
|
|
22
|
+
let editor: any;
|
|
23
|
+
|
|
24
|
+
describe('#whenTableInFocus', () => {
|
|
25
|
+
describe('when allowColumnResizing is false', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
28
|
+
const preset = new Preset<LightEditorPlugin>().add([
|
|
29
|
+
tablePlugin,
|
|
30
|
+
{ tableOptions: { allowColumnResizing: false } },
|
|
31
|
+
]);
|
|
32
|
+
editor = (doc: DocBuilder) =>
|
|
33
|
+
createEditor<TablePluginState, PluginKey>({
|
|
34
|
+
doc,
|
|
35
|
+
preset,
|
|
36
|
+
pluginKey,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should not return false', () => {
|
|
41
|
+
const { editorView: view } = editor(
|
|
42
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
43
|
+
);
|
|
44
|
+
const fakeHandler = jest.fn();
|
|
45
|
+
fakeHandler.mockReturnValue(true);
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
const fakeMouseEvent = jest.fn() as Event;
|
|
48
|
+
|
|
49
|
+
const result = whenTableInFocus(fakeHandler);
|
|
50
|
+
|
|
51
|
+
expect(result(view, fakeMouseEvent)).not.toBeFalsy();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('when allowColumnResizing is true', () => {
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
58
|
+
const preset = new Preset<LightEditorPlugin>().add([
|
|
59
|
+
tablePlugin,
|
|
60
|
+
{ tableOptions: { allowColumnResizing: false } },
|
|
61
|
+
]);
|
|
62
|
+
editor = (doc: DocBuilder) =>
|
|
63
|
+
createEditor<TablePluginState, PluginKey>({
|
|
64
|
+
doc,
|
|
65
|
+
preset,
|
|
66
|
+
pluginKey,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('when dragging exists', () => {
|
|
71
|
+
it('should return false', () => {
|
|
72
|
+
const { editorView: view } = editor(
|
|
73
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
74
|
+
);
|
|
75
|
+
const fakeHandler = jest.fn();
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
const fakeMouseEvent = jest.fn() as Event;
|
|
78
|
+
|
|
79
|
+
setDragging({ startX: 0, startWidth: 0 })(view.state, view.dispatch);
|
|
80
|
+
|
|
81
|
+
const result = whenTableInFocus(fakeHandler);
|
|
82
|
+
|
|
83
|
+
expect(result(view, fakeMouseEvent)).toBeFalsy();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('when dragging is null', () => {
|
|
88
|
+
it('should not return false', () => {
|
|
89
|
+
const { editorView: view } = editor(
|
|
90
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
91
|
+
);
|
|
92
|
+
const fakeHandler = jest.fn();
|
|
93
|
+
fakeHandler.mockReturnValue(true);
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
const fakeMouseEvent = jest.fn() as Event;
|
|
96
|
+
|
|
97
|
+
setDragging(null)(view.state, view.dispatch);
|
|
98
|
+
|
|
99
|
+
const result = whenTableInFocus(fakeHandler);
|
|
100
|
+
|
|
101
|
+
expect(result(view, fakeMouseEvent)).not.toBeFalsy();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { MediaAttributes } from '@atlaskit/adf-schema';
|
|
2
|
+
import { TextSelection } from 'prosemirror-state';
|
|
3
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
4
|
+
import {
|
|
5
|
+
doc,
|
|
6
|
+
table,
|
|
7
|
+
td,
|
|
8
|
+
tr,
|
|
9
|
+
tdEmpty,
|
|
10
|
+
thEmpty,
|
|
11
|
+
tdCursor,
|
|
12
|
+
DocBuilder,
|
|
13
|
+
media,
|
|
14
|
+
mediaGroup,
|
|
15
|
+
p,
|
|
16
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
17
|
+
import { TablePluginState } from '../../plugins/table/types';
|
|
18
|
+
import {
|
|
19
|
+
handleMouseOver,
|
|
20
|
+
handleMouseMove,
|
|
21
|
+
handleClick,
|
|
22
|
+
} from '../../plugins/table/event-handlers';
|
|
23
|
+
import {
|
|
24
|
+
showInsertColumnButton,
|
|
25
|
+
addResizeHandleDecorations,
|
|
26
|
+
} from '../../plugins/table/commands';
|
|
27
|
+
import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
28
|
+
import tablePlugin from '../../plugins/table-plugin';
|
|
29
|
+
|
|
30
|
+
describe('table event handlers', () => {
|
|
31
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
32
|
+
const fakeGetEditorFeatureFlags = () => ({});
|
|
33
|
+
const editor = (doc: DocBuilder) =>
|
|
34
|
+
createEditor({
|
|
35
|
+
doc,
|
|
36
|
+
editorProps: {
|
|
37
|
+
allowTables: false,
|
|
38
|
+
media: {
|
|
39
|
+
allowMediaSingle: true,
|
|
40
|
+
allowMediaGroup: true,
|
|
41
|
+
},
|
|
42
|
+
dangerouslyAppendPlugins: {
|
|
43
|
+
__plugins: [tablePlugin()],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
pluginKey,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('#handleMouseOver', () => {
|
|
50
|
+
describe('when insert col/row button is hidden', () => {
|
|
51
|
+
it('should return false', () => {
|
|
52
|
+
const { editorView } = editor(
|
|
53
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
54
|
+
);
|
|
55
|
+
const { state } = editorView;
|
|
56
|
+
const cursorPos = 8;
|
|
57
|
+
editorView.dispatch(
|
|
58
|
+
state.tr.setSelection(
|
|
59
|
+
new TextSelection(state.doc.resolve(cursorPos)),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
const event = {
|
|
63
|
+
target: editorView.dom.querySelector('td'),
|
|
64
|
+
};
|
|
65
|
+
expect(handleMouseOver(editorView, event as MouseEvent)).toEqual(false);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('when insert col/row button is visible', () => {
|
|
70
|
+
it('should call hideInsertColumnOrRowButton when moving to the first cell', () => {
|
|
71
|
+
const { editorView, refs } = editor(
|
|
72
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
showInsertColumnButton(0)(editorView.state, editorView.dispatch);
|
|
76
|
+
|
|
77
|
+
const firstCell = editorView.domAtPos(refs['<>']);
|
|
78
|
+
const event = {
|
|
79
|
+
target: firstCell.node,
|
|
80
|
+
};
|
|
81
|
+
expect(handleMouseOver(editorView, event as any)).toEqual(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('#handleMouseMove', () => {
|
|
87
|
+
describe('when resize decoration has been set', () => {
|
|
88
|
+
it('should return false', () => {
|
|
89
|
+
const { editorView, refs } = editor(
|
|
90
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
91
|
+
);
|
|
92
|
+
const { state, dispatch } = editorView;
|
|
93
|
+
|
|
94
|
+
addResizeHandleDecorations(0)(state, dispatch);
|
|
95
|
+
|
|
96
|
+
const firstCell = editorView.domAtPos(refs['<>']);
|
|
97
|
+
const event = {
|
|
98
|
+
target: firstCell.node,
|
|
99
|
+
};
|
|
100
|
+
expect(
|
|
101
|
+
handleMouseMove(fakeGetEditorFeatureFlags)(editorView, event as any),
|
|
102
|
+
).toEqual(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('#handleClick', () => {
|
|
108
|
+
describe('clicking on media group node', () => {
|
|
109
|
+
describe('when on last cell of middle row', () => {
|
|
110
|
+
describe('when last element is media group node', () => {
|
|
111
|
+
it('should insert a new paragraph node', () => {
|
|
112
|
+
const testCollectionName = 'media-plugin-mock-collection-random-id';
|
|
113
|
+
const fileId = 'random-id';
|
|
114
|
+
const mediaAttrs: MediaAttributes = {
|
|
115
|
+
id: fileId,
|
|
116
|
+
type: 'file',
|
|
117
|
+
collection: testCollectionName,
|
|
118
|
+
};
|
|
119
|
+
const tableAttrs = { localId: 'table' };
|
|
120
|
+
|
|
121
|
+
const { editorView } = editor(
|
|
122
|
+
doc(
|
|
123
|
+
table(tableAttrs)(
|
|
124
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
125
|
+
tr(tdEmpty, tdEmpty, td()(mediaGroup(media(mediaAttrs)()))),
|
|
126
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
127
|
+
),
|
|
128
|
+
),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const firstCell = editorView.domAtPos(27);
|
|
132
|
+
const event = {
|
|
133
|
+
target: firstCell.node,
|
|
134
|
+
};
|
|
135
|
+
expect(handleClick(editorView, event as any)).toEqual(true);
|
|
136
|
+
|
|
137
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
138
|
+
doc(
|
|
139
|
+
table(tableAttrs)(
|
|
140
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
141
|
+
tr(
|
|
142
|
+
tdEmpty,
|
|
143
|
+
tdEmpty,
|
|
144
|
+
td()(mediaGroup(media(mediaAttrs)()), p()),
|
|
145
|
+
),
|
|
146
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
147
|
+
),
|
|
148
|
+
),
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('when last element is not media group node', () => {
|
|
154
|
+
it('should not insert a new paragraph node', () => {
|
|
155
|
+
const testCollectionName = 'media-plugin-mock-collection-random-id';
|
|
156
|
+
const fileId = 'random-id';
|
|
157
|
+
const mediaAttrs: MediaAttributes = {
|
|
158
|
+
id: fileId,
|
|
159
|
+
type: 'file',
|
|
160
|
+
collection: testCollectionName,
|
|
161
|
+
};
|
|
162
|
+
const tableAttrs = { localId: 'table' };
|
|
163
|
+
|
|
164
|
+
const { editorView } = editor(
|
|
165
|
+
doc(
|
|
166
|
+
table(tableAttrs)(
|
|
167
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
168
|
+
tr(
|
|
169
|
+
tdEmpty,
|
|
170
|
+
tdEmpty,
|
|
171
|
+
td()(mediaGroup(media(mediaAttrs)()), p()),
|
|
172
|
+
),
|
|
173
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
174
|
+
),
|
|
175
|
+
),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const firstCell = editorView.domAtPos(27);
|
|
179
|
+
const event = {
|
|
180
|
+
target: firstCell.node,
|
|
181
|
+
};
|
|
182
|
+
expect(handleClick(editorView, event as any)).toEqual(true);
|
|
183
|
+
|
|
184
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
185
|
+
doc(
|
|
186
|
+
table(tableAttrs)(
|
|
187
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
188
|
+
tr(
|
|
189
|
+
tdEmpty,
|
|
190
|
+
tdEmpty,
|
|
191
|
+
td()(mediaGroup(media(mediaAttrs)()), p()),
|
|
192
|
+
),
|
|
193
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
2
|
+
import {
|
|
3
|
+
doc,
|
|
4
|
+
p,
|
|
5
|
+
table,
|
|
6
|
+
tr,
|
|
7
|
+
td,
|
|
8
|
+
th,
|
|
9
|
+
DocBuilder,
|
|
10
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
11
|
+
import { TablePluginState, PluginConfig } from '../../plugins/table/types';
|
|
12
|
+
|
|
13
|
+
import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
14
|
+
import tablePlugin from '../../plugins/table-plugin';
|
|
15
|
+
const TABLE_LOCAL_ID = 'test-table-local-id';
|
|
16
|
+
|
|
17
|
+
describe('fix tables', () => {
|
|
18
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
global['fetch'] = jest.fn();
|
|
21
|
+
const createAnalyticsEvent = jest.fn();
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
createAnalyticsEvent.mockReset();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const editor = (doc: DocBuilder) => {
|
|
28
|
+
const tableOptions = {
|
|
29
|
+
allowNumberColumn: true,
|
|
30
|
+
allowHeaderRow: true,
|
|
31
|
+
allowHeaderColumn: true,
|
|
32
|
+
permittedLayouts: 'all',
|
|
33
|
+
allowColumnResizing: true,
|
|
34
|
+
} as PluginConfig;
|
|
35
|
+
|
|
36
|
+
return createEditor({
|
|
37
|
+
doc,
|
|
38
|
+
editorProps: {
|
|
39
|
+
dangerouslyAppendPlugins: {
|
|
40
|
+
__plugins: [
|
|
41
|
+
tablePlugin({
|
|
42
|
+
tableOptions,
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
allowAnalyticsGASV3: true,
|
|
47
|
+
},
|
|
48
|
+
pluginKey: tablePluginKey,
|
|
49
|
+
createAnalyticsEvent,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe('removeExtraneousColumnWidths', () => {
|
|
54
|
+
it('removes unnecessary column widths', () => {
|
|
55
|
+
const { editorView } = editor(
|
|
56
|
+
doc(
|
|
57
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
58
|
+
tr(
|
|
59
|
+
th({ colwidth: [100, 100] })(p('{<>}1')),
|
|
60
|
+
th({ colwidth: [100, 100] })(p('2')),
|
|
61
|
+
th({ colwidth: [480] })(p('3')),
|
|
62
|
+
),
|
|
63
|
+
tr(
|
|
64
|
+
td({ colwidth: [100, 100] })(p('4')),
|
|
65
|
+
td({ colwidth: [100, 100] })(p('5')),
|
|
66
|
+
td({ colwidth: [480] })(p('6')),
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
73
|
+
doc(
|
|
74
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
75
|
+
tr(
|
|
76
|
+
th({ colwidth: [100] })(p('1')),
|
|
77
|
+
th({ colwidth: [100] })(p('2')),
|
|
78
|
+
th({ colwidth: [480] })(p('3')),
|
|
79
|
+
),
|
|
80
|
+
tr(
|
|
81
|
+
td({ colwidth: [100] })(p('4')),
|
|
82
|
+
td({ colwidth: [100] })(p('5')),
|
|
83
|
+
td({ colwidth: [480] })(p('6')),
|
|
84
|
+
),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('cells with negative rowSpan', () => {
|
|
92
|
+
const TABLE_LOCAL_ID = 'test-table-2';
|
|
93
|
+
const SPAN_VALUE = -2;
|
|
94
|
+
it('should fire v3 analytics', () => {
|
|
95
|
+
editor(
|
|
96
|
+
doc(
|
|
97
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
98
|
+
tr(
|
|
99
|
+
td({ rowspan: SPAN_VALUE })(p('')),
|
|
100
|
+
td({})(p('')),
|
|
101
|
+
td({})(p('')),
|
|
102
|
+
),
|
|
103
|
+
tr(td({})(p('')), td({})(p('')), td({})(p(''))),
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(createAnalyticsEvent).toHaveBeenCalledWith(
|
|
109
|
+
expect.objectContaining({
|
|
110
|
+
action: 'invalidDocumentEncountered',
|
|
111
|
+
actionSubject: 'editor',
|
|
112
|
+
attributes: expect.objectContaining({
|
|
113
|
+
nodeType: 'tableCell',
|
|
114
|
+
reason: 'rowspan: negative value',
|
|
115
|
+
tableLocalId: TABLE_LOCAL_ID,
|
|
116
|
+
spanValue: SPAN_VALUE,
|
|
117
|
+
}),
|
|
118
|
+
eventType: 'operational',
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('cells with negative colSpan', () => {
|
|
125
|
+
const TABLE_LOCAL_ID = 'test-table-3';
|
|
126
|
+
const SPAN_VALUE = -2;
|
|
127
|
+
it('should fire v3 analytics', () => {
|
|
128
|
+
editor(
|
|
129
|
+
doc(
|
|
130
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
131
|
+
tr(
|
|
132
|
+
td({ colspan: SPAN_VALUE })(p('')),
|
|
133
|
+
td({})(p('')),
|
|
134
|
+
td({})(p('')),
|
|
135
|
+
),
|
|
136
|
+
tr(td({})(p('')), td({})(p('')), td({})(p(''))),
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
expect(createAnalyticsEvent).toHaveBeenCalledWith(
|
|
142
|
+
expect.objectContaining({
|
|
143
|
+
action: 'invalidDocumentEncountered',
|
|
144
|
+
actionSubject: 'editor',
|
|
145
|
+
attributes: expect.objectContaining({
|
|
146
|
+
nodeType: 'tableCell',
|
|
147
|
+
reason: 'colspan: negative value',
|
|
148
|
+
tableLocalId: TABLE_LOCAL_ID,
|
|
149
|
+
spanValue: SPAN_VALUE,
|
|
150
|
+
}),
|
|
151
|
+
eventType: 'operational',
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// TODO: still broken
|
|
2
|
+
import { PluginConfig } from '../../plugins/table/types';
|
|
3
|
+
import { setTextSelection } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
5
|
+
import {
|
|
6
|
+
doc,
|
|
7
|
+
p,
|
|
8
|
+
table,
|
|
9
|
+
tr,
|
|
10
|
+
td,
|
|
11
|
+
th,
|
|
12
|
+
DocBuilder,
|
|
13
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
14
|
+
import {
|
|
15
|
+
FloatingToolbarPluginState,
|
|
16
|
+
pluginKey as floatingToolbarPluginKey,
|
|
17
|
+
} from '@atlaskit/editor-core/src/plugins/floating-toolbar';
|
|
18
|
+
import { setEditorFocus } from '../../plugins/table/commands';
|
|
19
|
+
import { EditorState } from 'prosemirror-state';
|
|
20
|
+
import tablePlugin from '../../plugins/table-plugin';
|
|
21
|
+
|
|
22
|
+
describe('table floating toolbar', () => {
|
|
23
|
+
const createEditor = createEditorFactory();
|
|
24
|
+
|
|
25
|
+
const editor = (doc: DocBuilder) => {
|
|
26
|
+
const tableOptions = {
|
|
27
|
+
allowNumberColumn: true,
|
|
28
|
+
allowHeaderRow: true,
|
|
29
|
+
allowHeaderColumn: true,
|
|
30
|
+
permittedLayouts: 'all',
|
|
31
|
+
} as PluginConfig;
|
|
32
|
+
|
|
33
|
+
return createEditor({
|
|
34
|
+
doc,
|
|
35
|
+
editorProps: {
|
|
36
|
+
dangerouslyAppendPlugins: {
|
|
37
|
+
__plugins: [tablePlugin({ tableOptions })],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe('when selecting a cell', () => {
|
|
44
|
+
it('should contain the floating toolbar info within the first dispatch', () => {
|
|
45
|
+
const { editorView, onEditorViewStateUpdatedCallbacks } = editor(
|
|
46
|
+
doc(
|
|
47
|
+
p('te{<>}xt'),
|
|
48
|
+
table()(
|
|
49
|
+
tr(
|
|
50
|
+
th({ colwidth: [100, 100] })(p('1')),
|
|
51
|
+
th({ colwidth: [100, 100] })(p('2')),
|
|
52
|
+
th({ colwidth: [480] })(p('3')),
|
|
53
|
+
),
|
|
54
|
+
tr(
|
|
55
|
+
td({ colwidth: [100, 100] })(p('4')),
|
|
56
|
+
td({ colwidth: [100, 100] })(p('5')),
|
|
57
|
+
td({ colwidth: [480] })(p('6')),
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
setEditorFocus(true)(editorView.state, editorView.dispatch);
|
|
64
|
+
setTextSelection(editorView, 5);
|
|
65
|
+
|
|
66
|
+
const pluginStates: Array<{ config: any } | null | undefined> = [];
|
|
67
|
+
|
|
68
|
+
const mock = jest.fn(
|
|
69
|
+
({ newEditorState }: { newEditorState: EditorState }) => {
|
|
70
|
+
const { getConfigWithNodeInfo } = floatingToolbarPluginKey.getState(
|
|
71
|
+
newEditorState,
|
|
72
|
+
) as FloatingToolbarPluginState;
|
|
73
|
+
pluginStates.push(getConfigWithNodeInfo(editorView.state));
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
onEditorViewStateUpdatedCallbacks.push({
|
|
78
|
+
pluginName: 'listener',
|
|
79
|
+
callback: mock,
|
|
80
|
+
});
|
|
81
|
+
setTextSelection(editorView, 9);
|
|
82
|
+
|
|
83
|
+
expect(pluginStates).toHaveLength(2);
|
|
84
|
+
// Inner dispatch for #findTable
|
|
85
|
+
const firstCall = pluginStates[0];
|
|
86
|
+
expect(firstCall).toBeTruthy();
|
|
87
|
+
expect(firstCall!.config).toBeTruthy();
|
|
88
|
+
|
|
89
|
+
// Outer dispatch for selection change
|
|
90
|
+
const secondCall = pluginStates[1];
|
|
91
|
+
expect(secondCall).toBeTruthy();
|
|
92
|
+
expect(secondCall!.config).toBeTruthy();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createProsemirrorEditorFactory,
|
|
5
|
+
Preset,
|
|
6
|
+
LightEditorPlugin,
|
|
7
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
8
|
+
import {
|
|
9
|
+
doc,
|
|
10
|
+
table,
|
|
11
|
+
tr,
|
|
12
|
+
tdEmpty,
|
|
13
|
+
tdCursor,
|
|
14
|
+
DocBuilder,
|
|
15
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
16
|
+
import { TablePluginState } from '../../plugins/table/types';
|
|
17
|
+
import { handleDocOrSelectionChanged } from '../../plugins/table/handlers';
|
|
18
|
+
import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
19
|
+
import { defaultTableSelection } from '../../plugins/table/pm-plugins/default-table-selection';
|
|
20
|
+
import tablePlugin from '../../plugins/table-plugin';
|
|
21
|
+
|
|
22
|
+
describe('table action handlers', () => {
|
|
23
|
+
let editor: any;
|
|
24
|
+
let defaultPluginState: any;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
28
|
+
const preset = new Preset<LightEditorPlugin>().add(tablePlugin);
|
|
29
|
+
|
|
30
|
+
editor = (doc: DocBuilder) =>
|
|
31
|
+
createEditor<TablePluginState, PluginKey>({
|
|
32
|
+
doc,
|
|
33
|
+
preset,
|
|
34
|
+
pluginKey,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
defaultPluginState = {
|
|
38
|
+
...defaultTableSelection,
|
|
39
|
+
pluginConfig: {},
|
|
40
|
+
editorHasFocus: true,
|
|
41
|
+
isNumberColumnEnabled: false,
|
|
42
|
+
isHeaderColumnEnabled: false,
|
|
43
|
+
isHeaderRowEnabled: false,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('#handleDocOrSelectionChanged', () => {
|
|
48
|
+
it('should return a new state with updated tableNode prop and reset selection', () => {
|
|
49
|
+
const pluginState = {
|
|
50
|
+
...defaultPluginState,
|
|
51
|
+
hoveredColumns: [1, 2, 3],
|
|
52
|
+
hoveredRows: [1, 2, 3],
|
|
53
|
+
isInDanger: true,
|
|
54
|
+
tableNode: undefined,
|
|
55
|
+
targetCellPosition: undefined,
|
|
56
|
+
ordering: undefined,
|
|
57
|
+
resizeHandleColumnIndex: undefined,
|
|
58
|
+
};
|
|
59
|
+
const { editorView } = editor(
|
|
60
|
+
doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
|
|
61
|
+
);
|
|
62
|
+
const { state } = editorView;
|
|
63
|
+
const cursorPos = 8;
|
|
64
|
+
editorView.dispatch(
|
|
65
|
+
state.tr.setSelection(new TextSelection(state.doc.resolve(cursorPos))),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const newState = handleDocOrSelectionChanged(
|
|
69
|
+
editorView.state.tr,
|
|
70
|
+
pluginState,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(newState).toEqual({
|
|
74
|
+
...pluginState,
|
|
75
|
+
...defaultTableSelection,
|
|
76
|
+
tableNode: editorView.state.doc.firstChild,
|
|
77
|
+
targetCellPosition: cursorPos - 2,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|