@ckeditor/ckeditor5-table 32.0.0 → 33.0.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.
@@ -10,7 +10,6 @@
10
10
  import { Command } from 'ckeditor5/src/core';
11
11
 
12
12
  import TableWalker from '../tablewalker';
13
- import { getColumnIndexes, getSelectionAffectedTableCells } from '../utils/selection';
14
13
 
15
14
  /**
16
15
  * The remove column command.
@@ -28,14 +27,15 @@ export default class RemoveColumnCommand extends Command {
28
27
  * @inheritDoc
29
28
  */
30
29
  refresh() {
31
- const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection );
30
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
31
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( this.editor.model.document.selection );
32
32
  const firstCell = selectedCells[ 0 ];
33
33
 
34
34
  if ( firstCell ) {
35
35
  const table = firstCell.findAncestor( 'table' );
36
- const tableColumnCount = this.editor.plugins.get( 'TableUtils' ).getColumns( table );
36
+ const tableColumnCount = tableUtils.getColumns( table );
37
37
 
38
- const { first, last } = getColumnIndexes( selectedCells );
38
+ const { first, last } = tableUtils.getColumnIndexes( selectedCells );
39
39
 
40
40
  this.isEnabled = last - first < ( tableColumnCount - 1 );
41
41
  } else {
@@ -47,7 +47,8 @@ export default class RemoveColumnCommand extends Command {
47
47
  * @inheritDoc
48
48
  */
49
49
  execute() {
50
- const [ firstCell, lastCell ] = getBoundaryCells( this.editor.model.document.selection );
50
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
51
+ const [ firstCell, lastCell ] = getBoundaryCells( this.editor.model.document.selection, tableUtils );
51
52
  const table = firstCell.parent.parent;
52
53
 
53
54
  // Cache the table before removing or updating colspans.
@@ -111,8 +112,8 @@ function getCellToFocus( tableMap, firstCell, lastCell, removedColumnIndexes ) {
111
112
  }
112
113
 
113
114
  // Returns helper object returning the first and the last cell contained in given selection, based on DOM order.
114
- function getBoundaryCells( selection ) {
115
- const referenceCells = getSelectionAffectedTableCells( selection );
115
+ function getBoundaryCells( selection, tableUtils ) {
116
+ const referenceCells = tableUtils.getSelectionAffectedTableCells( selection );
116
117
  const firstCell = referenceCells[ 0 ];
117
118
  const lastCell = referenceCells.pop();
118
119
 
@@ -9,8 +9,6 @@
9
9
 
10
10
  import { Command } from 'ckeditor5/src/core';
11
11
 
12
- import { getRowIndexes, getSelectionAffectedTableCells } from '../utils/selection';
13
-
14
12
  /**
15
13
  * The remove row command.
16
14
  *
@@ -27,7 +25,8 @@ export default class RemoveRowCommand extends Command {
27
25
  * @inheritDoc
28
26
  */
29
27
  refresh() {
30
- const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection );
28
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
29
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( this.editor.model.document.selection );
31
30
  const firstCell = selectedCells[ 0 ];
32
31
 
33
32
  if ( firstCell ) {
@@ -35,7 +34,7 @@ export default class RemoveRowCommand extends Command {
35
34
  const tableRowCount = this.editor.plugins.get( 'TableUtils' ).getRows( table );
36
35
  const lastRowIndex = tableRowCount - 1;
37
36
 
38
- const selectedRowIndexes = getRowIndexes( selectedCells );
37
+ const selectedRowIndexes = tableUtils.getRowIndexes( selectedCells );
39
38
 
40
39
  const areAllRowsSelected = selectedRowIndexes.first === 0 && selectedRowIndexes.last === lastRowIndex;
41
40
 
@@ -53,8 +52,8 @@ export default class RemoveRowCommand extends Command {
53
52
  const model = this.editor.model;
54
53
  const tableUtils = this.editor.plugins.get( 'TableUtils' );
55
54
 
56
- const referenceCells = getSelectionAffectedTableCells( model.document.selection );
57
- const removedRowIndexes = getRowIndexes( referenceCells );
55
+ const referenceCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
56
+ const removedRowIndexes = tableUtils.getRowIndexes( referenceCells );
58
57
 
59
58
  const firstCell = referenceCells[ 0 ];
60
59
  const table = firstCell.findAncestor( 'table' );
@@ -10,7 +10,6 @@
10
10
  import { Command } from 'ckeditor5/src/core';
11
11
 
12
12
  import TableWalker from '../tablewalker';
13
- import { getSelectionAffectedTableCells } from '../utils/selection';
14
13
 
15
14
  /**
16
15
  * The select column command.
@@ -38,7 +37,8 @@ export default class SelectColumnCommand extends Command {
38
37
  * @inheritDoc
39
38
  */
40
39
  refresh() {
41
- const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection );
40
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
41
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( this.editor.model.document.selection );
42
42
 
43
43
  this.isEnabled = selectedCells.length > 0;
44
44
  }
@@ -47,13 +47,13 @@ export default class SelectColumnCommand extends Command {
47
47
  * @inheritDoc
48
48
  */
49
49
  execute() {
50
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
50
51
  const model = this.editor.model;
51
- const referenceCells = getSelectionAffectedTableCells( model.document.selection );
52
+ const referenceCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
52
53
  const firstCell = referenceCells[ 0 ];
53
54
  const lastCell = referenceCells.pop();
54
55
  const table = firstCell.findAncestor( 'table' );
55
56
 
56
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
57
57
  const startLocation = tableUtils.getCellLocation( firstCell );
58
58
  const endLocation = tableUtils.getCellLocation( lastCell );
59
59
 
@@ -9,8 +9,6 @@
9
9
 
10
10
  import { Command } from 'ckeditor5/src/core';
11
11
 
12
- import { getRowIndexes, getSelectionAffectedTableCells } from '../utils/selection';
13
-
14
12
  /**
15
13
  * The select row command.
16
14
  *
@@ -37,7 +35,8 @@ export default class SelectRowCommand extends Command {
37
35
  * @inheritDoc
38
36
  */
39
37
  refresh() {
40
- const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection );
38
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
39
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( this.editor.model.document.selection );
41
40
 
42
41
  this.isEnabled = selectedCells.length > 0;
43
42
  }
@@ -47,8 +46,9 @@ export default class SelectRowCommand extends Command {
47
46
  */
48
47
  execute() {
49
48
  const model = this.editor.model;
50
- const referenceCells = getSelectionAffectedTableCells( model.document.selection );
51
- const rowIndexes = getRowIndexes( referenceCells );
49
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
50
+ const referenceCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
51
+ const rowIndexes = tableUtils.getRowIndexes( referenceCells );
52
52
 
53
53
  const table = referenceCells[ 0 ].findAncestor( 'table' );
54
54
  const rangesToSelect = [];
@@ -13,7 +13,6 @@ import {
13
13
  isHeadingColumnCell,
14
14
  updateNumericAttribute
15
15
  } from '../utils/common';
16
- import { getColumnIndexes, getSelectionAffectedTableCells } from '../utils/selection';
17
16
  import { getHorizontallyOverlappingCells, splitVertically } from '../utils/structure';
18
17
 
19
18
  /**
@@ -37,8 +36,9 @@ export default class SetHeaderColumnCommand extends Command {
37
36
  */
38
37
  refresh() {
39
38
  const model = this.editor.model;
40
- const selectedCells = getSelectionAffectedTableCells( model.document.selection );
41
39
  const tableUtils = this.editor.plugins.get( 'TableUtils' );
40
+
41
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
42
42
  const isInTable = selectedCells.length > 0;
43
43
 
44
44
  this.isEnabled = isInTable;
@@ -71,11 +71,12 @@ export default class SetHeaderColumnCommand extends Command {
71
71
  return;
72
72
  }
73
73
 
74
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
74
75
  const model = this.editor.model;
75
- const selectedCells = getSelectionAffectedTableCells( model.document.selection );
76
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
76
77
  const table = selectedCells[ 0 ].findAncestor( 'table' );
77
78
 
78
- const { first, last } = getColumnIndexes( selectedCells );
79
+ const { first, last } = tableUtils.getColumnIndexes( selectedCells );
79
80
  const headingColumnsToSet = this.value ? first : last + 1;
80
81
 
81
82
  model.change( writer => {
@@ -10,7 +10,6 @@
10
10
  import { Command } from 'ckeditor5/src/core';
11
11
 
12
12
  import { updateNumericAttribute } from '../utils/common';
13
- import { getRowIndexes, getSelectionAffectedTableCells } from '../utils/selection';
14
13
  import { getVerticallyOverlappingCells, splitHorizontally } from '../utils/structure';
15
14
 
16
15
  /**
@@ -32,8 +31,9 @@ export default class SetHeaderRowCommand extends Command {
32
31
  * @inheritDoc
33
32
  */
34
33
  refresh() {
34
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
35
35
  const model = this.editor.model;
36
- const selectedCells = getSelectionAffectedTableCells( model.document.selection );
36
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
37
37
  const isInTable = selectedCells.length > 0;
38
38
 
39
39
  this.isEnabled = isInTable;
@@ -65,11 +65,14 @@ export default class SetHeaderRowCommand extends Command {
65
65
  if ( options.forceValue === this.value ) {
66
66
  return;
67
67
  }
68
+
69
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
68
70
  const model = this.editor.model;
69
- const selectedCells = getSelectionAffectedTableCells( model.document.selection );
71
+
72
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
70
73
  const table = selectedCells[ 0 ].findAncestor( 'table' );
71
74
 
72
- const { first, last } = getRowIndexes( selectedCells );
75
+ const { first, last } = tableUtils.getRowIndexes( selectedCells );
73
76
  const headingRowsToSet = this.value ? first : last + 1;
74
77
  const currentHeadingRows = table.getAttribute( 'headingRows' ) || 0;
75
78
 
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  import { Command } from 'ckeditor5/src/core';
11
- import { getSelectionAffectedTableCells } from '../utils/selection';
12
11
 
13
12
  /**
14
13
  * The split cell command.
@@ -46,7 +45,8 @@ export default class SplitCellCommand extends Command {
46
45
  * @inheritDoc
47
46
  */
48
47
  refresh() {
49
- const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection );
48
+ const tableUtils = this.editor.plugins.get( 'TableUtils' );
49
+ const selectedCells = tableUtils.getSelectionAffectedTableCells( this.editor.model.document.selection );
50
50
 
51
51
  this.isEnabled = selectedCells.length === 1;
52
52
  }
@@ -55,9 +55,9 @@ export default class SplitCellCommand extends Command {
55
55
  * @inheritDoc
56
56
  */
57
57
  execute() {
58
- const tableCell = getSelectionAffectedTableCells( this.editor.model.document.selection )[ 0 ];
59
- const isHorizontal = this.direction === 'horizontally';
60
58
  const tableUtils = this.editor.plugins.get( 'TableUtils' );
59
+ const tableCell = tableUtils.getSelectionAffectedTableCells( this.editor.model.document.selection )[ 0 ];
60
+ const isHorizontal = this.direction === 'horizontally';
61
61
 
62
62
  if ( isHorizontal ) {
63
63
  tableUtils.splitCellHorizontally( tableCell, 2 );