@ckeditor/ckeditor5-table 36.0.1 → 37.0.0-alpha.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 (166) hide show
  1. package/build/table.js +1 -1
  2. package/package.json +34 -29
  3. package/src/commands/insertcolumncommand.d.ts +61 -0
  4. package/src/commands/insertcolumncommand.js +45 -60
  5. package/src/commands/insertrowcommand.d.ts +60 -0
  6. package/src/commands/insertrowcommand.js +44 -59
  7. package/src/commands/inserttablecommand.d.ts +50 -0
  8. package/src/commands/inserttablecommand.js +51 -68
  9. package/src/commands/mergecellcommand.d.ts +76 -0
  10. package/src/commands/mergecellcommand.js +169 -244
  11. package/src/commands/mergecellscommand.d.ts +33 -0
  12. package/src/commands/mergecellscommand.js +72 -101
  13. package/src/commands/removecolumncommand.d.ts +34 -0
  14. package/src/commands/removecolumncommand.js +88 -102
  15. package/src/commands/removerowcommand.d.ts +34 -0
  16. package/src/commands/removerowcommand.js +63 -80
  17. package/src/commands/selectcolumncommand.d.ts +38 -0
  18. package/src/commands/selectcolumncommand.js +41 -54
  19. package/src/commands/selectrowcommand.d.ts +38 -0
  20. package/src/commands/selectrowcommand.js +38 -48
  21. package/src/commands/setheadercolumncommand.d.ts +55 -0
  22. package/src/commands/setheadercolumncommand.js +48 -73
  23. package/src/commands/setheaderrowcommand.d.ts +58 -0
  24. package/src/commands/setheaderrowcommand.js +56 -85
  25. package/src/commands/splitcellcommand.d.ts +49 -0
  26. package/src/commands/splitcellcommand.js +35 -49
  27. package/src/converters/downcast.d.ts +63 -0
  28. package/src/converters/downcast.js +98 -130
  29. package/src/converters/table-caption-post-fixer.d.ts +20 -0
  30. package/src/converters/table-caption-post-fixer.js +36 -52
  31. package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -0
  32. package/src/converters/table-cell-paragraph-post-fixer.js +88 -119
  33. package/src/converters/table-cell-refresh-handler.d.ts +18 -0
  34. package/src/converters/table-cell-refresh-handler.js +29 -48
  35. package/src/converters/table-headings-refresh-handler.d.ts +17 -0
  36. package/src/converters/table-headings-refresh-handler.js +35 -54
  37. package/src/converters/table-layout-post-fixer.d.ts +226 -0
  38. package/src/converters/table-layout-post-fixer.js +276 -313
  39. package/src/converters/tableproperties.d.ts +54 -0
  40. package/src/converters/tableproperties.js +136 -168
  41. package/src/converters/upcasttable.d.ts +49 -0
  42. package/src/converters/upcasttable.js +196 -251
  43. package/src/index.d.ts +29 -0
  44. package/src/index.js +0 -2
  45. package/src/plaintableoutput.d.ts +30 -0
  46. package/src/plaintableoutput.js +107 -135
  47. package/src/table.d.ts +38 -0
  48. package/src/table.js +12 -88
  49. package/src/tablecaption/tablecaptionediting.d.ts +68 -0
  50. package/src/tablecaption/tablecaptionediting.js +104 -135
  51. package/src/tablecaption/tablecaptionui.d.ts +26 -0
  52. package/src/tablecaption/tablecaptionui.js +42 -58
  53. package/src/tablecaption/toggletablecaptioncommand.d.ts +73 -0
  54. package/src/tablecaption/toggletablecaptioncommand.js +77 -92
  55. package/src/tablecaption/utils.d.ts +42 -0
  56. package/src/tablecaption/utils.js +35 -61
  57. package/src/tablecaption.d.ts +27 -0
  58. package/src/tablecaption.js +12 -19
  59. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +37 -0
  60. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +14 -20
  61. package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +42 -0
  62. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +27 -37
  63. package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +42 -0
  64. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +27 -37
  65. package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +56 -0
  66. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +42 -53
  67. package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +51 -0
  68. package/src/tablecellproperties/commands/tablecellheightcommand.js +29 -36
  69. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +37 -0
  70. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +14 -20
  71. package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +56 -0
  72. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +42 -53
  73. package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -0
  74. package/src/tablecellproperties/commands/tablecellpropertycommand.js +77 -122
  75. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +45 -0
  76. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +14 -20
  77. package/src/tablecellproperties/tablecellpropertiesediting.d.ts +47 -0
  78. package/src/tablecellproperties/tablecellpropertiesediting.js +194 -236
  79. package/src/tablecellproperties/tablecellpropertiesui.d.ts +117 -0
  80. package/src/tablecellproperties/tablecellpropertiesui.js +303 -456
  81. package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +227 -0
  82. package/src/tablecellproperties/ui/tablecellpropertiesview.js +509 -844
  83. package/src/tablecellproperties.d.ts +33 -0
  84. package/src/tablecellproperties.js +12 -98
  85. package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +51 -0
  86. package/src/tablecellwidth/commands/tablecellwidthcommand.js +29 -35
  87. package/src/tablecellwidth/tablecellwidthediting.d.ts +34 -0
  88. package/src/tablecellwidth/tablecellwidthediting.js +26 -38
  89. package/src/tableclipboard.d.ts +68 -0
  90. package/src/tableclipboard.js +429 -568
  91. package/src/tablecolumnresize/constants.d.ts +20 -0
  92. package/src/tablecolumnresize/constants.js +0 -10
  93. package/src/tablecolumnresize/converters.d.ts +18 -0
  94. package/src/tablecolumnresize/converters.js +35 -119
  95. package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +142 -0
  96. package/src/tablecolumnresize/tablecolumnresizeediting.js +545 -711
  97. package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -0
  98. package/src/tablecolumnresize/tablewidthscommand.js +61 -0
  99. package/src/tablecolumnresize/utils.d.ts +141 -0
  100. package/src/tablecolumnresize/utils.js +256 -233
  101. package/src/tablecolumnresize.d.ts +29 -0
  102. package/src/tablecolumnresize.js +12 -19
  103. package/src/tableconfig.d.ts +341 -0
  104. package/src/tableconfig.js +5 -0
  105. package/src/tableediting.d.ts +102 -0
  106. package/src/tableediting.js +157 -176
  107. package/src/tablekeyboard.d.ts +68 -0
  108. package/src/tablekeyboard.js +261 -344
  109. package/src/tablemouse/mouseeventsobserver.d.ts +62 -0
  110. package/src/tablemouse/mouseeventsobserver.js +12 -49
  111. package/src/tablemouse.d.ts +51 -0
  112. package/src/tablemouse.js +154 -202
  113. package/src/tableproperties/commands/tablealignmentcommand.d.ts +37 -0
  114. package/src/tableproperties/commands/tablealignmentcommand.js +14 -20
  115. package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +37 -0
  116. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +14 -20
  117. package/src/tableproperties/commands/tablebordercolorcommand.d.ts +42 -0
  118. package/src/tableproperties/commands/tablebordercolorcommand.js +27 -37
  119. package/src/tableproperties/commands/tableborderstylecommand.d.ts +42 -0
  120. package/src/tableproperties/commands/tableborderstylecommand.js +27 -37
  121. package/src/tableproperties/commands/tableborderwidthcommand.d.ts +56 -0
  122. package/src/tableproperties/commands/tableborderwidthcommand.js +42 -53
  123. package/src/tableproperties/commands/tableheightcommand.d.ts +51 -0
  124. package/src/tableproperties/commands/tableheightcommand.js +29 -33
  125. package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -0
  126. package/src/tableproperties/commands/tablepropertycommand.js +68 -112
  127. package/src/tableproperties/commands/tablewidthcommand.d.ts +51 -0
  128. package/src/tableproperties/commands/tablewidthcommand.js +29 -33
  129. package/src/tableproperties/tablepropertiesediting.d.ts +45 -0
  130. package/src/tableproperties/tablepropertiesediting.js +164 -210
  131. package/src/tableproperties/tablepropertiesui.d.ts +119 -0
  132. package/src/tableproperties/tablepropertiesui.js +294 -439
  133. package/src/tableproperties/ui/tablepropertiesview.d.ts +203 -0
  134. package/src/tableproperties/ui/tablepropertiesview.js +427 -718
  135. package/src/tableproperties.d.ts +33 -0
  136. package/src/tableproperties.js +12 -95
  137. package/src/tableselection.d.ts +111 -0
  138. package/src/tableselection.js +279 -376
  139. package/src/tabletoolbar.d.ts +37 -0
  140. package/src/tabletoolbar.js +39 -92
  141. package/src/tableui.d.ts +58 -0
  142. package/src/tableui.js +281 -338
  143. package/src/tableutils.d.ts +453 -0
  144. package/src/tableutils.js +1015 -1229
  145. package/src/tablewalker.d.ts +323 -0
  146. package/src/tablewalker.js +308 -548
  147. package/src/ui/colorinputview.d.ts +143 -0
  148. package/src/ui/colorinputview.js +229 -366
  149. package/src/ui/formrowview.d.ts +61 -0
  150. package/src/ui/formrowview.js +38 -84
  151. package/src/ui/inserttableview.d.ts +77 -0
  152. package/src/ui/inserttableview.js +152 -242
  153. package/src/utils/common.d.ts +42 -0
  154. package/src/utils/common.js +33 -57
  155. package/src/utils/structure.d.ts +245 -0
  156. package/src/utils/structure.js +261 -379
  157. package/src/utils/table-properties.d.ts +67 -0
  158. package/src/utils/table-properties.js +60 -81
  159. package/src/utils/ui/contextualballoon.d.ts +34 -0
  160. package/src/utils/ui/contextualballoon.js +70 -89
  161. package/src/utils/ui/table-properties.d.ts +193 -0
  162. package/src/utils/ui/table-properties.js +259 -319
  163. package/src/utils/ui/widget.d.ts +16 -0
  164. package/src/utils/ui/widget.js +24 -46
  165. package/src/tablecolumnresize/tablecolumnwidthscommand.js +0 -55
  166. package/src/tablecolumnresize/tablewidthresizecommand.js +0 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-table",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "Table feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,35 +12,36 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^36.0.1",
