@ckeditor/ckeditor5-table 40.0.0 → 40.2.0

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.
Files changed (171) hide show
  1. package/CHANGELOG.md +15 -15
  2. package/LICENSE.md +3 -3
  3. package/build/table.js +1 -1
  4. package/build/translations/fi.js +1 -1
  5. package/lang/translations/fi.po +3 -3
  6. package/package.json +2 -2
  7. package/src/augmentation.d.ts +76 -76
  8. package/src/augmentation.js +5 -5
  9. package/src/commands/insertcolumncommand.d.ts +55 -55
  10. package/src/commands/insertcolumncommand.js +67 -67
  11. package/src/commands/insertrowcommand.d.ts +54 -54
  12. package/src/commands/insertrowcommand.js +66 -66
  13. package/src/commands/inserttablecommand.d.ts +44 -44
  14. package/src/commands/inserttablecommand.js +69 -69
  15. package/src/commands/mergecellcommand.d.ts +68 -68
  16. package/src/commands/mergecellcommand.js +198 -198
  17. package/src/commands/mergecellscommand.d.ts +28 -28
  18. package/src/commands/mergecellscommand.js +94 -94
  19. package/src/commands/removecolumncommand.d.ts +29 -29
  20. package/src/commands/removecolumncommand.js +109 -109
  21. package/src/commands/removerowcommand.d.ts +29 -29
  22. package/src/commands/removerowcommand.js +82 -82
  23. package/src/commands/selectcolumncommand.d.ts +33 -33
  24. package/src/commands/selectcolumncommand.js +60 -60
  25. package/src/commands/selectrowcommand.d.ts +33 -33
  26. package/src/commands/selectrowcommand.js +56 -56
  27. package/src/commands/setheadercolumncommand.d.ts +50 -50
  28. package/src/commands/setheadercolumncommand.js +71 -71
  29. package/src/commands/setheaderrowcommand.d.ts +53 -53
  30. package/src/commands/setheaderrowcommand.js +79 -79
  31. package/src/commands/splitcellcommand.d.ts +43 -43
  32. package/src/commands/splitcellcommand.js +54 -54
  33. package/src/converters/downcast.d.ts +63 -63
  34. package/src/converters/downcast.js +146 -146
  35. package/src/converters/table-caption-post-fixer.d.ts +20 -20
  36. package/src/converters/table-caption-post-fixer.js +53 -53
  37. package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -32
  38. package/src/converters/table-cell-paragraph-post-fixer.js +107 -107
  39. package/src/converters/table-cell-refresh-handler.d.ts +18 -18
  40. package/src/converters/table-cell-refresh-handler.js +45 -45
  41. package/src/converters/table-headings-refresh-handler.d.ts +17 -17
  42. package/src/converters/table-headings-refresh-handler.js +49 -49
  43. package/src/converters/table-layout-post-fixer.d.ts +226 -226
  44. package/src/converters/table-layout-post-fixer.js +367 -367
  45. package/src/converters/tableproperties.d.ts +54 -54
  46. package/src/converters/tableproperties.js +159 -159
  47. package/src/converters/upcasttable.d.ts +49 -49
  48. package/src/converters/upcasttable.js +243 -243
  49. package/src/index.d.ts +60 -60
  50. package/src/index.js +30 -30
  51. package/src/plaintableoutput.d.ts +26 -26
  52. package/src/plaintableoutput.js +123 -123
  53. package/src/table.d.ts +40 -40
  54. package/src/table.js +44 -44
  55. package/src/tablecaption/tablecaptionediting.d.ts +63 -63
  56. package/src/tablecaption/tablecaptionediting.js +122 -122
  57. package/src/tablecaption/tablecaptionui.d.ts +21 -21
  58. package/src/tablecaption/tablecaptionui.js +57 -57
  59. package/src/tablecaption/toggletablecaptioncommand.d.ts +68 -68
  60. package/src/tablecaption/toggletablecaptioncommand.js +105 -104
  61. package/src/tablecaption/utils.d.ts +38 -42
  62. package/src/tablecaption/utils.js +57 -67
  63. package/src/tablecaption.d.ts +24 -24
  64. package/src/tablecaption.js +28 -28
  65. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +32 -32
  66. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +30 -30
  67. package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +37 -37
  68. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +44 -44
  69. package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +37 -37
  70. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +44 -44
  71. package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +51 -51
  72. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +64 -64
  73. package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +46 -46
  74. package/src/tablecellproperties/commands/tablecellheightcommand.js +51 -51
  75. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +32 -32
  76. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +30 -30
  77. package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +51 -51
  78. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +64 -64
  79. package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -62
  80. package/src/tablecellproperties/commands/tablecellpropertycommand.js +92 -92
  81. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +40 -40
  82. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +38 -38
  83. package/src/tablecellproperties/tablecellpropertiesediting.d.ts +43 -43
  84. package/src/tablecellproperties/tablecellpropertiesediting.js +241 -241
  85. package/src/tablecellproperties/tablecellpropertiesui.d.ts +112 -112
  86. package/src/tablecellproperties/tablecellpropertiesui.js +330 -330
  87. package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +228 -228
  88. package/src/tablecellproperties/ui/tablecellpropertiesview.js +548 -548
  89. package/src/tablecellproperties.d.ts +30 -30
  90. package/src/tablecellproperties.js +34 -34
  91. package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +46 -46
  92. package/src/tablecellwidth/commands/tablecellwidthcommand.js +51 -51
  93. package/src/tablecellwidth/tablecellwidthediting.d.ts +29 -29
  94. package/src/tablecellwidth/tablecellwidthediting.js +45 -45
  95. package/src/tableclipboard.d.ts +65 -65
  96. package/src/tableclipboard.js +450 -450
  97. package/src/tablecolumnresize/constants.d.ts +20 -20
  98. package/src/tablecolumnresize/constants.js +20 -20
  99. package/src/tablecolumnresize/converters.d.ts +18 -18
  100. package/src/tablecolumnresize/converters.js +46 -46
  101. package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +139 -139
  102. package/src/tablecolumnresize/tablecolumnresizeediting.js +583 -583
  103. package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -38
  104. package/src/tablecolumnresize/tablewidthscommand.js +61 -61
  105. package/src/tablecolumnresize/utils.d.ts +148 -148
  106. package/src/tablecolumnresize/utils.js +358 -358
  107. package/src/tablecolumnresize.d.ts +26 -26
  108. package/src/tablecolumnresize.js +30 -30
  109. package/src/tableconfig.d.ts +343 -343
  110. package/src/tableconfig.js +5 -5
  111. package/src/tableediting.d.ts +98 -98
  112. package/src/tableediting.js +191 -191
  113. package/src/tablekeyboard.d.ts +68 -68
  114. package/src/tablekeyboard.js +279 -279
  115. package/src/tablemouse/mouseeventsobserver.d.ts +62 -62
  116. package/src/tablemouse/mouseeventsobserver.js +35 -35
  117. package/src/tablemouse.d.ts +48 -48
  118. package/src/tablemouse.js +172 -172
  119. package/src/tableproperties/commands/tablealignmentcommand.d.ts +32 -32
  120. package/src/tableproperties/commands/tablealignmentcommand.js +30 -30
  121. package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +32 -32
  122. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +30 -30
  123. package/src/tableproperties/commands/tablebordercolorcommand.d.ts +37 -37
  124. package/src/tableproperties/commands/tablebordercolorcommand.js +44 -44
  125. package/src/tableproperties/commands/tableborderstylecommand.d.ts +37 -37
  126. package/src/tableproperties/commands/tableborderstylecommand.js +44 -44
  127. package/src/tableproperties/commands/tableborderwidthcommand.d.ts +51 -51
  128. package/src/tableproperties/commands/tableborderwidthcommand.js +64 -64
  129. package/src/tableproperties/commands/tableheightcommand.d.ts +46 -46
  130. package/src/tableproperties/commands/tableheightcommand.js +54 -54
  131. package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -61
  132. package/src/tableproperties/commands/tablepropertycommand.js +81 -80
  133. package/src/tableproperties/commands/tablewidthcommand.d.ts +46 -46
  134. package/src/tableproperties/commands/tablewidthcommand.js +54 -54
  135. package/src/tableproperties/tablepropertiesediting.d.ts +40 -40
  136. package/src/tableproperties/tablepropertiesediting.js +206 -206
  137. package/src/tableproperties/tablepropertiesui.d.ts +114 -114
  138. package/src/tableproperties/tablepropertiesui.js +321 -321
  139. package/src/tableproperties/ui/tablepropertiesview.d.ts +207 -207
  140. package/src/tableproperties/ui/tablepropertiesview.js +466 -466
  141. package/src/tableproperties.d.ts +30 -30
  142. package/src/tableproperties.js +34 -34
  143. package/src/tableselection.d.ts +107 -107
  144. package/src/tableselection.js +297 -297
  145. package/src/tabletoolbar.d.ts +32 -32
  146. package/src/tabletoolbar.js +57 -57
  147. package/src/tableui.d.ts +53 -53
  148. package/src/tableui.js +309 -309
  149. package/src/tableutils.d.ts +448 -448
  150. package/src/tableutils.js +1055 -1055
  151. package/src/tablewalker.d.ts +362 -362
  152. package/src/tablewalker.js +393 -393
  153. package/src/ui/colorinputview.d.ts +140 -140
  154. package/src/ui/colorinputview.js +271 -271
  155. package/src/ui/formrowview.d.ts +61 -61
  156. package/src/ui/formrowview.js +57 -57
  157. package/src/ui/inserttableview.d.ts +77 -77
  158. package/src/ui/inserttableview.js +169 -169
  159. package/src/utils/common.d.ts +46 -42
  160. package/src/utils/common.js +68 -57
  161. package/src/utils/structure.d.ts +245 -245
  162. package/src/utils/structure.js +426 -426
  163. package/src/utils/table-properties.d.ts +67 -67
  164. package/src/utils/table-properties.js +86 -86
  165. package/src/utils/ui/contextualballoon.d.ts +34 -34
  166. package/src/utils/ui/contextualballoon.js +110 -106
  167. package/src/utils/ui/table-properties.d.ts +195 -195
  168. package/src/utils/ui/table-properties.js +362 -362
  169. package/src/utils/ui/widget.d.ts +20 -16
  170. package/src/utils/ui/widget.js +48 -38
  171. package/build/table.js.map +0 -1
