@atlaskit/editor-plugin-table 5.4.12 → 5.4.14
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/event-handlers.js +10 -4
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +7 -5
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -0
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- package/dist/cjs/plugins/table/utils/column-controls.js +63 -1
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/es2019/plugins/table/event-handlers.js +11 -5
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +8 -6
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -0
- package/dist/es2019/plugins/table/ui/common-styles.js +6 -4
- package/dist/es2019/plugins/table/utils/column-controls.js +62 -0
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/event-handlers.js +11 -5
- package/dist/esm/plugins/table/ui/DragHandle/index.js +7 -5
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +2 -0
- package/dist/esm/plugins/table/ui/common-styles.js +1 -1
- package/dist/esm/plugins/table/utils/column-controls.js +62 -0
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/types/plugins/table/utils/column-controls.d.ts +3 -0
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/utils/column-controls.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/__tests__/unit/utils/column-controls.ts +145 -1
- package/src/plugins/table/event-handlers.ts +22 -4
- package/src/plugins/table/ui/DragHandle/index.tsx +7 -7
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +2 -0
- package/src/plugins/table/ui/common-styles.ts +6 -4
- package/src/plugins/table/utils/column-controls.ts +81 -0
- package/src/plugins/table/utils/index.ts +2 -0
- package/src/__tests__/integration/block-node-selection.ts +0 -165
|
@@ -217,3 +217,84 @@ export const colWidthsForRow = (tr: HTMLTableRowElement) => {
|
|
|
217
217
|
|
|
218
218
|
return pctWidths.map((pct) => `${pct}%`).join(' ');
|
|
219
219
|
};
|
|
220
|
+
|
|
221
|
+
export const convertHTMLCellIndexToColumnIndex = (
|
|
222
|
+
htmlColIndex: number,
|
|
223
|
+
htmlRowIndex: number,
|
|
224
|
+
tableMap: TableMap,
|
|
225
|
+
): number => {
|
|
226
|
+
// Same numbers (positions) in tableMap.map array mean that there are merged cells.
|
|
227
|
+
// Cells can be merged across columns. So we need to check if the cell on the left and current cell have the same value.
|
|
228
|
+
// Cells can be merged acroll rows. So we need to check if the cell above has the same value as current cell.
|
|
229
|
+
// When cell has the same value as the cell above it or the cell to the left of it, html cellIndex won't count it a separete column.
|
|
230
|
+
const width = tableMap.width;
|
|
231
|
+
const map = tableMap.map;
|
|
232
|
+
let htmlColCount = 0;
|
|
233
|
+
|
|
234
|
+
if (htmlRowIndex === 0) {
|
|
235
|
+
for (let colIndex = 0; colIndex < width; colIndex++) {
|
|
236
|
+
if (colIndex === 0 || map[colIndex] !== map[colIndex - 1]) {
|
|
237
|
+
htmlColCount++;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (htmlColCount - 1 === htmlColIndex) {
|
|
241
|
+
return colIndex;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
for (let colIndex = 0; colIndex < width; colIndex++) {
|
|
246
|
+
const currentCellMapIndex = htmlRowIndex * width + colIndex;
|
|
247
|
+
const cellAboveMapIndex = (htmlRowIndex - 1) * width + colIndex;
|
|
248
|
+
if (colIndex > 0) {
|
|
249
|
+
if (
|
|
250
|
+
map[currentCellMapIndex] !== map[currentCellMapIndex - 1] &&
|
|
251
|
+
map[currentCellMapIndex] !== map[cellAboveMapIndex]
|
|
252
|
+
) {
|
|
253
|
+
htmlColCount++;
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
if (map[currentCellMapIndex] !== map[cellAboveMapIndex]) {
|
|
257
|
+
htmlColCount++;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (htmlColCount - 1 === htmlColIndex) {
|
|
262
|
+
return colIndex;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return 0;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// When first row has merged cells, our converted column index needs to be mapped.
|
|
271
|
+
export const getColumnIndexMappedToColumnIndexInFirstRow = (
|
|
272
|
+
convertedColIndex: number,
|
|
273
|
+
htmlRowIndex: number,
|
|
274
|
+
tableMap: TableMap,
|
|
275
|
+
): number => {
|
|
276
|
+
const width = tableMap.width;
|
|
277
|
+
const map = tableMap.map;
|
|
278
|
+
const mapColIndexToFistRowColIndex = [];
|
|
279
|
+
let htmlColCounFirstRow = 0;
|
|
280
|
+
let colSpan = 0;
|
|
281
|
+
|
|
282
|
+
if (htmlRowIndex === 0) {
|
|
283
|
+
return convertedColIndex;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
for (let colIndex = 0; colIndex < width; colIndex++) {
|
|
287
|
+
if (colIndex === 0 || map[colIndex] !== map[colIndex - 1]) {
|
|
288
|
+
if (colSpan > 0) {
|
|
289
|
+
htmlColCounFirstRow += colSpan;
|
|
290
|
+
colSpan = 0;
|
|
291
|
+
}
|
|
292
|
+
htmlColCounFirstRow++;
|
|
293
|
+
} else if (map[colIndex] === map[colIndex - 1]) {
|
|
294
|
+
colSpan++;
|
|
295
|
+
}
|
|
296
|
+
mapColIndexToFistRowColIndex[colIndex] = htmlColCounFirstRow - 1;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return mapColIndexToFistRowColIndex[convertedColIndex];
|
|
300
|
+
};
|
|
@@ -59,10 +59,12 @@ export {
|
|
|
59
59
|
hasResizeHandler,
|
|
60
60
|
} from './dom';
|
|
61
61
|
export {
|
|
62
|
+
convertHTMLCellIndexToColumnIndex,
|
|
62
63
|
getColumnsWidths,
|
|
63
64
|
isColumnDeleteButtonVisible,
|
|
64
65
|
getColumnDeleteButtonParams,
|
|
65
66
|
getColumnClassNames,
|
|
67
|
+
getColumnIndexMappedToColumnIndexInFirstRow,
|
|
66
68
|
} from './column-controls';
|
|
67
69
|
export {
|
|
68
70
|
getRowHeights,
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
it.todo('TODO: ED-15801 - Fix smart link async rendering integration test');
|
|
3
|
-
// import { runBlockNodeSelectionTestSuite } from '@atlaskit/editor-test-helpers/integration/selection';
|
|
4
|
-
//
|
|
5
|
-
// runBlockNodeSelectionTestSuite({
|
|
6
|
-
// nodeName: 'table',
|
|
7
|
-
// editorOptions: {
|
|
8
|
-
// allowTables: {
|
|
9
|
-
// advanced: true,
|
|
10
|
-
// },
|
|
11
|
-
// },
|
|
12
|
-
// selector: 'table',
|
|
13
|
-
// adfNode: {
|
|
14
|
-
// type: 'table',
|
|
15
|
-
// attrs: {
|
|
16
|
-
// isNumberColumnEnabled: false,
|
|
17
|
-
// layout: 'default',
|
|
18
|
-
// localId: '15804638-b946-4591-b64c-beffe5122733',
|
|
19
|
-
// },
|
|
20
|
-
// content: [
|
|
21
|
-
// {
|
|
22
|
-
// type: 'tableRow',
|
|
23
|
-
// content: [
|
|
24
|
-
// {
|
|
25
|
-
// type: 'tableHeader',
|
|
26
|
-
// attrs: {},
|
|
27
|
-
// content: [
|
|
28
|
-
// {
|
|
29
|
-
// type: 'paragraph',
|
|
30
|
-
// content: [],
|
|
31
|
-
// },
|
|
32
|
-
// ],
|
|
33
|
-
// },
|
|
34
|
-
// {
|
|
35
|
-
// type: 'tableHeader',
|
|
36
|
-
// attrs: {},
|
|
37
|
-
// content: [
|
|
38
|
-
// {
|
|
39
|
-
// type: 'paragraph',
|
|
40
|
-
// content: [],
|
|
41
|
-
// },
|
|
42
|
-
// ],
|
|
43
|
-
// },
|
|
44
|
-
// {
|
|
45
|
-
// type: 'tableHeader',
|
|
46
|
-
// attrs: {},
|
|
47
|
-
// content: [
|
|
48
|
-
// {
|
|
49
|
-
// type: 'paragraph',
|
|
50
|
-
// content: [],
|
|
51
|
-
// },
|
|
52
|
-
// ],
|
|
53
|
-
// },
|
|
54
|
-
// ],
|
|
55
|
-
// },
|
|
56
|
-
// {
|
|
57
|
-
// type: 'tableRow',
|
|
58
|
-
// content: [
|
|
59
|
-
// {
|
|
60
|
-
// type: 'tableCell',
|
|
61
|
-
// attrs: {},
|
|
62
|
-
// content: [
|
|
63
|
-
// {
|
|
64
|
-
// type: 'paragraph',
|
|
65
|
-
// content: [],
|
|
66
|
-
// },
|
|
67
|
-
// ],
|
|
68
|
-
// },
|
|
69
|
-
// {
|
|
70
|
-
// type: 'tableCell',
|
|
71
|
-
// attrs: {},
|
|
72
|
-
// content: [
|
|
73
|
-
// {
|
|
74
|
-
// type: 'paragraph',
|
|
75
|
-
// content: [],
|
|
76
|
-
// },
|
|
77
|
-
// ],
|
|
78
|
-
// },
|
|
79
|
-
// {
|
|
80
|
-
// type: 'tableCell',
|
|
81
|
-
// attrs: {},
|
|
82
|
-
// content: [
|
|
83
|
-
// {
|
|
84
|
-
// type: 'paragraph',
|
|
85
|
-
// content: [],
|
|
86
|
-
// },
|
|
87
|
-
// ],
|
|
88
|
-
// },
|
|
89
|
-
// ],
|
|
90
|
-
// },
|
|
91
|
-
// {
|
|
92
|
-
// type: 'tableRow',
|
|
93
|
-
// content: [
|
|
94
|
-
// {
|
|
95
|
-
// type: 'tableCell',
|
|
96
|
-
// attrs: {},
|
|
97
|
-
// content: [
|
|
98
|
-
// {
|
|
99
|
-
// type: 'paragraph',
|
|
100
|
-
// content: [],
|
|
101
|
-
// },
|
|
102
|
-
// ],
|
|
103
|
-
// },
|
|
104
|
-
// {
|
|
105
|
-
// type: 'tableCell',
|
|
106
|
-
// attrs: {},
|
|
107
|
-
// content: [
|
|
108
|
-
// {
|
|
109
|
-
// type: 'paragraph',
|
|
110
|
-
// content: [],
|
|
111
|
-
// },
|
|
112
|
-
// ],
|
|
113
|
-
// },
|
|
114
|
-
// {
|
|
115
|
-
// type: 'tableCell',
|
|
116
|
-
// attrs: {},
|
|
117
|
-
// content: [
|
|
118
|
-
// {
|
|
119
|
-
// type: 'paragraph',
|
|
120
|
-
// content: [],
|
|
121
|
-
// },
|
|
122
|
-
// ],
|
|
123
|
-
// },
|
|
124
|
-
// ],
|
|
125
|
-
// },
|
|
126
|
-
// ],
|
|
127
|
-
// },
|
|
128
|
-
// skipTests: {
|
|
129
|
-
// 'Extend selection right two characters to select [block-node] from line above with shift + arrow right': [
|
|
130
|
-
// 'chrome',
|
|
131
|
-
// 'safari',
|
|
132
|
-
// 'firefox',
|
|
133
|
-
// ],
|
|
134
|
-
// 'Extend selection left two characters to select [block-node] from line below with shift + arrow left': [
|
|
135
|
-
// 'chrome',
|
|
136
|
-
// 'safari',
|
|
137
|
-
// 'firefox',
|
|
138
|
-
// ],
|
|
139
|
-
// 'Extend a selection from end of the document to the start when [block-node] is the first node': [
|
|
140
|
-
// 'chrome',
|
|
141
|
-
// 'safari',
|
|
142
|
-
// 'firefox',
|
|
143
|
-
// ],
|
|
144
|
-
// 'Click and drag from the end to start of the document to select [block-node] when [block-node] is the first node': [
|
|
145
|
-
// 'chrome',
|
|
146
|
-
// 'safari',
|
|
147
|
-
// 'firefox',
|
|
148
|
-
// ],
|
|
149
|
-
// 'Extend a selection to the end of the document from start when [block-node] is the last node': [
|
|
150
|
-
// 'chrome',
|
|
151
|
-
// 'safari',
|
|
152
|
-
// 'firefox',
|
|
153
|
-
// ],
|
|
154
|
-
// 'Click and drag from start of the document to select [block-node] when [block-node] is the last node': [
|
|
155
|
-
// 'chrome',
|
|
156
|
-
// 'safari',
|
|
157
|
-
// 'firefox',
|
|
158
|
-
// ],
|
|
159
|
-
// "Extend selection down by one line multiple times to select [block-node]'s in sequence with shift + arrow down": [
|
|
160
|
-
// 'chrome',
|
|
161
|
-
// 'safari',
|
|
162
|
-
// 'firefox',
|
|
163
|
-
// ],
|
|
164
|
-
// },
|
|
165
|
-
// });
|