15
+ "ckeditor5": "^37.0.0-alpha.0",
16
16
  "lodash-es": "^4.17.15"
17
17
  },
18
18
  "devDependencies": {
19
- "@ckeditor/ckeditor5-alignment": "^36.0.1",
20
- "@ckeditor/ckeditor5-basic-styles": "^36.0.1",
21
- "@ckeditor/ckeditor5-block-quote": "^36.0.1",
22
- "@ckeditor/ckeditor5-clipboard": "^36.0.1",
23
- "@ckeditor/ckeditor5-core": "^36.0.1",
24
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
25
- "@ckeditor/ckeditor5-editor-classic": "^36.0.1",
26
- "@ckeditor/ckeditor5-engine": "^36.0.1",
27
- "@ckeditor/ckeditor5-highlight": "^36.0.1",
28
- "@ckeditor/ckeditor5-horizontal-line": "^36.0.1",
29
- "@ckeditor/ckeditor5-html-support": "^36.0.1",
30
- "@ckeditor/ckeditor5-image": "^36.0.1",
31
- "@ckeditor/ckeditor5-indent": "^36.0.1",
32
- "@ckeditor/ckeditor5-link": "^36.0.1",
33
- "@ckeditor/ckeditor5-list": "^36.0.1",
34
- "@ckeditor/ckeditor5-media-embed": "^36.0.1",
35
- "@ckeditor/ckeditor5-paragraph": "^36.0.1",
36
- "@ckeditor/ckeditor5-theme-lark": "^36.0.1",
37
- "@ckeditor/ckeditor5-typing": "^36.0.1",
38
- "@ckeditor/ckeditor5-ui": "^36.0.1",
39
- "@ckeditor/ckeditor5-undo": "^36.0.1",
40
- "@ckeditor/ckeditor5-utils": "^36.0.1",
41
- "@ckeditor/ckeditor5-widget": "^36.0.1",
42
- "@ckeditor/ckeditor5-source-editing": "^36.0.1",
19
+ "@ckeditor/ckeditor5-alignment": "^37.0.0-alpha.0",
20
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.0",
21
+ "@ckeditor/ckeditor5-block-quote": "^37.0.0-alpha.0",
22
+ "@ckeditor/ckeditor5-clipboard": "^37.0.0-alpha.0",
23
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
24
+ "@ckeditor/ckeditor5-dev-utils": "^34.0.0",
25
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
26
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0",
27
+ "@ckeditor/ckeditor5-highlight": "^37.0.0-alpha.0",
28
+ "@ckeditor/ckeditor5-horizontal-line": "^37.0.0-alpha.0",
29
+ "@ckeditor/ckeditor5-html-support": "^37.0.0-alpha.0",
30
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.0",
31
+ "@ckeditor/ckeditor5-indent": "^37.0.0-alpha.0",
32
+ "@ckeditor/ckeditor5-link": "^37.0.0-alpha.0",
33
+ "@ckeditor/ckeditor5-list": "^37.0.0-alpha.0",
34
+ "@ckeditor/ckeditor5-media-embed": "^37.0.0-alpha.0",
35
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
36
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.0",
37
+ "@ckeditor/ckeditor5-typing": "^37.0.0-alpha.0",
38
+ "@ckeditor/ckeditor5-ui": "^37.0.0-alpha.0",
39
+ "@ckeditor/ckeditor5-undo": "^37.0.0-alpha.0",
40
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.0",
41
+ "@ckeditor/ckeditor5-widget": "^37.0.0-alpha.0",
42
+ "@ckeditor/ckeditor5-source-editing": "^37.0.0-alpha.0",
43
43
  "json-diff": "^0.5.4",
44
+ "typescript": "^4.8.4",
44
45
  "webpack": "^5.58.1",
45
46
  "webpack-cli": "^4.9.0"
46
47
  },