@@ -1,362 +1,362 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module table/tablewalker
7
- */
8
- import type { Element, Position } from 'ckeditor5/src/engine';
9
- /**
10
- * An object with configuration for `TableWalker`.
11
- */
12
- export interface TableWalkerOptions {
13
- /**
14
- * A row index for which this iterator will output cells. Can't be used together with `startRow` and `endRow`.
15
- */
16
- row?: number | null;
17
- /**
18
- * A row index from which this iterator should start. Can't be used together with `row`. Default value is 0.
19
- */
20
- startRow?: number;
21
- /**
22
- * A row index at which this iterator should end. Can't be used together with `row`.
23
- */
24
- endRow?: number;
25
- /**
26
- * A column index for which this iterator will output cells. Can't be used together with `startColumn` and `endColumn`.
27
- */
28
- column?: number;
29
- /**
30
- * A column index from which this iterator should start. Can't be used together with `column`. Default value is 0.
31
- */
32
- startColumn?: number;
33
- /**
34
- * A column index at which this iterator should end. Can't be used together with `column`.
35
- */
36
- endColumn?: number;
37
- /**
38
- * Also return values for spanned cells. Default value is false.
39
- */
40
- includeAllSlots?: boolean;
41
- }
42
- /**
43
- * The table iterator class. It allows to iterate over table cells. For each cell the iterator yields
44
- * {@link module:table/tablewalker~TableSlot} with proper table cell attributes.
45
- */
46
- export default class TableWalker implements IterableIterator<TableSlot> {
47
- /**
48
- * The walker's table element.
49
- *
50
- * @internal
51
- */
52
- readonly _table: Element;
53
- /**
54
- * A row index from which this iterator will start.
55
- */
56
- private readonly _startRow;
57
- /**
58
- * A row index at which this iterator will end.
59
- */
60
- private readonly _endRow?;
61
- /**
62
- * If set, the table walker will only output cells from a given column and following ones or cells that overlap them.
63
- */
64
- private readonly _startColumn;
65
- /**
66
- * If set, the table walker will only output cells up to a given column.
67
- */
68
- private readonly _endColumn?;
69
- /**
70
- * Enables output of spanned cells that are normally not yielded.
71
- */
72
- private readonly _includeAllSlots;
73
- /**
74
- * Row indexes to skip from the iteration.
75
- */
76
- private readonly _skipRows;
77
- /**
78
- * The current row index.
79
- *
80
- * @internal
81
- */
82
- _row: number;
83
- /**
84
- * The index of the current row element in the table.
85
- *
86
- * @internal
87
- */
88
- _rowIndex: number;
89
- /**
90
- * The current column index.
91
- *
92
- * @internal
93
- */
94
- _column: number;
95
- /**
96
- * The cell index in a parent row. For spanned cells when {@link #_includeAllSlots} is set to `true`,
97
- * this represents the index of the next table cell.
98
- *
99
- * @internal
100
- */
101
- _cellIndex: number;
102
- /**
103
- * Holds a map of spanned cells in a table.
104
- */
105
- private readonly _spannedCells;
106
- /**
107
- * Index of the next column where a cell is anchored.
108
- */
109
- private _nextCellAtColumn;
110
- /**
111
- * Indicates whether the iterator jumped to (or close to) the start row, ignoring rows that don't need to be traversed.
112
- */
113
- private _jumpedToStartRow;
114
- /**
115
- * Creates an instance of the table walker.
116
- *
117
- * The table walker iterates internally by traversing the table from row index = 0 and column index = 0.
118
- * It walks row by row and column by column in order to output values defined in the constructor.
119
- * By default it will output only the locations that are occupied by a cell. To include also spanned rows and columns,
120
- * pass the `includeAllSlots` option to the constructor.
121
- *
122
- * The most important values of the iterator are column and row indexes of a cell.
123
- *
124
- * See {@link module:table/tablewalker~TableSlot} what values are returned by the table walker.
125
- *
126
- * To iterate over a given row:
127
- *
128
- * ```ts
129
- * const tableWalker = new TableWalker( table, { startRow: 1, endRow: 2 } );
130
- *
131
- * for ( const tableSlot of tableWalker ) {
132
- * console.log( 'A cell at row', tableSlot.row, 'and column', tableSlot.column );
133
- * }
134
- * ```
135
- *
136
- * For instance the code above for the following table:
137
- *
138
- * +----+----+----+----+----+----+
139
- * | 00 | 02 | 03 | 04 | 05 |
140
- * | +----+----+----+----+
141
- * | | 12 | 14 | 15 |
142
- * | +----+----+----+ +
143
- * | | 22 | |
144
- * |----+----+----+----+----+ +
145
- * | 30 | 31 | 32 | 33 | 34 | |
146
- * +----+----+----+----+----+----+
147
- *
148
- * will log in the console:
149
- *
150
- * 'A cell at row 1 and column 2'
151
- * 'A cell at row 1 and column 4'
152
- * 'A cell at row 1 and column 5'
153
- * 'A cell at row 2 and column 2'
154
- *
155
- * To also iterate over spanned cells:
156
- *
157
- * ```ts
158
- * const tableWalker = new TableWalker( table, { row: 1, includeAllSlots: true } );
159
- *
160
- * for ( const tableSlot of tableWalker ) {
161
- * console.log( 'Slot at', tableSlot.row, 'x', tableSlot.column, ':', tableSlot.isAnchor ? 'is anchored' : 'is spanned' );
162
- * }
163
- * ```
164
- *
165
- * will log in the console for the table from the previous example:
166
- *
167
- * 'Cell at 1 x 0 : is spanned'
168
- * 'Cell at 1 x 1 : is spanned'
169
- * 'Cell at 1 x 2 : is anchored'
170
- * 'Cell at 1 x 3 : is spanned'
171
- * 'Cell at 1 x 4 : is anchored'
172
- * 'Cell at 1 x 5 : is anchored'
173
- *
174
- * **Note**: Option `row` is a shortcut that sets both `startRow` and `endRow` to the same row.
175
- * (Use either `row` or `startRow` and `endRow` but never together). Similarly the `column` option sets both `startColumn`
176
- * and `endColumn` to the same column (Use either `column` or `startColumn` and `endColumn` but never together).
177
- *
178
- * @param table A table over which the walker iterates.
179
- * @param options An object with configuration.
180
- * @param options.row A row index for which this iterator will output cells. Can't be used together with `startRow` and `endRow`.
181
- * @param options.startRow A row index from which this iterator should start. Can't be used together with `row`. Default value is 0.
182
- * @param options.endRow A row index at which this iterator should end. Can't be used together with `row`.
183
- * @param options.column A column index for which this iterator will output cells.
184
- * Can't be used together with `startColumn` and `endColumn`.
185
- * @param options.startColumn A column index from which this iterator should start.
186
- * Can't be used together with `column`. Default value is 0.
187
- * @param options.endColumn A column index at which this iterator should end. Can't be used together with `column`.
188
- * @param options.includeAllSlots Also return values for spanned cells. Default value is "false".
189
- */
190
- constructor(table: Element, options?: TableWalkerOptions);
191
- /**
192
- * Iterable interface.
193
- */
194
- [Symbol.iterator](): IterableIterator<TableSlot>;
195
- /**
196
- * Gets the next table walker's value.
197
- *
198
- * @returns The next table walker's value.
199
- */
200
- next(): IteratorResult<TableSlot, undefined>;
201
- /**
202
- * Marks a row to skip in the next iteration. It will also skip cells from the current row if there are any cells from the current row
203
- * to output.
204
- *
205
- * @param row The row index to skip.
206
- */
207
- skipRow(row: number): void;
208
- /**
209
- * Advances internal cursor to the next row.
210
- */
211
- private _advanceToNextRow;
212
- /**
213
- * Checks if the current row is over {@link #_endRow}.
214
- */
215
- private _isOverEndRow;
216
- /**
217
- * Checks if the current cell is over {@link #_endColumn}
218
- */
219
- private _isOverEndColumn;
220
- /**
221
- * A common method for formatting the iterator's output value.
222
- *
223
- * @param cell The table cell to output.
224
- * @param anchorRow The row index of a cell anchor slot.
225
- * @param anchorColumn The column index of a cell anchor slot.
226
- */
227
- private _formatOutValue;
228
- /**
229
- * Checks if the current slot should be skipped.
230
- */
231
- private _shouldSkipSlot;
232
- /**
233
- * Returns the cell element that is spanned over the current cell location.
234
- */
235
- private _getSpanned;
236
- /**
237
- * Updates spanned cells map relative to the current cell location and its span dimensions.
238
- *
239
- * @param cell A cell that is spanned.
240
- * @param rowspan Cell height.
241
- * @param colspan Cell width.
242
- */
243
- private _recordSpans;
244
- /**
245
- * Marks the cell location as spanned by another cell.
246
- *
247
- * @param row The row index of the cell location.
248
- * @param column The column index of the cell location.
249
- * @param data A spanned cell details (cell element, anchor row and column).
250
- */
251
- private _markSpannedCell;
252
- /**
253
- * Checks if part of the table can be skipped.
254
- */
255
- private _canJumpToStartRow;
256
- /**
257
- * Sets the current row to `this._startRow` or the first row before it that has the number of cells
258
- * equal to the number of columns in the table.
259
- *
260
- * Example:
261
- * +----+----+----+
262
- * | 00 | 01 | 02 |
263
- * |----+----+----+
264
- * | 10 | 12 |
265
- * | +----+
266
- * | | 22 |
267
- * | +----+
268
- * | | 32 | <--- Start row
269
- * +----+----+----+
270
- * | 40 | 41 | 42 |
271
- * +----+----+----+
272
- *
273
- * If the 4th row is a `this._startRow`, this method will:
274
- * 1.) Count the number of columns this table has based on the first row (3 columns in this case).
275
- * 2.) Check if the 4th row contains 3 cells. It doesn't, so go to the row before it.
276
- * 3.) Check if the 3rd row contains 3 cells. It doesn't, so go to the row before it.
277
- * 4.) Check if the 2nd row contains 3 cells. It does, so set the current row to that row.
278
- *
279
- * Setting the current row this way is necessary to let the `next()` method loop over the cells
280
- * spanning multiple rows or columns and update the `this._spannedCells` property.
281
- */
282
- private _jumpToNonSpannedRowClosestToStartRow;
283
- /**
284
- * Returns a number of columns in a row taking `colspan` into consideration.
285
- */
286
- private _getRowLength;
287
- }
288
- /**
289
- * An object returned by {@link module:table/tablewalker~TableWalker} when traversing table cells.
290
- */
291
- declare class TableSlot {
292
- /**
293
- * The current table cell.
294
- */
295
- readonly cell: Element;
296
- /**
297
- * The row index of a table slot.
298
- */
299
- readonly row: number;
300
- /**
301
- * The column index of a table slot.
302
- */
303
- readonly column: number;
304
- /**
305
- * The row index of a cell anchor slot.
306
- */
307
- readonly cellAnchorRow: number;
308
- /**
309
- * The column index of a cell anchor slot.
310
- */
311
- readonly cellAnchorColumn: number;
312
- /**
313
- * The index of the current cell in the parent row.
314
- */
315
- private readonly _cellIndex;
316
- /**
317
- * The index of the current row element in the table.
318
- */
319
- private readonly _rowIndex;
320
- /**
321
- * The table element.
322
- */
323
- private readonly _table;
324
- /**
325
- * Creates an instance of the table walker value.
326
- *
327
- * @param tableWalker The table walker instance.
328
- * @param cell The current table cell.
329
- * @param anchorRow The row index of a cell anchor slot.
330
- * @param anchorColumn The column index of a cell anchor slot.
331
- */
332
- constructor(tableWalker: TableWalker, cell: Element, anchorRow: number, anchorColumn: number);
333
- /**
334
- * Whether the cell is anchored in the current slot.
335
- */
336
- get isAnchor(): boolean;
337
- /**
338
- * The width of a cell defined by a `colspan` attribute. If the model attribute is not present, it is set to `1`.
339
- */
340
- get cellWidth(): number;
341
- /**
342
- * The height of a cell defined by a `rowspan` attribute. If the model attribute is not present, it is set to `1`.
343
- */
344
- get cellHeight(): number;
345
- /**
346
- * The index of the current row element in the table.
347
- */
348
- get rowIndex(): number;
349
- /**
350
- * Returns the {@link module:engine/model/position~Position} before the table slot.
351
- */
352
- getPositionBefore(): Position;
353
- }
354
- export type { TableSlot };
355
- /**
356
- * This `TableSlot`'s getter (property) was removed in CKEditor 5 v20.0.0.
357
- *
358
- * Check out the new `TableWalker`'s API in the documentation.
359
- *
360
- * @error tableslot-getter-removed
361
- * @param getterName
362
- */
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module table/tablewalker
7
+ */
8
+ import type { Element, Position } from 'ckeditor5/src/engine';
9
+ /**
10
+ * An object with configuration for `TableWalker`.
11
+ */
12
+ export interface TableWalkerOptions {
13
+ /**
14
+ * A row index for which this iterator will output cells. Can't be used together with `startRow` and `endRow`.
15
+ */
16
+ row?: number | null;
17
+ /**
18
+ * A row index from which this iterator should start. Can't be used together with `row`. Default value is 0.
19
+ */
20
+ startRow?: number;
21
+ /**
22
+ * A row index at which this iterator should end. Can't be used together with `row`.
23
+ */
24
+ endRow?: number;
25
+ /**
26
+ * A column index for which this iterator will output cells. Can't be used together with `startColumn` and `endColumn`.
27
+ */
28
+ column?: number;
29
+ /**
30
+ * A column index from which this iterator should start. Can't be used together with `column`. Default value is 0.
31
+ */
32
+ startColumn?: number;
33
+ /**
34
+ * A column index at which this iterator should end. Can't be used together with `column`.
35
+ */
36
+ endColumn?: number;
37
+ /**
38
+ * Also return values for spanned cells. Default value is false.
39
+ */
40
+ includeAllSlots?: boolean;
41
+ }
42
+ /**
43
+ * The table iterator class. It allows to iterate over table cells. For each cell the iterator yields
44
+ * {@link module:table/tablewalker~TableSlot} with proper table cell attributes.
45
+ */
46
+ export default class TableWalker implements IterableIterator<TableSlot> {
47
+ /**
48
+ * The walker's table element.
49
+ *
50
+ * @internal
51
+ */
52
+ readonly _table: Element;
53
+ /**
54
+ * A row index from which this iterator will start.
55
+ */
56
+ private readonly _startRow;
57
+ /**
58
+ * A row index at which this iterator will end.
59
+ */
60
+ private readonly _endRow?;
61
+ /**
62
+ * If set, the table walker will only output cells from a given column and following ones or cells that overlap them.
63
+ */
64
+ private readonly _startColumn;
65
+ /**
66
+ * If set, the table walker will only output cells up to a given column.
67
+ */
68
+ private readonly _endColumn?;
69
+ /**
70
+ * Enables output of spanned cells that are normally not yielded.
71
+ */
72
+ private readonly _includeAllSlots;
73
+ /**
74
+ * Row indexes to skip from the iteration.
75
+ */
76
+ private readonly _skipRows;
77
+ /**
78
+ * The current row index.
79
+ *
80
+ * @internal
81
+ */
82
+ _row: number;
83
+ /**
84
+ * The index of the current row element in the table.
85
+ *
86
+ * @internal
87
+ */
88
+ _rowIndex: number;
89
+ /**
90
+ * The current column index.
91
+ *
92
+ * @internal
93
+ */
94
+ _column: number;
95
+ /**
96
+ * The cell index in a parent row. For spanned cells when {@link #_includeAllSlots} is set to `true`,
97
+ * this represents the index of the next table cell.
98
+ *
99
+ * @internal
100
+ */
101
+ _cellIndex: number;
102
+ /**
103
+ * Holds a map of spanned cells in a table.
104
+ */
105
+ private readonly _spannedCells;
106
+ /**
107
+ * Index of the next column where a cell is anchored.
108
+ */
109
+ private _nextCellAtColumn;
110
+ /**
111
+ * Indicates whether the iterator jumped to (or close to) the start row, ignoring rows that don't need to be traversed.
112
+ */
113
+ private _jumpedToStartRow;
114
+ /**
115
+ * Creates an instance of the table walker.
116
+ *
117
+ * The table walker iterates internally by traversing the table from row index = 0 and column index = 0.
118
+ * It walks row by row and column by column in order to output values defined in the constructor.
119
+ * By default it will output only the locations that are occupied by a cell. To include also spanned rows and columns,
120
+ * pass the `includeAllSlots` option to the constructor.
121
+ *
122
+ * The most important values of the iterator are column and row indexes of a cell.
123
+ *
124
+ * See {@link module:table/tablewalker~TableSlot} what values are returned by the table walker.
125
+ *
126
+ * To iterate over a given row:
127
+ *
128
+ * ```ts
129
+ * const tableWalker = new TableWalker( table, { startRow: 1, endRow: 2 } );
130
+ *
131
+ * for ( const tableSlot of tableWalker ) {
132
+ * console.log( 'A cell at row', tableSlot.row, 'and column', tableSlot.column );
133
+ * }
134
+ * ```
135
+ *
136
+ * For instance the code above for the following table:
137
+ *
138
+ * +----+----+----+----+----+----+
139
+ * | 00 | 02 | 03 | 04 | 05 |
140
+ * | +----+----+----+----+
141
+ * | | 12 | 14 | 15 |
142
+ * | +----+----+----+ +
143
+ * | | 22 | |
144
+ * |----+----+----+----+----+ +
145
+ * | 30 | 31 | 32 | 33 | 34 | |
146
+ * +----+----+----+----+----+----+
147
+ *
148
+ * will log in the console:
149
+ *
150
+ * 'A cell at row 1 and column 2'
151
+ * 'A cell at row 1 and column 4'
152
+ * 'A cell at row 1 and column 5'
153
+ * 'A cell at row 2 and column 2'
154
+ *
155
+ * To also iterate over spanned cells:
156
+ *
157
+ * ```ts
158
+ * const tableWalker = new TableWalker( table, { row: 1, includeAllSlots: true } );
159
+ *
160
+ * for ( const tableSlot of tableWalker ) {
161
+ * console.log( 'Slot at', tableSlot.row, 'x', tableSlot.column, ':', tableSlot.isAnchor ? 'is anchored' : 'is spanned' );
162
+ * }
163
+ * ```
164
+ *
165
+ * will log in the console for the table from the previous example:
166
+ *
167
+ * 'Cell at 1 x 0 : is spanned'
168
+ * 'Cell at 1 x 1 : is spanned'
169
+ * 'Cell at 1 x 2 : is anchored'
170
+ * 'Cell at 1 x 3 : is spanned'
171
+ * 'Cell at 1 x 4 : is anchored'
172
+ * 'Cell at 1 x 5 : is anchored'
173
+ *
174
+ * **Note**: Option `row` is a shortcut that sets both `startRow` and `endRow` to the same row.
175
+ * (Use either `row` or `startRow` and `endRow` but never together). Similarly the `column` option sets both `startColumn`
176
+ * and `endColumn` to the same column (Use either `column` or `startColumn` and `endColumn` but never together).
177
+ *
178
+ * @param table A table over which the walker iterates.
179
+ * @param options An object with configuration.
180
+ * @param options.row A row index for which this iterator will output cells. Can't be used together with `startRow` and `endRow`.
181
+ * @param options.startRow A row index from which this iterator should start. Can't be used together with `row`. Default value is 0.
182
+ * @param options.endRow A row index at which this iterator should end. Can't be used together with `row`.
183
+ * @param options.column A column index for which this iterator will output cells.
184
+ * Can't be used together with `startColumn` and `endColumn`.
185
+ * @param options.startColumn A column index from which this iterator should start.
186
+ * Can't be used together with `column`. Default value is 0.
187
+ * @param options.endColumn A column index at which this iterator should end. Can't be used together with `column`.
188
+ * @param options.includeAllSlots Also return values for spanned cells. Default value is "false".
189
+ */
190
+ constructor(table: Element, options?: TableWalkerOptions);
191
+ /**
192
+ * Iterable interface.
193
+ */
194
+ [Symbol.iterator](): IterableIterator<TableSlot>;
195
+ /**
196
+ * Gets the next table walker's value.
197
+ *
198
+ * @returns The next table walker's value.
199
+ */
200
+ next(): IteratorResult<TableSlot, undefined>;
201
+ /**
202
+ * Marks a row to skip in the next iteration. It will also skip cells from the current row if there are any cells from the current row
203
+ * to output.
204
+ *
205
+ * @param row The row index to skip.
206
+ */
207
+ skipRow(row: number): void;
208
+ /**
209
+ * Advances internal cursor to the next row.
210
+ */
211
+ private _advanceToNextRow;
212
+ /**
213
+ * Checks if the current row is over {@link #_endRow}.
214
+ */
215
+ private _isOverEndRow;
216
+ /**
217
+ * Checks if the current cell is over {@link #_endColumn}
218
+ */
219
+ private _isOverEndColumn;
220
+ /**
221
+ * A common method for formatting the iterator's output value.
222
+ *
223
+ * @param cell The table cell to output.
224
+ * @param anchorRow The row index of a cell anchor slot.
225
+ * @param anchorColumn The column index of a cell anchor slot.
226
+ */
227
+ private _formatOutValue;
228
+ /**
229
+ * Checks if the current slot should be skipped.
230
+ */
231
+ private _shouldSkipSlot;
232
+ /**
233
+ * Returns the cell element that is spanned over the current cell location.
234
+ */
235
+ private _getSpanned;
236
+ /**
237
+ * Updates spanned cells map relative to the current cell location and its span dimensions.
238
+ *
239
+ * @param cell A cell that is spanned.
240
+ * @param rowspan Cell height.
241
+ * @param colspan Cell width.
242
+ */
243
+ private _recordSpans;
244
+ /**
245
+ * Marks the cell location as spanned by another cell.
246
+ *
247
+ * @param row The row index of the cell location.
248
+ * @param column The column index of the cell location.
249
+ * @param data A spanned cell details (cell element, anchor row and column).
250
+ */
251
+ private _markSpannedCell;
252
+ /**
253
+ * Checks if part of the table can be skipped.
254
+ */
255
+ private _canJumpToStartRow;
256
+ /**
257
+ * Sets the current row to `this._startRow` or the first row before it that has the number of cells
258
+ * equal to the number of columns in the table.
259
+ *
260
+ * Example:
261
+ * +----+----+----+
262
+ * | 00 | 01 | 02 |
263
+ * |----+----+----+
264
+ * | 10 | 12 |
265
+ * | +----+
266
+ * | | 22 |
267
+ * | +----+
268
+ * | | 32 | <--- Start row
269
+ * +----+----+----+
270
+ * | 40 | 41 | 42 |
271
+ * +----+----+----+
272
+ *
273
+ * If the 4th row is a `this._startRow`, this method will:
274
+ * 1.) Count the number of columns this table has based on the first row (3 columns in this case).
275
+ * 2.) Check if the 4th row contains 3 cells. It doesn't, so go to the row before it.
276
+ * 3.) Check if the 3rd row contains 3 cells. It doesn't, so go to the row before it.
277
+ * 4.) Check if the 2nd row contains 3 cells. It does, so set the current row to that row.
278
+ *
279
+ * Setting the current row this way is necessary to let the `next()` method loop over the cells
280
+ * spanning multiple rows or columns and update the `this._spannedCells` property.
281
+ */
282
+ private _jumpToNonSpannedRowClosestToStartRow;
283
+ /**
284
+ * Returns a number of columns in a row taking `colspan` into consideration.
285
+ */
286
+ private _getRowLength;
287
+ }
288
+ /**
289
+ * An object returned by {@link module:table/tablewalker~TableWalker} when traversing table cells.
290
+ */
291
+ declare class TableSlot {
292
+ /**
293
+ * The current table cell.
294
+ */
295
+ readonly cell: Element;
296
+ /**
297
+ * The row index of a table slot.
298
+ */
299
+ readonly row: number;
300
+ /**
301
+ * The column index of a table slot.
302
+ */
303
+ readonly column: number;
304
+ /**
305
+ * The row index of a cell anchor slot.
306
+ */
307
+ readonly cellAnchorRow: number;
308
+ /**
309
+ * The column index of a cell anchor slot.
310
+ */
311
+ readonly cellAnchorColumn: number;
312
+ /**
313
+ * The index of the current cell in the parent row.
314
+ */
315
+ private readonly _cellIndex;
316
+ /**
317
+ * The index of the current row element in the table.
318
+ */
319
+ private readonly _rowIndex;
320
+ /**
321
+ * The table element.
322
+ */
323
+ private readonly _table;
324
+ /**
325
+ * Creates an instance of the table walker value.
326
+ *
327
+ * @param tableWalker The table walker instance.
328
+ * @param cell The current table cell.
329
+ * @param anchorRow The row index of a cell anchor slot.
330
+ * @param anchorColumn The column index of a cell anchor slot.
331
+ */
332
+ constructor(tableWalker: TableWalker, cell: Element, anchorRow: number, anchorColumn: number);
333
+ /**
334
+ * Whether the cell is anchored in the current slot.
335
+ */
336
+ get isAnchor(): boolean;
337
+ /**
338
+ * The width of a cell defined by a `colspan` attribute. If the model attribute is not present, it is set to `1`.
339
+ */
340
+ get cellWidth(): number;
341
+ /**
342
+ * The height of a cell defined by a `rowspan` attribute. If the model attribute is not present, it is set to `1`.
343
+ */
344
+ get cellHeight(): number;
345
+ /**
346
+ * The index of the current row element in the table.
347
+ */
348
+ get rowIndex(): number;
349
+ /**
350
+ * Returns the {@link module:engine/model/position~Position} before the table slot.
351
+ */
352
+ getPositionBefore(): Position;
353
+ }
354
+ export type { TableSlot };
355
+ /**
356
+ * This `TableSlot`'s getter (property) was removed in CKEditor 5 v20.0.0.
357
+ *
358
+ * Check out the new `TableWalker`'s API in the documentation.
359
+ *
360
+ * @error tableslot-getter-removed
361
+ * @param getterName
362
+ */