@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,652 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProsemirrorEditorFactory,
|
|
3
|
+
Preset,
|
|
4
|
+
LightEditorPlugin,
|
|
5
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
6
|
+
import {
|
|
7
|
+
doc,
|
|
8
|
+
p,
|
|
9
|
+
table,
|
|
10
|
+
tr,
|
|
11
|
+
td,
|
|
12
|
+
tdCursor,
|
|
13
|
+
tdEmpty,
|
|
14
|
+
DocBuilder,
|
|
15
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
16
|
+
import { TablePluginState } from '../../plugins/table/types';
|
|
17
|
+
import {
|
|
18
|
+
getRowHeights,
|
|
19
|
+
isColumnDeleteButtonVisible,
|
|
20
|
+
isRowDeleteButtonVisible,
|
|
21
|
+
getColumnDeleteButtonParams,
|
|
22
|
+
getRowDeleteButtonParams,
|
|
23
|
+
getRowsParams,
|
|
24
|
+
getColumnClassNames,
|
|
25
|
+
getRowClassNames,
|
|
26
|
+
} from '../../plugins/table/utils';
|
|
27
|
+
import { getColumnsWidths } from '../../plugins/table/utils/column-controls';
|
|
28
|
+
import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
29
|
+
import tablePlugin from '../../plugins/table';
|
|
30
|
+
import { PluginKey } from 'prosemirror-state';
|
|
31
|
+
|
|
32
|
+
describe('table plugin: utils', () => {
|
|
33
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
34
|
+
const preset = new Preset<LightEditorPlugin>().add(tablePlugin);
|
|
35
|
+
|
|
36
|
+
const editor = (doc: DocBuilder) =>
|
|
37
|
+
createEditor<TablePluginState, PluginKey>({
|
|
38
|
+
doc,
|
|
39
|
+
preset,
|
|
40
|
+
pluginKey,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('#getColumnsWidths', () => {
|
|
44
|
+
describe('when columns are not merged', () => {
|
|
45
|
+
it('should return an array of widths of all columns', () => {
|
|
46
|
+
const { editorView } = editor(
|
|
47
|
+
doc(
|
|
48
|
+
p('text'),
|
|
49
|
+
table()(
|
|
50
|
+
tr(td({})(p('a1')), td({})(p('a2'))),
|
|
51
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
const columnsWidths = getColumnsWidths(editorView);
|
|
56
|
+
columnsWidths.forEach((width) => {
|
|
57
|
+
expect(typeof width).toEqual('number');
|
|
58
|
+
expect(width && width > 0).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('when columns are merged', () => {
|
|
64
|
+
describe('when merged column has cells', () => {
|
|
65
|
+
it('should return an array of widths of all columns', () => {
|
|
66
|
+
const { editorView } = editor(
|
|
67
|
+
doc(
|
|
68
|
+
p('text'),
|
|
69
|
+
table()(
|
|
70
|
+
tr(td({ colspan: 2 })(p('a1')), td({})(p('a3'))),
|
|
71
|
+
tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'))),
|
|
72
|
+
),
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
const columnsWidths = getColumnsWidths(editorView);
|
|
76
|
+
expect(columnsWidths).toEqual([1, undefined, 1]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('#getRowHeights', () => {
|
|
83
|
+
describe('when rows are not merged', () => {
|
|
84
|
+
it('should return an array of heights of all rows', () => {
|
|
85
|
+
const { editorView } = editor(
|
|
86
|
+
doc(
|
|
87
|
+
p('text'),
|
|
88
|
+
table()(
|
|
89
|
+
tr(td({})(p('a1')), td({})(p('a2'))),
|
|
90
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
const tableRef = editorView.dom.querySelector('table')!;
|
|
95
|
+
const rowHeights = getRowHeights(tableRef);
|
|
96
|
+
rowHeights.forEach((height) => {
|
|
97
|
+
expect(typeof height).toEqual('number');
|
|
98
|
+
expect(height > 0).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('when rows are merged', () => {
|
|
104
|
+
describe('when merged row has cells', () => {
|
|
105
|
+
it('should return an array of heights of all rows', () => {
|
|
106
|
+
const { editorView } = editor(
|
|
107
|
+
doc(
|
|
108
|
+
p('text'),
|
|
109
|
+
table()(
|
|
110
|
+
tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'))),
|
|
111
|
+
tr(td({})(p('b2'))),
|
|
112
|
+
),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
const tableRef = editorView.dom.querySelector('table')!;
|
|
116
|
+
const rowHeights = getRowHeights(tableRef);
|
|
117
|
+
|
|
118
|
+
rowHeights.forEach((height) => {
|
|
119
|
+
expect(typeof height).toEqual('number');
|
|
120
|
+
expect(height > 0).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('#isColumnDeleteButtonVisible', () => {
|
|
128
|
+
describe('when selection is a TextSelection', () => {
|
|
129
|
+
it('should return false', () => {
|
|
130
|
+
const { editorView } = editor(
|
|
131
|
+
doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
132
|
+
);
|
|
133
|
+
expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
134
|
+
false,
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('when selection is a CellSelection', () => {
|
|
139
|
+
describe('when no columns are fully selected', () => {
|
|
140
|
+
it('should return false', () => {
|
|
141
|
+
const { editorView } = editor(
|
|
142
|
+
doc(
|
|
143
|
+
p('text'),
|
|
144
|
+
table()(
|
|
145
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
146
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}b3'))),
|
|
147
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
153
|
+
false,
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
describe('when a column is selected', () => {
|
|
158
|
+
it('should return true', () => {
|
|
159
|
+
const { editorView } = editor(
|
|
160
|
+
doc(
|
|
161
|
+
p('text'),
|
|
162
|
+
table()(
|
|
163
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
164
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
165
|
+
tr(td({})(p('{cell>}c1')), tdEmpty, tdEmpty),
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
171
|
+
true,
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe('when table is selected', () => {
|
|
176
|
+
it('should return false', () => {
|
|
177
|
+
const { editorView } = editor(
|
|
178
|
+
doc(
|
|
179
|
+
p('text'),
|
|
180
|
+
table()(
|
|
181
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
182
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
183
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
184
|
+
),
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
189
|
+
false,
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('#isRowDeleteButtonVisible', () => {
|
|
197
|
+
describe('when selection is a TextSelection', () => {
|
|
198
|
+
it('should return false', () => {
|
|
199
|
+
const { editorView } = editor(
|
|
200
|
+
doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
201
|
+
);
|
|
202
|
+
expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
203
|
+
false,
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe('when selection is a CellSelection', () => {
|
|
208
|
+
describe('when no rows are fully selected', () => {
|
|
209
|
+
it('should return false', () => {
|
|
210
|
+
const { editorView } = editor(
|
|
211
|
+
doc(
|
|
212
|
+
p('text'),
|
|
213
|
+
table()(
|
|
214
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
215
|
+
tr(tdEmpty, td({})(p('{cell>}b3')), tdEmpty),
|
|
216
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
217
|
+
),
|
|
218
|
+
),
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
222
|
+
false,
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
describe('when a row is selected', () => {
|
|
227
|
+
it('should return true', () => {
|
|
228
|
+
const { editorView } = editor(
|
|
229
|
+
doc(
|
|
230
|
+
p('text'),
|
|
231
|
+
table()(
|
|
232
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, td({})(p('{cell>}a1'))),
|
|
233
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
234
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
235
|
+
),
|
|
236
|
+
),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
240
|
+
true,
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
describe('when table is selected', () => {
|
|
245
|
+
it('should return false', () => {
|
|
246
|
+
const { editorView } = editor(
|
|
247
|
+
doc(
|
|
248
|
+
p('text'),
|
|
249
|
+
table()(
|
|
250
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
251
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
252
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
253
|
+
),
|
|
254
|
+
),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
|
|
258
|
+
false,
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe('#getColumnDeleteButtonParams', () => {
|
|
266
|
+
describe('when selection is a TextSelection', () => {
|
|
267
|
+
it('should return null', () => {
|
|
268
|
+
const { editorView } = editor(
|
|
269
|
+
doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
270
|
+
);
|
|
271
|
+
const columnsWidths = [100, 150, 200];
|
|
272
|
+
expect(
|
|
273
|
+
getColumnDeleteButtonParams(
|
|
274
|
+
columnsWidths,
|
|
275
|
+
editorView.state.selection,
|
|
276
|
+
),
|
|
277
|
+
).toBe(null);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
describe('when selection is a CellSelection and 3 columns are selected', () => {
|
|
281
|
+
describe('columnsWidths = [100, 150, 200]', () => {
|
|
282
|
+
it('should return indexes = [0, 1, 2]', () => {
|
|
283
|
+
const { editorView } = editor(
|
|
284
|
+
doc(
|
|
285
|
+
p('text'),
|
|
286
|
+
table()(
|
|
287
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty, tdEmpty),
|
|
288
|
+
tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
|
|
289
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3')), tdEmpty),
|
|
290
|
+
),
|
|
291
|
+
),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const columnsWidths = [100, 150, 200];
|
|
295
|
+
const { indexes, left } = getColumnDeleteButtonParams(
|
|
296
|
+
columnsWidths,
|
|
297
|
+
editorView.state.selection,
|
|
298
|
+
)!;
|
|
299
|
+
expect(indexes).toEqual([0, 1, 2]);
|
|
300
|
+
expect(left > 0).toBe(true);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('#getRowDeleteButtonParams', () => {
|
|
307
|
+
describe('when selection is a TextSelection', () => {
|
|
308
|
+
it('should return null', () => {
|
|
309
|
+
const { editorView } = editor(
|
|
310
|
+
doc(
|
|
311
|
+
p('text'),
|
|
312
|
+
table()(
|
|
313
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
314
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
315
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
316
|
+
),
|
|
317
|
+
),
|
|
318
|
+
);
|
|
319
|
+
const rowsHeights = [100, 150, 200];
|
|
320
|
+
expect(
|
|
321
|
+
getRowDeleteButtonParams(rowsHeights, editorView.state.selection),
|
|
322
|
+
).toBe(null);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
describe('when selection is a CellSelection and 3 rows are selected', () => {
|
|
326
|
+
describe('rowsHeights = [100, 150, 200]', () => {
|
|
327
|
+
it('should return indexes = [0, 1, 2]', () => {
|
|
328
|
+
const { editorView } = editor(
|
|
329
|
+
doc(
|
|
330
|
+
p('text'),
|
|
331
|
+
table()(
|
|
332
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
333
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
334
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
335
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
336
|
+
),
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
const rowsHeights = [100, 150, 200];
|
|
341
|
+
const { indexes, top } = getRowDeleteButtonParams(
|
|
342
|
+
rowsHeights,
|
|
343
|
+
editorView.state.selection,
|
|
344
|
+
)!;
|
|
345
|
+
expect(indexes).toEqual([0, 1, 2]);
|
|
346
|
+
expect(top > 0).toBe(true);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
describe('rowsHeights = [100, ,150, ,200]', () => {
|
|
350
|
+
it('should return indexes = [0, 1, 2]', () => {
|
|
351
|
+
const { editorView } = editor(
|
|
352
|
+
doc(
|
|
353
|
+
p('text'),
|
|
354
|
+
table()(
|
|
355
|
+
tr(
|
|
356
|
+
td({ rowspan: 2 })(p('{<cell}a1')),
|
|
357
|
+
td({ rowspan: 2 })(p('a2')),
|
|
358
|
+
td({ rowspan: 2 })(p('a3')),
|
|
359
|
+
),
|
|
360
|
+
tr(
|
|
361
|
+
td({ rowspan: 2 })(p('c1')),
|
|
362
|
+
td({ rowspan: 2 })(p('c2')),
|
|
363
|
+
td({ rowspan: 2 })(p('{cell>}c3')),
|
|
364
|
+
),
|
|
365
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
366
|
+
),
|
|
367
|
+
),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const rowsHeights = [100, , 150, , 200];
|
|
371
|
+
const { indexes, top } = getRowDeleteButtonParams(
|
|
372
|
+
rowsHeights,
|
|
373
|
+
editorView.state.selection,
|
|
374
|
+
)!;
|
|
375
|
+
expect(indexes).toEqual([0, 2]);
|
|
376
|
+
expect(top > 0).toBe(true);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
describe('#getRowsParams', () => {
|
|
383
|
+
describe('rowHeights = [100, 150, 200]', () => {
|
|
384
|
+
it('should return consecutive indexes', () => {
|
|
385
|
+
const rowHeights = [100, 150, 200];
|
|
386
|
+
const rows = getRowsParams(rowHeights);
|
|
387
|
+
rows.forEach((row, index) => {
|
|
388
|
+
expect(row.startIndex).toEqual(index);
|
|
389
|
+
expect(row.endIndex).toEqual(index + 1);
|
|
390
|
+
expect(row.height).toEqual(rowHeights[index]);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
describe('rowHeights = [100, ,150, ,200]', () => {
|
|
395
|
+
it('should return correct indexes', () => {
|
|
396
|
+
const rowHeights = [100, , 150, , 200];
|
|
397
|
+
const rows = getRowsParams(rowHeights);
|
|
398
|
+
const expectedIndexes = [0, 2, 4, 5];
|
|
399
|
+
for (let i = 0, count = rows.length; i < count; i++) {
|
|
400
|
+
const row = rows[i];
|
|
401
|
+
expect(row.startIndex).toEqual(expectedIndexes[i]);
|
|
402
|
+
expect(row.endIndex).toEqual(expectedIndexes[i + 1]);
|
|
403
|
+
expect(row.height).toEqual(rowHeights[expectedIndexes[i]]);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
describe('#getColumnClassNames', () => {
|
|
410
|
+
describe('when selection is a TextSelection', () => {
|
|
411
|
+
[[0], [1], [2], [0, 1], [1, 2], [0, 2]].forEach((hoveredColumns) => {
|
|
412
|
+
describe(`when hoveredColumns = ${hoveredColumns}`, () => {
|
|
413
|
+
it('return a string containing "active" substring', () => {
|
|
414
|
+
const { editorView } = editor(
|
|
415
|
+
doc(
|
|
416
|
+
p('text'),
|
|
417
|
+
table()(
|
|
418
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
419
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
420
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
421
|
+
),
|
|
422
|
+
),
|
|
423
|
+
);
|
|
424
|
+
const isInDanger = false;
|
|
425
|
+
const classNames = getColumnClassNames(
|
|
426
|
+
hoveredColumns[0],
|
|
427
|
+
editorView.state.selection,
|
|
428
|
+
hoveredColumns,
|
|
429
|
+
isInDanger,
|
|
430
|
+
);
|
|
431
|
+
expect(classNames.indexOf('active') > -1).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
describe('when isInDanger = true', () => {
|
|
434
|
+
it('return a string containing "danger" substring', () => {
|
|
435
|
+
const { editorView } = editor(
|
|
436
|
+
doc(
|
|
437
|
+
p('text'),
|
|
438
|
+
table()(
|
|
439
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
440
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
441
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
442
|
+
),
|
|
443
|
+
),
|
|
444
|
+
);
|
|
445
|
+
const isInDanger = true;
|
|
446
|
+
const classNames = getColumnClassNames(
|
|
447
|
+
hoveredColumns[0],
|
|
448
|
+
editorView.state.selection,
|
|
449
|
+
hoveredColumns,
|
|
450
|
+
isInDanger,
|
|
451
|
+
);
|
|
452
|
+
expect(classNames.indexOf('danger') > -1).toBe(true);
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
describe('when selection is a CellSelection', () => {
|
|
459
|
+
describe('when no columns are fully selected', () => {
|
|
460
|
+
it('should return an empty string', () => {
|
|
461
|
+
const { editorView } = editor(
|
|
462
|
+
doc(
|
|
463
|
+
p('text'),
|
|
464
|
+
table()(
|
|
465
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
466
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}b3'))),
|
|
467
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
468
|
+
),
|
|
469
|
+
),
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
const classNames = getColumnClassNames(
|
|
473
|
+
0,
|
|
474
|
+
editorView.state.selection,
|
|
475
|
+
[],
|
|
476
|
+
false,
|
|
477
|
+
);
|
|
478
|
+
expect(classNames).toBe('');
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
describe('when a column is selected', () => {
|
|
482
|
+
it('return a string containing "active" substring', () => {
|
|
483
|
+
const { editorView } = editor(
|
|
484
|
+
doc(
|
|
485
|
+
p('text'),
|
|
486
|
+
table()(
|
|
487
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
488
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
489
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
490
|
+
),
|
|
491
|
+
),
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
[0, 1, 2].forEach((index) => {
|
|
495
|
+
const classNames = getColumnClassNames(
|
|
496
|
+
index,
|
|
497
|
+
editorView.state.selection,
|
|
498
|
+
[],
|
|
499
|
+
false,
|
|
500
|
+
);
|
|
501
|
+
expect(classNames.indexOf('active') > -1).toBe(true);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
describe('when isInDanger = true', () => {
|
|
505
|
+
it('return a string containing "danger" substring', () => {
|
|
506
|
+
const { editorView } = editor(
|
|
507
|
+
doc(
|
|
508
|
+
p('text'),
|
|
509
|
+
table()(
|
|
510
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
511
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
512
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
513
|
+
),
|
|
514
|
+
),
|
|
515
|
+
);
|
|
516
|
+
[0, 1, 2].forEach((index) => {
|
|
517
|
+
const classNames = getColumnClassNames(
|
|
518
|
+
index,
|
|
519
|
+
editorView.state.selection,
|
|
520
|
+
[],
|
|
521
|
+
true,
|
|
522
|
+
);
|
|
523
|
+
expect(classNames.indexOf('danger') > -1).toBe(true);
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
describe('#getRowClassNames', () => {
|
|
532
|
+
describe('when selection is a TextSelection', () => {
|
|
533
|
+
[[0], [1], [2], [0, 1], [1, 2], [0, 2]].forEach((hoveredRows) => {
|
|
534
|
+
describe(`when hoveredRows = ${hoveredRows}`, () => {
|
|
535
|
+
it('return a string containing "active" substring', () => {
|
|
536
|
+
const { editorView } = editor(
|
|
537
|
+
doc(
|
|
538
|
+
p('text'),
|
|
539
|
+
table()(
|
|
540
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
541
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
542
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
543
|
+
),
|
|
544
|
+
),
|
|
545
|
+
);
|
|
546
|
+
const isInDanger = false;
|
|
547
|
+
const classNames = getRowClassNames(
|
|
548
|
+
hoveredRows[0],
|
|
549
|
+
editorView.state.selection,
|
|
550
|
+
hoveredRows,
|
|
551
|
+
isInDanger,
|
|
552
|
+
);
|
|
553
|
+
expect(classNames.indexOf('active') > -1).toBe(true);
|
|
554
|
+
});
|
|
555
|
+
describe('when isInDanger = true', () => {
|
|
556
|
+
it('return a string containing "danger" substring', () => {
|
|
557
|
+
const { editorView } = editor(
|
|
558
|
+
doc(
|
|
559
|
+
p('text'),
|
|
560
|
+
table()(
|
|
561
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
562
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
563
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
564
|
+
),
|
|
565
|
+
),
|
|
566
|
+
);
|
|
567
|
+
const isInDanger = true;
|
|
568
|
+
const classNames = getRowClassNames(
|
|
569
|
+
hoveredRows[0],
|
|
570
|
+
editorView.state.selection,
|
|
571
|
+
hoveredRows,
|
|
572
|
+
isInDanger,
|
|
573
|
+
);
|
|
574
|
+
expect(classNames.indexOf('danger') > -1).toBe(true);
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
describe('when selection is a CellSelection', () => {
|
|
581
|
+
describe('when no rows are fully selected', () => {
|
|
582
|
+
it('should return an empty string', () => {
|
|
583
|
+
const { editorView } = editor(
|
|
584
|
+
doc(
|
|
585
|
+
p('text'),
|
|
586
|
+
table()(
|
|
587
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
588
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
589
|
+
tr(tdEmpty, td({})(p('{cell>}c3')), tdEmpty),
|
|
590
|
+
),
|
|
591
|
+
),
|
|
592
|
+
);
|
|
593
|
+
|
|
594
|
+
const classNames = getRowClassNames(
|
|
595
|
+
0,
|
|
596
|
+
editorView.state.selection,
|
|
597
|
+
[],
|
|
598
|
+
false,
|
|
599
|
+
);
|
|
600
|
+
expect(classNames).toBe('');
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
describe('when a row is selected', () => {
|
|
604
|
+
it('return a string containing "active" substring', () => {
|
|
605
|
+
const { editorView } = editor(
|
|
606
|
+
doc(
|
|
607
|
+
p('text'),
|
|
608
|
+
table()(
|
|
609
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
610
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
611
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
612
|
+
),
|
|
613
|
+
),
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
[0, 1, 2].forEach((index) => {
|
|
617
|
+
const classNames = getRowClassNames(
|
|
618
|
+
index,
|
|
619
|
+
editorView.state.selection,
|
|
620
|
+
[],
|
|
621
|
+
false,
|
|
622
|
+
);
|
|
623
|
+
expect(classNames.indexOf('active') > -1).toBe(true);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
describe('when isInDanger = true', () => {
|
|
627
|
+
it('return a string containing "danger" substring', () => {
|
|
628
|
+
const { editorView } = editor(
|
|
629
|
+
doc(
|
|
630
|
+
p('text'),
|
|
631
|
+
table()(
|
|
632
|
+
tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
|
|
633
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
634
|
+
tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
|
|
635
|
+
),
|
|
636
|
+
),
|
|
637
|
+
);
|
|
638
|
+
[0, 1, 2].forEach((index) => {
|
|
639
|
+
const classNames = getRowClassNames(
|
|
640
|
+
index,
|
|
641
|
+
editorView.state.selection,
|
|
642
|
+
[],
|
|
643
|
+
true,
|
|
644
|
+
);
|
|
645
|
+
expect(classNames.indexOf('danger') > -1).toBe(true);
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
});
|
|
@@ -53,7 +53,7 @@ describe('table plugin: insert', () => {
|
|
|
53
53
|
pluginKey,
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
it('does scale cells in tables which are not overflowing', () => {
|
|
57
57
|
const { editorView } = editor(
|
|
58
58
|
doc(
|
|
59
59
|
table({ localId: TABLE_LOCAL_ID })(
|
|
@@ -84,7 +84,7 @@ describe('table plugin: insert', () => {
|
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
it('does not scale cells in tables which are overflowing', () => {
|
|
88
88
|
const { editorView } = editor(
|
|
89
89
|
doc(
|
|
90
90
|
table({ localId: TABLE_LOCAL_ID })(
|
|
@@ -810,7 +810,7 @@ describe('table plugin: actions', () => {
|
|
|
810
810
|
* | th | th | th |
|
|
811
811
|
* | th | td | td |
|
|
812
812
|
*/
|
|
813
|
-
|
|
813
|
+
it('should keep right row header and cells after split', () => {
|
|
814
814
|
const { editorView } = editor(
|
|
815
815
|
doc(
|
|
816
816
|
table()(
|
|
@@ -833,7 +833,7 @@ describe('table plugin: actions', () => {
|
|
|
833
833
|
);
|
|
834
834
|
});
|
|
835
835
|
|
|
836
|
-
|
|
836
|
+
it('should split cell with media selected', () => {
|
|
837
837
|
const { editorView } = editor(
|
|
838
838
|
doc(
|
|
839
839
|
table()(
|
|
@@ -259,7 +259,7 @@ describe('table -> nodeviews -> TableComponent.tsx', () => {
|
|
|
259
259
|
return { wrapper, view };
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
describe('with
|
|
262
|
+
describe('with optimization on', () => {
|
|
263
263
|
let wrapper: ReactWrapper;
|
|
264
264
|
beforeEach(() => {
|
|
265
265
|
wrapper = setupTable(true).wrapper;
|
|
@@ -306,7 +306,7 @@ describe('table -> nodeviews -> TableComponent.tsx', () => {
|
|
|
306
306
|
});
|
|
307
307
|
});
|
|
308
308
|
|
|
309
|
-
describe('with
|
|
309
|
+
describe('with optimization off', () => {
|
|
310
310
|
let wrapper: ReactWrapper;
|
|
311
311
|
beforeEach(() => {
|
|
312
312
|
wrapper = setupTable(false).wrapper;
|