@@ -59,13 +60,17 @@
59
60
  },
60
61
  "files": [
61
62
  "lang",
62
- "src",
63
+ "src/**/*.js",
64
+ "src/**/*.d.ts",
63
65
  "theme",
64
66
  "build",
65
67
  "ckeditor5-metadata.json",
66
68
  "CHANGELOG.md"
67
69
  ],
68
70
  "scripts": {
69
- "dll:build": "webpack"
70
- }
71
+ "dll:build": "webpack",
72
+ "build": "tsc -p ./tsconfig.release.json",
73
+ "postversion": "npm run build"
74
+ },
75
+ "types": "src/index.d.ts"
71
76
  }
@@ -0,0 +1,61 @@
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/commands/insertcolumncommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The insert column command.
11
+ *
12
+ * The command is registered by {@link module:table/tableediting~TableEditing} as the `'insertTableColumnLeft'` and
13
+ * `'insertTableColumnRight'` editor commands.
14
+ *
15
+ * To insert a column to the left of the selected cell, execute the following command:
16
+ *
17
+ * ```ts
18
+ * editor.execute( 'insertTableColumnLeft' );
19
+ * ```
20
+ *
21
+ * To insert a column to the right of the selected cell, execute the following command:
22
+ *
23
+ * ```ts
24
+ * editor.execute( 'insertTableColumnRight' );
25
+ * ```
26
+ */
27
+ export default class InsertColumnCommand extends Command {
28
+ /**
29
+ * The order of insertion relative to the column in which the caret is located.
30
+ */
31
+ readonly order: 'left' | 'right';
32
+ /**
33
+ * Creates a new `InsertColumnCommand` instance.
34
+ *
35
+ * @param editor An editor on which this command will be used.
36
+ * @param options.order The order of insertion relative to the column in which the caret is located.
37
+ * Possible values: `"left"` and `"right"`. Default value is "right".
38
+ */
39
+ constructor(editor: Editor, options?: {
40
+ order?: 'left' | 'right';
41
+ });
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ refresh(): void;
46
+ /**
47
+ * Executes the command.
48
+ *
49
+ * Depending on the command's {@link #order} value, it inserts a column to the `'left'` or `'right'` of the column
50
+ * in which the selection is set.
51
+ *
52
+ * @fires execute
53
+ */
54
+ execute(): void;
55
+ }
56
+ declare module '@ckeditor/ckeditor5-core' {
57
+ interface CommandsMap {
58
+ insertTableColumnLeft: InsertColumnCommand;
59
+ insertTableColumnRight: InsertColumnCommand;
60
+ }
61
+ }
@@ -2,13 +2,10 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module table/commands/insertcolumncommand
8
7
  */
