@ckeditor/ckeditor5-table 0.0.0-nightly-20230829.0 → 0.0.0-nightly-20230831.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 (61) hide show
  1. package/build/table.js +1 -1
  2. package/lang/translations/ar.po +1 -0
  3. package/lang/translations/az.po +1 -0
  4. package/lang/translations/bg.po +1 -0
  5. package/lang/translations/bn.po +1 -0
  6. package/lang/translations/ca.po +1 -0
  7. package/lang/translations/cs.po +1 -0
  8. package/lang/translations/da.po +1 -0
  9. package/lang/translations/de-ch.po +1 -0
  10. package/lang/translations/de.po +1 -0
  11. package/lang/translations/el.po +1 -0
  12. package/lang/translations/en-au.po +1 -0
  13. package/lang/translations/en-gb.po +1 -0
  14. package/lang/translations/en.po +1 -0
  15. package/lang/translations/es.po +1 -0
  16. package/lang/translations/et.po +1 -0
  17. package/lang/translations/fa.po +1 -0
  18. package/lang/translations/fi.po +1 -0
  19. package/lang/translations/fr.po +1 -0
  20. package/lang/translations/gl.po +1 -0
  21. package/lang/translations/he.po +1 -0
  22. package/lang/translations/hi.po +1 -0
  23. package/lang/translations/hr.po +1 -0
  24. package/lang/translations/hu.po +1 -0
  25. package/lang/translations/id.po +1 -0
  26. package/lang/translations/it.po +1 -0
  27. package/lang/translations/ja.po +1 -0
  28. package/lang/translations/ko.po +1 -0
  29. package/lang/translations/ku.po +1 -0
  30. package/lang/translations/lt.po +1 -0
  31. package/lang/translations/lv.po +1 -0
  32. package/lang/translations/ms.po +1 -0
  33. package/lang/translations/nb.po +1 -0
  34. package/lang/translations/ne.po +1 -0
  35. package/lang/translations/nl.po +1 -0
  36. package/lang/translations/no.po +1 -0
  37. package/lang/translations/pl.po +1 -0
  38. package/lang/translations/pt-br.po +1 -0
  39. package/lang/translations/pt.po +1 -0
  40. package/lang/translations/ro.po +1 -0
  41. package/lang/translations/ru.po +1 -0
  42. package/lang/translations/sk.po +1 -0
  43. package/lang/translations/sl.po +1 -0
  44. package/lang/translations/sq.po +1 -0
  45. package/lang/translations/sr-latn.po +1 -0
  46. package/lang/translations/sr.po +1 -0
  47. package/lang/translations/sv.po +1 -0
  48. package/lang/translations/th.po +1 -0
  49. package/lang/translations/tk.po +1 -0
  50. package/lang/translations/tr.po +1 -0
  51. package/lang/translations/tt.po +1 -0
  52. package/lang/translations/ug.po +1 -0
  53. package/lang/translations/uk.po +1 -0
  54. package/lang/translations/ur.po +1 -0
  55. package/lang/translations/uz.po +1 -0
  56. package/lang/translations/vi.po +1 -0
  57. package/lang/translations/zh-cn.po +1 -0
  58. package/lang/translations/zh.po +1 -0
  59. package/package.json +2 -2
  60. package/src/tablewalker.d.ts +39 -0
  61. package/src/tablewalker.js +60 -0
@@ -84,6 +84,10 @@ export default class TableWalker {
84
84
  * @param options.includeAllSlots Also return values for spanned cells. Default value is "false".
85
85
  */
86
86
  constructor(table, options = {}) {
87
+ /**
88
+ * Indicates whether the iterator jumped to (or close to) the start row, ignoring rows that don't need to be traversed.
89
+ */
90
+ this._jumpedToStartRow = false;
87
91
  this._table = table;
88
92
  this._startRow = options.row !== undefined ? options.row : options.startRow || 0;
89
93
  this._endRow = options.row !== undefined ? options.row : options.endRow;
@@ -110,6 +114,9 @@ export default class TableWalker {
110
114
  * @returns The next table walker's value.
111
115
  */
112
116
  next() {
117
+ if (this._canJumpToStartRow()) {
118
+ this._jumpToNonSpannedRowClosestToStartRow();
119
+ }
113
120
  const row = this._table.getChild(this._rowIndex);
114
121
  // Iterator is done when there's no row (table ended) or the row is after `endRow` limit.
115
122
  if (!row || this._isOverEndRow()) {
@@ -259,6 +266,59 @@ export default class TableWalker {
259
266
  const rowSpans = this._spannedCells.get(row);
260
267
  rowSpans.set(column, data);
261
268
  }
269
+ /**
270
+ * Checks if part of the table can be skipped.
271
+ */
272
+ _canJumpToStartRow() {
273
+ return !!this._startRow &&
274
+ this._startRow > 0 &&
275
+ !this._jumpedToStartRow;
276
+ }
277
+ /**
278
+ * Sets the current row to `this._startRow` or the first row before it that has the number of cells
279
+ * equal to the number of columns in the table.
280
+ *
281
+ * Example:
282
+ * +----+----+----+
283
+ * | 00 | 01 | 02 |
284
+ * |----+----+----+
285
+ * | 10 | 12 |
286
+ * | +----+
287
+ * | | 22 |
288
+ * | +----+
289
+ * | | 32 | <--- Start row
290
+ * +----+----+----+
291
+ * | 40 | 41 | 42 |
292
+ * +----+----+----+
293
+ *
294
+ * If the 4th row is a `this._startRow`, this method will:
295
+ * 1.) Count the number of columns this table has based on the first row (3 columns in this case).
296
+ * 2.) Check if the 4th row contains 3 cells. It doesn't, so go to the row before it.
297
+ * 3.) Check if the 3rd row contains 3 cells. It doesn't, so go to the row before it.
298
+ * 4.) Check if the 2nd row contains 3 cells. It does, so set the current row to that row.
299
+ *
300
+ * Setting the current row this way is necessary to let the `next()` method loop over the cells
301
+ * spanning multiple rows or columns and update the `this._spannedCells` property.
302
+ */
303
+ _jumpToNonSpannedRowClosestToStartRow() {
304
+ const firstRowLength = this._getRowLength(0);
305
+ for (let i = this._startRow; !this._jumpedToStartRow; i--) {
306
+ if (firstRowLength === this._getRowLength(i)) {
307
+ this._row = i;
308
+ this._rowIndex = i;
309
+ this._jumpedToStartRow = true;
310
+ }
311
+ }
312
+ }
313
+ /**
314
+ * Returns a number of columns in a row taking `colspan` into consideration.
315
+ */
316
+ _getRowLength(rowIndex) {
317
+ const row = this._table.getChild(rowIndex);
318
+ return [...row.getChildren()].reduce((cols, row) => {
319
+ return cols + parseInt(row.getAttribute('colspan') || '1');
320
+ }, 0);
321
+ }
262
322
  }
263
323
  /**
264
324
  * An object returned by {@link module:table/tablewalker~TableWalker} when traversing table cells.