9
-
10
8
  import { Command } from 'ckeditor5/src/core';
11
-
12
9
  /**
13
10
  * The insert column command.
14
11
  *
@@ -17,66 +14,54 @@ import { Command } from 'ckeditor5/src/core';
17
14
  *
18
15
  * To insert a column to the left of the selected cell, execute the following command:
19
16
  *
20
- * editor.execute( 'insertTableColumnLeft' );
17
+ * ```ts
18
+ * editor.execute( 'insertTableColumnLeft' );
19
+ * ```
21
20
  *
22
21
  * To insert a column to the right of the selected cell, execute the following command:
23
22
  *
24
- * editor.execute( 'insertTableColumnRight' );
25
- *
26
- * @extends module:core/command~Command
23
+ * ```ts
24
+ * editor.execute( 'insertTableColumnRight' );
25
+ * ```
27
26
  */
28
27
  export default class InsertColumnCommand extends Command {
29
- /**
30
- * Creates a new `InsertColumnCommand` instance.
31
- *
32
- * @param {module:core/editor/editor~Editor} editor An editor on which this command will be used.
33
- * @param {Object} options
34
- * @param {String} [options.order="right"] The order of insertion relative to the column in which the caret is located.
35
- * Possible values: `"left"` and `"right"`.
36
- */
37
- constructor( editor, options = {} ) {
38
- super( editor );
39
-
40
- /**
41
- * The order of insertion relative to the column in which the caret is located.
42
- *
43
- * @readonly
44
- * @member {String} module:table/commands/insertcolumncommand~InsertColumnCommand#order
45
- */
46
- this.order = options.order || 'right';
47
- }
48
-
49
- /**
50
- * @inheritDoc
51
- */
52
- refresh() {
53
- const selection = this.editor.model.document.selection;
54
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
55
- const isAnyCellSelected = !!tableUtils.getSelectionAffectedTableCells( selection ).length;
56
-
57
- this.isEnabled = isAnyCellSelected;
58
- }
59
-
60
- /**
61
- * Executes the command.
62
- *
63
- * Depending on the command's {@link #order} value, it inserts a column to the `'left'` or `'right'` of the column
64
- * in which the selection is set.
65
- *
66
- * @fires execute
67
- */
68
- execute() {
69
- const editor = this.editor;
70
- const selection = editor.model.document.selection;
71
- const tableUtils = editor.plugins.get( 'TableUtils' );
72
- const insertBefore = this.order === 'left';
73
-
74
- const affectedTableCells = tableUtils.getSelectionAffectedTableCells( selection );
75
- const columnIndexes = tableUtils.getColumnIndexes( affectedTableCells );
76
-
77
- const column = insertBefore ? columnIndexes.first : columnIndexes.last;
78
- const table = affectedTableCells[ 0 ].findAncestor( 'table' );
79
-
80
- tableUtils.insertColumns( table, { columns: 1, at: insertBefore ? column : column + 1 } );
81
- }
28
+ /**
29
+ * Creates a new `InsertColumnCommand` instance.
30
+ *
31
+ * @param editor An editor on which this command will be used.
32
+ * @param options.order The order of insertion relative to the column in which the caret is located.
33
+ * Possible values: `"left"` and `"right"`. Default value is "right".
34
+ */
35
+ constructor(editor, options = {}) {
36
+ super(editor);
37
+ this.order = options.order || 'right';
38
+ }
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ refresh() {
43
+ const selection = this.editor.model.document.selection;
44
+ const tableUtils = this.editor.plugins.get('TableUtils');
45
+ const isAnyCellSelected = !!tableUtils.getSelectionAffectedTableCells(selection).length;
46
+ this.isEnabled = isAnyCellSelected;
47
+ }
48
+ /**
49
+ * Executes the command.
50
+ *
51
+ * Depending on the command's {@link #order} value, it inserts a column to the `'left'` or `'right'` of the column
52
+ * in which the selection is set.
53
+ *
54
+ * @fires execute
55
+ */
56
+ execute() {
57
+ const editor = this.editor;
58
+ const selection = editor.model.document.selection;
59
+ const tableUtils = editor.plugins.get('TableUtils');
60
+ const insertBefore = this.order === 'left';
61
+ const affectedTableCells = tableUtils.getSelectionAffectedTableCells(selection);
62
+ const columnIndexes = tableUtils.getColumnIndexes(affectedTableCells);
63
+ const column = insertBefore ? columnIndexes.first : columnIndexes.last;
64
+ const table = affectedTableCells[0].findAncestor('table');
65
+ tableUtils.insertColumns(table, { columns: 1, at: insertBefore ? column : column + 1 });
66
+ }
82
67
  }
@@ -0,0 +1,60 @@
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/commands/insertrowcommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The insert row command.
11
+ *
12
+ * The command is registered by {@link module:table/tableediting~TableEditing} as the `'insertTableRowBelow'` and
13
+ * `'insertTableRowAbove'` editor commands.
14
+ *
15
+ * To insert a row below the selected cell, execute the following command:
16
+ *
17
+ * ```ts
18
+ * editor.execute( 'insertTableRowBelow' );
19
+ * ```
20
+ *
21
+ * To insert a row above the selected cell, execute the following command:
22
+ *
23
+ * ```ts
24
+ * editor.execute( 'insertTableRowAbove' );
25
+ * ```
26
+ */
27
+ export default class InsertRowCommand extends Command {
28
+ /**
29
+ * The order of insertion relative to the row in which the caret is located.
30
+ */
31
+ readonly order: 'above' | 'below';
32
+ /**
33
+ * Creates a new `InsertRowCommand` instance.
34
+ *
35
+ * @param editor The editor on which this command will be used.
36
+ * @param options.order The order of insertion relative to the row in which the caret is located.
37
+ * Possible values: `"above"` and `"below"`. Default value is "below"
38
+ */
39
+ constructor(editor: Editor, options?: {
40
+ order?: 'above' | 'below';
41
+ });
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ refresh(): void;
46
+ /**
47
+ * Executes the command.
48
+ *
49
+ * Depending on the command's {@link #order} value, it inserts a row `'below'` or `'above'` the row in which selection is set.
50
+ *
51
+ * @fires execute
52
+ */
53
+ execute(): void;
54
+ }
55
+ declare module '@ckeditor/ckeditor5-core' {
56
+ interface CommandsMap {
57
+ insertTableRowAbove: InsertRowCommand;
58
+ insertTableRowBelow: InsertRowCommand;
59
+ }
60
+ }
@@ -2,13 +2,10 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module table/commands/insertrowcommand
8
7
  */
9
-
10
8
  import { Command } from 'ckeditor5/src/core';
11
-
12
9
  /**
13
10
  * The insert row command.
14
11
  *
@@ -17,65 +14,53 @@ import { Command } from 'ckeditor5/src/core';
17
14
  *
18
15
  * To insert a row below the selected cell, execute the following command:
19
16
  *
20
- * editor.execute( 'insertTableRowBelow' );
17
+ * ```ts
18
+ * editor.execute( 'insertTableRowBelow' );
19
+ * ```
21
20
  *
22
21
  * To insert a row above the selected cell, execute the following command:
23
22
  *
24
- * editor.execute( 'insertTableRowAbove' );
25
- *
26
- * @extends module:core/command~Command
23
+ * ```ts
24
+ * editor.execute( 'insertTableRowAbove' );
25
+ * ```
27
26
  */
28
27
  export default class InsertRowCommand extends Command {
29
- /**
30
- * Creates a new `InsertRowCommand` instance.
31
- *
32
- * @param {module:core/editor/editor~Editor} editor The editor on which this command will be used.
33
- * @param {Object} options
34
- * @param {String} [options.order="below"] The order of insertion relative to the row in which the caret is located.
35
- * Possible values: `"above"` and `"below"`.
36
- */
37
- constructor( editor, options = {} ) {
38
- super( editor );
39
-
40
- /**
41
- * The order of insertion relative to the row in which the caret is located.
42
- *
43
- * @readonly
44
- * @member {String} module:table/commands/insertrowcommand~InsertRowCommand#order
45
- */
46
- this.order = options.order || 'below';
47
- }
48
-
49
- /**
50
- * @inheritDoc
51
- */
52
- refresh() {
53
- const selection = this.editor.model.document.selection;
54
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
55
- const isAnyCellSelected = !!tableUtils.getSelectionAffectedTableCells( selection ).length;
56
-
57
- this.isEnabled = isAnyCellSelected;
58
- }
59
-
60
- /**
61
- * Executes the command.
62
- *
63
- * Depending on the command's {@link #order} value, it inserts a row `'below'` or `'above'` the row in which selection is set.
64
- *
65
- * @fires execute
66
- */
67
- execute() {
68
- const editor = this.editor;
69
- const selection = editor.model.document.selection;
70
- const tableUtils = editor.plugins.get( 'TableUtils' );
71
- const insertAbove = this.order === 'above';
72
-
73
- const affectedTableCells = tableUtils.getSelectionAffectedTableCells( selection );
74
- const rowIndexes = tableUtils.getRowIndexes( affectedTableCells );
75
-
76
- const row = insertAbove ? rowIndexes.first : rowIndexes.last;
77
- const table = affectedTableCells[ 0 ].findAncestor( 'table' );
78
-
79
- tableUtils.insertRows( table, { at: insertAbove ? row : row + 1, copyStructureFromAbove: !insertAbove } );
80
- }
28
+ /**
29
+ * Creates a new `InsertRowCommand` instance.
30
+ *
31
+ * @param editor The editor on which this command will be used.
32
+ * @param options.order The order of insertion relative to the row in which the caret is located.
33
+ * Possible values: `"above"` and `"below"`. Default value is "below"
34
+ */
35
+ constructor(editor, options = {}) {
36
+ super(editor);
37
+ this.order = options.order || 'below';
38
+ }
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ refresh() {
43
+ const selection = this.editor.model.document.selection;
44
+ const tableUtils = this.editor.plugins.get('TableUtils');
45
+ const isAnyCellSelected = !!tableUtils.getSelectionAffectedTableCells(selection).length;
46
+ this.isEnabled = isAnyCellSelected;
47
+ }
48
+ /**
49
+ * Executes the command.
50
+ *
51
+ * Depending on the command's {@link #order} value, it inserts a row `'below'` or `'above'` the row in which selection is set.
52
+ *
53
+ * @fires execute
54
+ */
55
+ execute() {
56
+ const editor = this.editor;
57
+ const selection = editor.model.document.selection;
58
+ const tableUtils = editor.plugins.get('TableUtils');
59
+ const insertAbove = this.order === 'above';
60
+ const affectedTableCells = tableUtils.getSelectionAffectedTableCells(selection);
61
+ const rowIndexes = tableUtils.getRowIndexes(affectedTableCells);
62
+ const row = insertAbove ? rowIndexes.first : rowIndexes.last;
63
+ const table = affectedTableCells[0].findAncestor('table');
64
+ tableUtils.insertRows(table, { at: insertAbove ? row : row + 1, copyStructureFromAbove: !insertAbove });
65
+ }
81
66
  }
@@ -0,0 +1,50 @@
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/commands/inserttablecommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ import '../tableconfig';
10
+ /**
11
+ * The insert table command.
12
+ *
13
+ * The command is registered by {@link module:table/tableediting~TableEditing} as the `'insertTable'` editor command.
14
+ *
15
+ * To insert a table at the current selection, execute the command and specify the dimensions:
16
+ *
17
+ * ```ts
18
+ * editor.execute( 'insertTable', { rows: 20, columns: 5 } );
19
+ * ```
20
+ */
21
+ export default class InsertTableCommand extends Command {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ refresh(): void;
26
+ /**
27
+ * Executes the command.
28
+ *
29
+ * Inserts a table with the given number of rows and columns into the editor.
30
+ *
31
+ * @param options.rows The number of rows to create in the inserted table. Default value is 2.
32
+ * @param options.columns The number of columns to create in the inserted table. Default value is 2.
33
+ * @param options.headingRows The number of heading rows. If not provided it will default to
34
+ * {@link module:table/tableconfig~TableConfig#defaultHeadings `config.table.defaultHeadings.rows`} table config.
35
+ * @param options.headingColumns The number of heading columns. If not provided it will default to
36
+ * {@link module:table/tableconfig~TableConfig#defaultHeadings `config.table.defaultHeadings.columns`} table config.
37
+ * @fires execute
38
+ */
39
+ execute(options?: {
40
+ rows?: number;
41
+ columns?: number;
42
+ headingRows?: number;
43
+ headingColumns?: number;
44
+ }): void;
45
+ }
46
+ declare module '@ckeditor/ckeditor5-core' {
47
+ interface CommandsMap {
48
+ insertTable: InsertTableCommand;
49
+ }
50
+ }
@@ -2,13 +2,11 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module table/commands/inserttablecommand
8
7
  */
9
-
10
8
  import { Command } from 'ckeditor5/src/core';
11
-
9
+ import '../tableconfig';
12
10
  /**
13
11
  * The insert table command.
14
12
  *
@@ -16,72 +14,57 @@ import { Command } from 'ckeditor5/src/core';
16
14
  *
17
15
  * To insert a table at the current selection, execute the command and specify the dimensions:
18
16
  *
19
- * editor.execute( 'insertTable', { rows: 20, columns: 5 } );
20
- *
21
- * @extends module:core/command~Command
17
+ * ```ts
18
+ * editor.execute( 'insertTable', { rows: 20, columns: 5 } );
19
+ * ```
22
20
  */
23
21
  export default class InsertTableCommand extends Command {
24
- /**
25
- * @inheritDoc
26
- */
27
- refresh() {
28
- const model = this.editor.model;
29
- const selection = model.document.selection;
30
- const schema = model.schema;
31
-
32
- this.isEnabled = isAllowedInParent( selection, schema );
33
- }
34
-
35
- /**
36
- * Executes the command.
37
- *
38
- * Inserts a table with the given number of rows and columns into the editor.
39
- *
40
- * @param {Object} options
41
- * @param {Number} [options.rows=2] The number of rows to create in the inserted table.
42
- * @param {Number} [options.columns=2] The number of columns to create in the inserted table.
43
- * @param {Number} [options.headingRows] The number of heading rows.
44
- * If not provided it will default to {@link module:table/table~TableConfig#defaultHeadings `config.table.defaultHeadings.rows`}
45
- * table config.
46
- * @param {Number} [options.headingColumns] The number of heading columns.
47
- * If not provided it will default to {@link module:table/table~TableConfig#defaultHeadings `config.table.defaultHeadings.columns`}
48
- * table config.
49
- * @fires execute
50
- */
51
- execute( options = {} ) {
52
- const model = this.editor.model;
53
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
54
- const config = this.editor.config.get( 'table' );
55
-
56
- const defaultRows = config.defaultHeadings.rows;
57
- const defaultColumns = config.defaultHeadings.columns;
58
-
59
- if ( options.headingRows === undefined && defaultRows ) {
60
- options.headingRows = defaultRows;
61
- }
62
-
63
- if ( options.headingColumns === undefined && defaultColumns ) {
64
- options.headingColumns = defaultColumns;
65
- }
66
-
67
- model.change( writer => {
68
- const table = tableUtils.createTable( writer, options );
69
-
70
- model.insertObject( table, null, null, { findOptimalPosition: 'auto' } );
71
-
72
- writer.setSelection( writer.createPositionAt( table.getNodeByPath( [ 0, 0, 0 ] ), 0 ) );
73
- } );
74
- }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ refresh() {
26
+ const model = this.editor.model;
27
+ const selection = model.document.selection;
28
+ const schema = model.schema;
29
+ this.isEnabled = isAllowedInParent(selection, schema);
30
+ }
31
+ /**
32
+ * Executes the command.
33
+ *
34
+ * Inserts a table with the given number of rows and columns into the editor.
35
+ *
36
+ * @param options.rows The number of rows to create in the inserted table. Default value is 2.
37
+ * @param options.columns The number of columns to create in the inserted table. Default value is 2.
38
+ * @param options.headingRows The number of heading rows. If not provided it will default to
39
+ * {@link module:table/tableconfig~TableConfig#defaultHeadings `config.table.defaultHeadings.rows`} table config.
40
+ * @param options.headingColumns The number of heading columns. If not provided it will default to
41
+ * {@link module:table/tableconfig~TableConfig#defaultHeadings `config.table.defaultHeadings.columns`} table config.
42
+ * @fires execute
43
+ */
44
+ execute(options = {}) {
45
+ const editor = this.editor;
46
+ const model = editor.model;
47
+ const tableUtils = editor.plugins.get('TableUtils');
48
+ const defaultRows = editor.config.get('table.defaultHeadings.rows');
49
+ const defaultColumns = editor.config.get('table.defaultHeadings.columns');
50
+ if (options.headingRows === undefined && defaultRows) {
51
+ options.headingRows = defaultRows;
52
+ }
53
+ if (options.headingColumns === undefined && defaultColumns) {
54
+ options.headingColumns = defaultColumns;
55
+ }
56
+ model.change(writer => {
57
+ const table = tableUtils.createTable(writer, options);
58
+ model.insertObject(table, null, null, { findOptimalPosition: 'auto' });
59
+ writer.setSelection(writer.createPositionAt(table.getNodeByPath([0, 0, 0]), 0));
60
+ });
61
+ }
75
62
  }
76
-
77
- // Checks if the table is allowed in the parent.
78
- //
79
- // @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
80
- // @param {module:engine/model/schema~Schema} schema
81
- // @returns {Boolean}
82
- function isAllowedInParent( selection, schema ) {
83
- const positionParent = selection.getFirstPosition().parent;
84
- const validParent = positionParent === positionParent.root ? positionParent : positionParent.parent;
85
-
86
- return schema.checkChild( validParent, 'table' );
63
+ /**
64
+ * Checks if the table is allowed in the parent.
65
+ */
66
+ function isAllowedInParent(selection, schema) {
67
+ const positionParent = selection.getFirstPosition().parent;
68
+ const validParent = positionParent === positionParent.root ? positionParent : positionParent.parent;
69
+ return schema.checkChild(validParent, 'table');
87
70
  }