qms-angular 1.0.87 → 1.0.88
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/README.md +5 -1
- package/bundles/qms-angular.umd.js +121 -29
- package/bundles/qms-angular.umd.js.map +1 -1
- package/esm2015/lib/components/badges/qms-badges.component.js +1 -1
- package/esm2015/lib/components/banner/qms-banner/qms-banner.component.js +1 -1
- package/esm2015/lib/components/banner/qms-banner-confirm/qms-banner-confirm.component.js +1 -1
- package/esm2015/lib/components/banner/qms-banner-loading/qms-banner-loading.component.js +1 -1
- package/esm2015/lib/components/button/button-toggle.js +1 -1
- package/esm2015/lib/components/button/button.js +3 -3
- package/esm2015/lib/components/comment/comment.js +1 -1
- package/esm2015/lib/components/dialog/dialog.js +2 -2
- package/esm2015/lib/components/list/list.js +2 -2
- package/esm2015/lib/components/qms-paginator/qms-paginator.component.js +16 -7
- package/esm2015/lib/components/related/list-other-related/list-related.component.js +1 -1
- package/esm2015/lib/components/related/risk/list/list.component.js +1 -1
- package/esm2015/lib/components/related/risk/result/result.component.js +1 -1
- package/esm2015/lib/components/rich-text/rich-text.js +1 -1
- package/esm2015/lib/components/table/table-action.js +2 -2
- package/esm2015/lib/components/tooltip/tooltip.js +1 -1
- package/esm2015/lib/components/tree/tree.component.js +1 -1
- package/esm2015/lib/components/treeNew/tree.component.js +18 -2
- package/esm2015/lib/directives/text-truncate/text-truncate.directive.js +54 -0
- package/esm2015/lib/qms-angular.module.js +4 -1
- package/esm2015/lib/qms-ckeditor-components/common/functions/common.function.js +3 -1
- package/esm2015/lib/qms-ckeditor-components/qms-ckeditor.component.js +1 -1
- package/esm2015/public-api.js +2 -1
- package/fesm2015/qms-angular.js +112 -30
- package/fesm2015/qms-angular.js.map +1 -1
- package/lib/components/qms-paginator/qms-paginator.component.d.ts +1 -0
- package/lib/components/treeNew/tree.component.d.ts +1 -0
- package/lib/directives/text-truncate/text-truncate.directive.d.ts +14 -0
- package/lib.theme.scss +178 -3
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
- package/qms-angular.metadata.json +1 -1
- package/src/assets/fonts/Material/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2 +0 -0
- package/src/assets/fonts/Material/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUce.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFUZ0bbck.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFVZ0b.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFVp0bbck.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFW50bbck.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFWJ0bbck.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFWZ0bbck.woff2 +0 -0
- package/src/assets/fonts/OpenSans/mem8YaGs126MiZpBA-UFWp0bbck.woff2 +0 -0
- package/src/assets/fonts/Raleway/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCFPrEHJA.woff2 +0 -0
- package/src/assets/fonts/Raleway/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCGPrEHJA.woff2 +0 -0
- package/src/assets/fonts/Raleway/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCHPrEHJA.woff2 +0 -0
- package/src/assets/fonts/Raleway/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCIPrE.woff2 +0 -0
- package/src/assets/fonts/Raleway/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCMPrEHJA.woff2 +0 -0
- package/src/assets/qms-ckeditor-plugin/build/ckeditor.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/ckeditor.js.map +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ar.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/az.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/bg.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/cs.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/da.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/de-ch.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/de.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/en-au.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/en-gb.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/es.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/et.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/fa.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/fi.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/fr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/gl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/hi.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/hr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/hu.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/id.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/it.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ja.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ko.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ku.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/lt.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/lv.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/nb.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ne.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/nl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/no.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/pl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/pt-br.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ro.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ru.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sk.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sq.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sr-latn.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sv.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/th.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/tk.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/tr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ug.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/uk.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/vi.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/zh-cn.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/zh.js +1 -1
- package/src/assets/qms-ckeditor-plugin/package-lock.json +0 -1
- package/src/assets/qms-ckeditor-plugin/package.json +0 -1
- package/src/assets/qms-ckeditor-plugin/src/ckeditor.js +5 -5
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/insertcolumncommand.js +83 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/insertrowcommand.js +82 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/inserttablecommand.js +76 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/mergecellcommand.js +272 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/mergecellscommand.js +122 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/removecolumncommand.js +122 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/removerowcommand.js +97 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/selectcolumncommand.js +63 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/selectrowcommand.js +56 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/setheadercolumncommand.js +95 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/setheaderrowcommand.js +105 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/commands/splitcellcommand.js +68 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/downcast.js +529 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/table-cell-paragraph-post-fixer.js +136 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/table-cell-refresh-post-fixer.js +75 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/table-heading-rows-refresh-post-fixer.js +55 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/table-layout-post-fixer.js +399 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/tableproperties.js +126 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/converters/upcasttable.js +211 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/index.js +42 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/table.js +103 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +35 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellbordercolorcommand.js +47 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellborderstylecommand.js +47 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellborderwidthcommand.js +62 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellheightcommand.js +51 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +35 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellpaddingcommand.js +62 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellpropertycommand.js +110 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellverticalalignmentcommand.js +43 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/commands/tablecellwidthcommand.js +51 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/tablecellpropertiesediting.js +204 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/tablecellpropertiesui.js +401 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties/ui/tablecellpropertiesview.js +829 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablecellproperties.js +80 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableclipboard.js +586 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableediting.js +160 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablekeyboard.js +343 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablemouse/mouseeventsobserver.js +72 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablemouse.js +218 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tablealignmentcommand.js +35 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tablebackgroundcolorcommand.js +35 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tablebordercolorcommand.js +47 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tableborderstylecommand.js +47 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tableborderwidthcommand.js +62 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tableheightcommand.js +51 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tablepropertycommand.js +98 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/commands/tablewidthcommand.js +51 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/tablepropertiesediting.js +182 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/tablepropertiesui.js +397 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties/ui/tablepropertiesview.js +714 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableproperties.js +81 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableselection.js +357 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tabletoolbar.js +111 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableui.js +359 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tableutils.js +909 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/tablewalker.js +538 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/colorinput.css +39 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/form.css +11 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/formrow.css +23 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/icons/table-cell-properties.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/icons/table-column.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/icons/table-merge-cell.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/icons/table-properties.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/icons/table-row.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/icons/table.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/inserttable.css +10 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/snippet.css +3876 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/table.css +67 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/tablecaption.css +53 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/tablecellproperties.css +28 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/tableediting.css +10 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/tableform.css +59 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/tableproperties.css +18 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/theme/tableselection.css +10 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/ui/colorinputview.js +343 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/ui/formrowview.js +103 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/ui/inserttableview.js +222 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/common.js +57 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/selection.js +276 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/structure.js +543 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/table-properties.js +66 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/ui/contextualballoon.js +130 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/ui/table-properties.js +397 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/table/utils/ui/widget.js +62 -0
- package/src/lib/components/qms-paginator/qms-paginator.component.scss +4 -1
- package/src/themes/core/_mat-icon.scss +60 -60
- package/src/themes/core/_table.scss +55 -2
- package/src/themes/core/_typography.scss +108 -108
- package/src/assets/fonts/OpenSans/OpenSans.woff2 +0 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module table/commands/insertrowcommand
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Command } from 'ckeditor5/src/core';
|
11
|
+
import { getRowIndexes, getSelectionAffectedTableCells } from '../utils/selection';
|
12
|
+
|
13
|
+
/**
|
14
|
+
* The insert row command.
|
15
|
+
*
|
16
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'insertTableRowBelow'` and
|
17
|
+
* `'insertTableRowAbove'` editor commands.
|
18
|
+
*
|
19
|
+
* To insert a row below the selected cell, execute the following command:
|
20
|
+
*
|
21
|
+
* editor.execute( 'insertTableRowBelow' );
|
22
|
+
*
|
23
|
+
* To insert a row above the selected cell, execute the following command:
|
24
|
+
*
|
25
|
+
* editor.execute( 'insertTableRowAbove' );
|
26
|
+
*
|
27
|
+
* @extends module:core/command~Command
|
28
|
+
*/
|
29
|
+
export default class InsertRowCommand extends Command {
|
30
|
+
/**
|
31
|
+
* Creates a new `InsertRowCommand` instance.
|
32
|
+
*
|
33
|
+
* @param {module:core/editor/editor~Editor} editor The editor on which this command will be used.
|
34
|
+
* @param {Object} options
|
35
|
+
* @param {String} [options.order="below"] The order of insertion relative to the row in which the caret is located.
|
36
|
+
* Possible values: `"above"` and `"below"`.
|
37
|
+
*/
|
38
|
+
constructor( editor, options = {} ) {
|
39
|
+
super( editor );
|
40
|
+
|
41
|
+
/**
|
42
|
+
* The order of insertion relative to the row in which the caret is located.
|
43
|
+
*
|
44
|
+
* @readonly
|
45
|
+
* @member {String} module:table/commands/insertrowcommand~InsertRowCommand#order
|
46
|
+
*/
|
47
|
+
this.order = options.order || 'below';
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* @inheritDoc
|
52
|
+
*/
|
53
|
+
refresh() {
|
54
|
+
const selection = this.editor.model.document.selection;
|
55
|
+
|
56
|
+
const tableParent = selection.getFirstPosition().findAncestor( 'table' );
|
57
|
+
|
58
|
+
this.isEnabled = !!tableParent;
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Executes the command.
|
63
|
+
*
|
64
|
+
* Depending on the command's {@link #order} value, it inserts a row `'below'` or `'above'` the row in which 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 insertAbove = this.order === 'above';
|
73
|
+
|
74
|
+
const affectedTableCells = getSelectionAffectedTableCells( selection );
|
75
|
+
const rowIndexes = getRowIndexes( affectedTableCells );
|
76
|
+
|
77
|
+
const row = insertAbove ? rowIndexes.first : rowIndexes.last;
|
78
|
+
const table = affectedTableCells[ 0 ].findAncestor( 'table' );
|
79
|
+
|
80
|
+
tableUtils.insertRows( table, { at: insertAbove ? row : row + 1, copyStructureFromAbove: !insertAbove } );
|
81
|
+
}
|
82
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module table/commands/inserttablecommand
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Command } from 'ckeditor5/src/core';
|
11
|
+
import { findOptimalInsertionPosition, checkSelectionOnObject } from 'ckeditor5/src/widget';
|
12
|
+
|
13
|
+
/**
|
14
|
+
* The insert table command.
|
15
|
+
*
|
16
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'insertTable'` editor command.
|
17
|
+
*
|
18
|
+
* To insert a table at the current selection, execute the command and specify the dimensions:
|
19
|
+
*
|
20
|
+
* editor.execute( 'insertTable', { rows: 20, columns: 5 } );
|
21
|
+
*
|
22
|
+
* @extends module:core/command~Command
|
23
|
+
*/
|
24
|
+
export default class InsertTableCommand extends Command {
|
25
|
+
/**
|
26
|
+
* @inheritDoc
|
27
|
+
*/
|
28
|
+
refresh() {
|
29
|
+
const model = this.editor.model;
|
30
|
+
const selection = model.document.selection;
|
31
|
+
const schema = model.schema;
|
32
|
+
|
33
|
+
this.isEnabled = isAllowedInParent( selection, schema ) &&
|
34
|
+
!checkSelectionOnObject( selection, schema );
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Executes the command.
|
39
|
+
*
|
40
|
+
* Inserts a table with the given number of rows and columns into the editor.
|
41
|
+
*
|
42
|
+
* @param {Object} options
|
43
|
+
* @param {Number} [options.rows=2] The number of rows to create in the inserted table.
|
44
|
+
* @param {Number} [options.columns=2] The number of columns to create in the inserted table.
|
45
|
+
* @param {Number} [options.headingRows=0] The number of heading rows.
|
46
|
+
* @param {Number} [options.headingColumns=0] The number of heading columns.
|
47
|
+
* @fires execute
|
48
|
+
*/
|
49
|
+
execute( options = {} ) {
|
50
|
+
const model = this.editor.model;
|
51
|
+
const selection = model.document.selection;
|
52
|
+
const tableUtils = this.editor.plugins.get( 'TableUtils' );
|
53
|
+
|
54
|
+
const insertPosition = findOptimalInsertionPosition( selection, model );
|
55
|
+
|
56
|
+
model.change( writer => {
|
57
|
+
const table = tableUtils.createTable( writer, options );
|
58
|
+
|
59
|
+
model.insertContent( table, insertPosition );
|
60
|
+
|
61
|
+
writer.setSelection( writer.createPositionAt( table.getNodeByPath( [ 0, 0, 0 ] ), 0 ) );
|
62
|
+
} );
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
// Checks if the table is allowed in the parent.
|
67
|
+
//
|
68
|
+
// @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
|
69
|
+
// @param {module:engine/model/schema~Schema} schema
|
70
|
+
// @returns {Boolean}
|
71
|
+
function isAllowedInParent( selection, schema ) {
|
72
|
+
const positionParent = selection.getFirstPosition().parent;
|
73
|
+
const validParent = positionParent === positionParent.root ? positionParent : positionParent.parent;
|
74
|
+
|
75
|
+
return schema.checkChild( validParent, 'table' );
|
76
|
+
}
|
@@ -0,0 +1,272 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module table/commands/mergecellcommand
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Command } from 'ckeditor5/src/core';
|
11
|
+
import TableWalker from '../tablewalker';
|
12
|
+
import { getTableCellsContainingSelection } from '../utils/selection';
|
13
|
+
import { isHeadingColumnCell } from '../utils/common';
|
14
|
+
import { removeEmptyRowsColumns } from '../utils/structure';
|
15
|
+
|
16
|
+
/**
|
17
|
+
* The merge cell command.
|
18
|
+
*
|
19
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'mergeTableCellRight'`, `'mergeTableCellLeft'`,
|
20
|
+
* `'mergeTableCellUp'` and `'mergeTableCellDown'` editor commands.
|
21
|
+
*
|
22
|
+
* To merge a table cell at the current selection with another cell, execute the command corresponding with the preferred direction.
|
23
|
+
*
|
24
|
+
* For example, to merge with a cell to the right:
|
25
|
+
*
|
26
|
+
* editor.execute( 'mergeTableCellRight' );
|
27
|
+
*
|
28
|
+
* **Note**: If a table cell has a different [`rowspan`](https://www.w3.org/TR/html50/tabular-data.html#attr-tdth-rowspan)
|
29
|
+
* (for `'mergeTableCellRight'` and `'mergeTableCellLeft'`) or [`colspan`](https://www.w3.org/TR/html50/tabular-data.html#attr-tdth-colspan)
|
30
|
+
* (for `'mergeTableCellUp'` and `'mergeTableCellDown'`), the command will be disabled.
|
31
|
+
*
|
32
|
+
* @extends module:core/command~Command
|
33
|
+
*/
|
34
|
+
export default class MergeCellCommand extends Command {
|
35
|
+
/**
|
36
|
+
* Creates a new `MergeCellCommand` instance.
|
37
|
+
*
|
38
|
+
* @param {module:core/editor/editor~Editor} editor The editor on which this command will be used.
|
39
|
+
* @param {Object} options
|
40
|
+
* @param {String} options.direction Indicates which cell to merge with the currently selected one.
|
41
|
+
* Possible values are: `'left'`, `'right'`, `'up'` and `'down'`.
|
42
|
+
*/
|
43
|
+
constructor( editor, options ) {
|
44
|
+
super( editor );
|
45
|
+
|
46
|
+
/**
|
47
|
+
* The direction that indicates which cell will be merged with the currently selected one.
|
48
|
+
*
|
49
|
+
* @readonly
|
50
|
+
* @member {String} #direction
|
51
|
+
*/
|
52
|
+
this.direction = options.direction;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Whether the merge is horizontal (left/right) or vertical (up/down).
|
56
|
+
*
|
57
|
+
* @readonly
|
58
|
+
* @member {Boolean} #isHorizontal
|
59
|
+
*/
|
60
|
+
this.isHorizontal = this.direction == 'right' || this.direction == 'left';
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @inheritDoc
|
65
|
+
*/
|
66
|
+
refresh() {
|
67
|
+
const cellToMerge = this._getMergeableCell();
|
68
|
+
|
69
|
+
this.value = cellToMerge;
|
70
|
+
this.isEnabled = !!cellToMerge;
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Executes the command.
|
75
|
+
*
|
76
|
+
* Depending on the command's {@link #direction} value, it will merge the cell that is to the `'left'`, `'right'`, `'up'` or `'down'`.
|
77
|
+
*
|
78
|
+
* @fires execute
|
79
|
+
*/
|
80
|
+
execute() {
|
81
|
+
const model = this.editor.model;
|
82
|
+
const doc = model.document;
|
83
|
+
const tableCell = getTableCellsContainingSelection( doc.selection )[ 0 ];
|
84
|
+
|
85
|
+
const cellToMerge = this.value;
|
86
|
+
const direction = this.direction;
|
87
|
+
|
88
|
+
model.change( writer => {
|
89
|
+
const isMergeNext = direction == 'right' || direction == 'down';
|
90
|
+
|
91
|
+
// The merge mechanism is always the same so sort cells to be merged.
|
92
|
+
const cellToExpand = isMergeNext ? tableCell : cellToMerge;
|
93
|
+
const cellToRemove = isMergeNext ? cellToMerge : tableCell;
|
94
|
+
|
95
|
+
// Cache the parent of cell to remove for later check.
|
96
|
+
const removedTableCellRow = cellToRemove.parent;
|
97
|
+
|
98
|
+
mergeTableCells( cellToRemove, cellToExpand, writer );
|
99
|
+
|
100
|
+
const spanAttribute = this.isHorizontal ? 'colspan' : 'rowspan';
|
101
|
+
const cellSpan = parseInt( tableCell.getAttribute( spanAttribute ) || 1 );
|
102
|
+
const cellToMergeSpan = parseInt( cellToMerge.getAttribute( spanAttribute ) || 1 );
|
103
|
+
|
104
|
+
// Update table cell span attribute and merge set selection on merged contents.
|
105
|
+
writer.setAttribute( spanAttribute, cellSpan + cellToMergeSpan, cellToExpand );
|
106
|
+
writer.setSelection( writer.createRangeIn( cellToExpand ) );
|
107
|
+
|
108
|
+
const tableUtils = this.editor.plugins.get( 'TableUtils' );
|
109
|
+
const table = removedTableCellRow.findAncestor( 'table' );
|
110
|
+
|
111
|
+
// Remove empty rows and columns after merging.
|
112
|
+
removeEmptyRowsColumns( table, tableUtils );
|
113
|
+
} );
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Returns a cell that can be merged with the current cell depending on the command's direction.
|
118
|
+
*
|
119
|
+
* @returns {module:engine/model/element~Element|undefined}
|
120
|
+
* @private
|
121
|
+
*/
|
122
|
+
_getMergeableCell() {
|
123
|
+
const model = this.editor.model;
|
124
|
+
const doc = model.document;
|
125
|
+
const tableCell = getTableCellsContainingSelection( doc.selection )[ 0 ];
|
126
|
+
|
127
|
+
if ( !tableCell ) {
|
128
|
+
return;
|
129
|
+
}
|
130
|
+
|
131
|
+
const tableUtils = this.editor.plugins.get( 'TableUtils' );
|
132
|
+
|
133
|
+
// First get the cell on proper direction.
|
134
|
+
const cellToMerge = this.isHorizontal ?
|
135
|
+
getHorizontalCell( tableCell, this.direction, tableUtils ) :
|
136
|
+
getVerticalCell( tableCell, this.direction );
|
137
|
+
|
138
|
+
if ( !cellToMerge ) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
|
142
|
+
// If found check if the span perpendicular to merge direction is equal on both cells.
|
143
|
+
const spanAttribute = this.isHorizontal ? 'rowspan' : 'colspan';
|
144
|
+
const span = parseInt( tableCell.getAttribute( spanAttribute ) || 1 );
|
145
|
+
|
146
|
+
const cellToMergeSpan = parseInt( cellToMerge.getAttribute( spanAttribute ) || 1 );
|
147
|
+
|
148
|
+
if ( cellToMergeSpan === span ) {
|
149
|
+
return cellToMerge;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
// Returns the cell that can be merged horizontally.
|
155
|
+
//
|
156
|
+
// @param {module:engine/model/element~Element} tableCell
|
157
|
+
// @param {String} direction
|
158
|
+
// @returns {module:engine/model/node~Node|null}
|
159
|
+
function getHorizontalCell( tableCell, direction, tableUtils ) {
|
160
|
+
const tableRow = tableCell.parent;
|
161
|
+
const table = tableRow.parent;
|
162
|
+
const horizontalCell = direction == 'right' ? tableCell.nextSibling : tableCell.previousSibling;
|
163
|
+
const hasHeadingColumns = ( table.getAttribute( 'headingColumns' ) || 0 ) > 0;
|
164
|
+
|
165
|
+
if ( !horizontalCell ) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
|
169
|
+
// Sort cells:
|
170
|
+
const cellOnLeft = direction == 'right' ? tableCell : horizontalCell;
|
171
|
+
const cellOnRight = direction == 'right' ? horizontalCell : tableCell;
|
172
|
+
|
173
|
+
// Get their column indexes:
|
174
|
+
const { column: leftCellColumn } = tableUtils.getCellLocation( cellOnLeft );
|
175
|
+
const { column: rightCellColumn } = tableUtils.getCellLocation( cellOnRight );
|
176
|
+
|
177
|
+
const leftCellSpan = parseInt( cellOnLeft.getAttribute( 'colspan' ) || 1 );
|
178
|
+
|
179
|
+
const isCellOnLeftInHeadingColumn = isHeadingColumnCell( tableUtils, cellOnLeft, table );
|
180
|
+
const isCellOnRightInHeadingColumn = isHeadingColumnCell( tableUtils, cellOnRight, table );
|
181
|
+
|
182
|
+
// We cannot merge heading columns cells with regular cells.
|
183
|
+
if ( hasHeadingColumns && isCellOnLeftInHeadingColumn != isCellOnRightInHeadingColumn ) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
|
187
|
+
// The cell on the right must have index that is distant to the cell on the left by the left cell's width (colspan).
|
188
|
+
const cellsAreTouching = leftCellColumn + leftCellSpan === rightCellColumn;
|
189
|
+
|
190
|
+
// If the right cell's column index is different it means that there are rowspanned cells between them.
|
191
|
+
return cellsAreTouching ? horizontalCell : undefined;
|
192
|
+
}
|
193
|
+
|
194
|
+
// Returns the cell that can be merged vertically.
|
195
|
+
//
|
196
|
+
// @param {module:engine/model/element~Element} tableCell
|
197
|
+
// @param {String} direction
|
198
|
+
// @returns {module:engine/model/node~Node|null}
|
199
|
+
function getVerticalCell( tableCell, direction ) {
|
200
|
+
const tableRow = tableCell.parent;
|
201
|
+
const table = tableRow.parent;
|
202
|
+
|
203
|
+
const rowIndex = table.getChildIndex( tableRow );
|
204
|
+
|
205
|
+
// Don't search for mergeable cell if direction points out of the table.
|
206
|
+
if ( ( direction == 'down' && rowIndex === table.childCount - 1 ) || ( direction == 'up' && rowIndex === 0 ) ) {
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
|
210
|
+
const rowspan = parseInt( tableCell.getAttribute( 'rowspan' ) || 1 );
|
211
|
+
const headingRows = table.getAttribute( 'headingRows' ) || 0;
|
212
|
+
|
213
|
+
const isMergeWithBodyCell = direction == 'down' && ( rowIndex + rowspan ) === headingRows;
|
214
|
+
const isMergeWithHeadCell = direction == 'up' && rowIndex === headingRows;
|
215
|
+
|
216
|
+
// Don't search for mergeable cell if direction points out of the current table section.
|
217
|
+
if ( headingRows && ( isMergeWithBodyCell || isMergeWithHeadCell ) ) {
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
|
221
|
+
const currentCellRowSpan = parseInt( tableCell.getAttribute( 'rowspan' ) || 1 );
|
222
|
+
const rowOfCellToMerge = direction == 'down' ? rowIndex + currentCellRowSpan : rowIndex;
|
223
|
+
|
224
|
+
const tableMap = [ ...new TableWalker( table, { endRow: rowOfCellToMerge } ) ];
|
225
|
+
|
226
|
+
const currentCellData = tableMap.find( value => value.cell === tableCell );
|
227
|
+
const mergeColumn = currentCellData.column;
|
228
|
+
|
229
|
+
const cellToMergeData = tableMap.find( ( { row, cellHeight, column } ) => {
|
230
|
+
if ( column !== mergeColumn ) {
|
231
|
+
return false;
|
232
|
+
}
|
233
|
+
|
234
|
+
if ( direction == 'down' ) {
|
235
|
+
// If merging a cell below the mergeRow is already calculated.
|
236
|
+
return row === rowOfCellToMerge;
|
237
|
+
} else {
|
238
|
+
// If merging a cell above calculate if it spans to mergeRow.
|
239
|
+
return rowOfCellToMerge === row + cellHeight;
|
240
|
+
}
|
241
|
+
} );
|
242
|
+
|
243
|
+
return cellToMergeData && cellToMergeData.cell;
|
244
|
+
}
|
245
|
+
|
246
|
+
// Merges two table cells. It will ensure that after merging cells with an empty paragraph, the resulting table cell will only have one
|
247
|
+
// paragraph. If one of the merged table cells is empty, the merged table cell will have the contents of the non-empty table cell.
|
248
|
+
// If both are empty, the merged table cell will have only one empty paragraph.
|
249
|
+
//
|
250
|
+
// @param {module:engine/model/element~Element} cellToRemove
|
251
|
+
// @param {module:engine/model/element~Element} cellToExpand
|
252
|
+
// @param {module:engine/model/writer~Writer} writer
|
253
|
+
function mergeTableCells( cellToRemove, cellToExpand, writer ) {
|
254
|
+
if ( !isEmpty( cellToRemove ) ) {
|
255
|
+
if ( isEmpty( cellToExpand ) ) {
|
256
|
+
writer.remove( writer.createRangeIn( cellToExpand ) );
|
257
|
+
}
|
258
|
+
|
259
|
+
writer.move( writer.createRangeIn( cellToRemove ), writer.createPositionAt( cellToExpand, 'end' ) );
|
260
|
+
}
|
261
|
+
|
262
|
+
// Remove merged table cell.
|
263
|
+
writer.remove( cellToRemove );
|
264
|
+
}
|
265
|
+
|
266
|
+
// Checks if the passed table cell contains an empty paragraph.
|
267
|
+
//
|
268
|
+
// @param {module:engine/model/element~Element} tableCell
|
269
|
+
// @returns {Boolean}
|
270
|
+
function isEmpty( tableCell ) {
|
271
|
+
return tableCell.childCount == 1 && tableCell.getChild( 0 ).is( 'element', 'paragraph' ) && tableCell.getChild( 0 ).isEmpty;
|
272
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module table/commands/mergecellscommand
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Command } from 'ckeditor5/src/core';
|
11
|
+
import TableUtils from '../tableutils';
|
12
|
+
import { getSelectedTableCells, isSelectionRectangular } from '../utils/selection';
|
13
|
+
import { updateNumericAttribute } from '../utils/common';
|
14
|
+
import { removeEmptyRowsColumns } from '../utils/structure';
|
15
|
+
|
16
|
+
/**
|
17
|
+
* The merge cells command.
|
18
|
+
*
|
19
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'mergeTableCells'` editor command.
|
20
|
+
*
|
21
|
+
* For example, to merge selected table cells:
|
22
|
+
*
|
23
|
+
* editor.execute( 'mergeTableCells' );
|
24
|
+
*
|
25
|
+
* @extends module:core/command~Command
|
26
|
+
*/
|
27
|
+
export default class MergeCellsCommand extends Command {
|
28
|
+
/**
|
29
|
+
* @inheritDoc
|
30
|
+
*/
|
31
|
+
refresh() {
|
32
|
+
const selectedTableCells = getSelectedTableCells( this.editor.model.document.selection );
|
33
|
+
this.isEnabled = isSelectionRectangular( selectedTableCells, this.editor.plugins.get( TableUtils ) );
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Executes the command.
|
38
|
+
*
|
39
|
+
* @fires execute
|
40
|
+
*/
|
41
|
+
execute() {
|
42
|
+
const model = this.editor.model;
|
43
|
+
const tableUtils = this.editor.plugins.get( TableUtils );
|
44
|
+
|
45
|
+
model.change( writer => {
|
46
|
+
const selectedTableCells = getSelectedTableCells( model.document.selection );
|
47
|
+
|
48
|
+
// All cells will be merged into the first one.
|
49
|
+
const firstTableCell = selectedTableCells.shift();
|
50
|
+
|
51
|
+
// Update target cell dimensions.
|
52
|
+
const { mergeWidth, mergeHeight } = getMergeDimensions( firstTableCell, selectedTableCells, tableUtils );
|
53
|
+
updateNumericAttribute( 'colspan', mergeWidth, firstTableCell, writer );
|
54
|
+
updateNumericAttribute( 'rowspan', mergeHeight, firstTableCell, writer );
|
55
|
+
|
56
|
+
for ( const tableCell of selectedTableCells ) {
|
57
|
+
mergeTableCells( tableCell, firstTableCell, writer );
|
58
|
+
}
|
59
|
+
|
60
|
+
const table = firstTableCell.findAncestor( 'table' );
|
61
|
+
|
62
|
+
// Remove rows and columns that become empty (have no anchored cells).
|
63
|
+
removeEmptyRowsColumns( table, tableUtils );
|
64
|
+
|
65
|
+
writer.setSelection( firstTableCell, 'in' );
|
66
|
+
} );
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
// Merges two table cells. It will ensure that after merging cells with empty paragraphs the resulting table cell will only have one
|
71
|
+
// paragraph. If one of the merged table cells is empty, the merged table cell will have contents of the non-empty table cell.
|
72
|
+
// If both are empty, the merged table cell will have only one empty paragraph.
|
73
|
+
//
|
74
|
+
// @param {module:engine/model/element~Element} cellBeingMerged
|
75
|
+
// @param {module:engine/model/element~Element} targetCell
|
76
|
+
// @param {module:engine/model/writer~Writer} writer
|
77
|
+
function mergeTableCells( cellBeingMerged, targetCell, writer ) {
|
78
|
+
if ( !isEmpty( cellBeingMerged ) ) {
|
79
|
+
if ( isEmpty( targetCell ) ) {
|
80
|
+
writer.remove( writer.createRangeIn( targetCell ) );
|
81
|
+
}
|
82
|
+
|
83
|
+
writer.move( writer.createRangeIn( cellBeingMerged ), writer.createPositionAt( targetCell, 'end' ) );
|
84
|
+
}
|
85
|
+
|
86
|
+
// Remove merged table cell.
|
87
|
+
writer.remove( cellBeingMerged );
|
88
|
+
}
|
89
|
+
|
90
|
+
// Checks if the passed table cell contains an empty paragraph.
|
91
|
+
//
|
92
|
+
// @param {module:engine/model/element~Element} tableCell
|
93
|
+
// @returns {Boolean}
|
94
|
+
function isEmpty( tableCell ) {
|
95
|
+
return tableCell.childCount == 1 && tableCell.getChild( 0 ).is( 'element', 'paragraph' ) && tableCell.getChild( 0 ).isEmpty;
|
96
|
+
}
|
97
|
+
|
98
|
+
function getMergeDimensions( firstTableCell, selectedTableCells, tableUtils ) {
|
99
|
+
let maxWidthOffset = 0;
|
100
|
+
let maxHeightOffset = 0;
|
101
|
+
|
102
|
+
for ( const tableCell of selectedTableCells ) {
|
103
|
+
const { row, column } = tableUtils.getCellLocation( tableCell );
|
104
|
+
|
105
|
+
maxWidthOffset = getMaxOffset( tableCell, column, maxWidthOffset, 'colspan' );
|
106
|
+
maxHeightOffset = getMaxOffset( tableCell, row, maxHeightOffset, 'rowspan' );
|
107
|
+
}
|
108
|
+
|
109
|
+
// Update table cell span attribute and merge set selection on a merged contents.
|
110
|
+
const { row: firstCellRow, column: firstCellColumn } = tableUtils.getCellLocation( firstTableCell );
|
111
|
+
|
112
|
+
const mergeWidth = maxWidthOffset - firstCellColumn;
|
113
|
+
const mergeHeight = maxHeightOffset - firstCellRow;
|
114
|
+
|
115
|
+
return { mergeWidth, mergeHeight };
|
116
|
+
}
|
117
|
+
|
118
|
+
function getMaxOffset( tableCell, start, currentMaxOffset, which ) {
|
119
|
+
const dimensionValue = parseInt( tableCell.getAttribute( which ) || 1 );
|
120
|
+
|
121
|
+
return Math.max( currentMaxOffset, start + dimensionValue );
|
122
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module table/commands/removecolumncommand
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Command } from 'ckeditor5/src/core';
|
11
|
+
|
12
|
+
import TableWalker from '../tablewalker';
|
13
|
+
import { getColumnIndexes, getSelectionAffectedTableCells } from '../utils/selection';
|
14
|
+
|
15
|
+
/**
|
16
|
+
* The remove column command.
|
17
|
+
*
|
18
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'removeTableColumn'` editor command.
|
19
|
+
*
|
20
|
+
* To remove the column containing the selected cell, execute the command:
|
21
|
+
*
|
22
|
+
* editor.execute( 'removeTableColumn' );
|
23
|
+
*
|
24
|
+
* @extends module:core/command~Command
|
25
|
+
*/
|
26
|
+
export default class RemoveColumnCommand extends Command {
|
27
|
+
/**
|
28
|
+
* @inheritDoc
|
29
|
+
*/
|
30
|
+
refresh() {
|
31
|
+
const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection );
|
32
|
+
const firstCell = selectedCells[ 0 ];
|
33
|
+
|
34
|
+
if ( firstCell ) {
|
35
|
+
const table = firstCell.findAncestor( 'table' );
|
36
|
+
const tableColumnCount = this.editor.plugins.get( 'TableUtils' ).getColumns( table );
|
37
|
+
|
38
|
+
const { first, last } = getColumnIndexes( selectedCells );
|
39
|
+
|
40
|
+
this.isEnabled = last - first < ( tableColumnCount - 1 );
|
41
|
+
} else {
|
42
|
+
this.isEnabled = false;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @inheritDoc
|
48
|
+
*/
|
49
|
+
execute() {
|
50
|
+
const [ firstCell, lastCell ] = getBoundaryCells( this.editor.model.document.selection );
|
51
|
+
const table = firstCell.parent.parent;
|
52
|
+
|
53
|
+
// Cache the table before removing or updating colspans.
|
54
|
+
const tableMap = [ ...new TableWalker( table ) ];
|
55
|
+
|
56
|
+
// Store column indexes of removed columns.
|
57
|
+
const removedColumnIndexes = {
|
58
|
+
first: tableMap.find( value => value.cell === firstCell ).column,
|
59
|
+
last: tableMap.find( value => value.cell === lastCell ).column
|
60
|
+
};
|
61
|
+
|
62
|
+
const cellToFocus = getCellToFocus( tableMap, firstCell, lastCell, removedColumnIndexes );
|
63
|
+
|
64
|
+
this.editor.model.change( writer => {
|
65
|
+
const columnsToRemove = removedColumnIndexes.last - removedColumnIndexes.first + 1;
|
66
|
+
|
67
|
+
this.editor.plugins.get( 'TableUtils' ).removeColumns( table, {
|
68
|
+
at: removedColumnIndexes.first,
|
69
|
+
columns: columnsToRemove
|
70
|
+
} );
|
71
|
+
|
72
|
+
writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
|
73
|
+
} );
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
// Returns a proper table cell to focus after removing a column.
|
78
|
+
// - selection is on last table cell it will return previous cell.
|
79
|
+
function getCellToFocus( tableMap, firstCell, lastCell, removedColumnIndexes ) {
|
80
|
+
const colspan = parseInt( lastCell.getAttribute( 'colspan' ) || 1 );
|
81
|
+
|
82
|
+
// If the table cell is spanned over 2+ columns - it will be truncated so the selection should
|
83
|
+
// stay in that cell.
|
84
|
+
if ( colspan > 1 ) {
|
85
|
+
return lastCell;
|
86
|
+
}
|
87
|
+
// Normally, look for the cell in the same row that precedes the first cell to put selection there ("column on the left").
|
88
|
+
// If the deleted column is the first column of the table, there will be no predecessor: use the cell
|
89
|
+
// from the column that follows then (also in the same row).
|
90
|
+
else if ( firstCell.previousSibling || lastCell.nextSibling ) {
|
91
|
+
return lastCell.nextSibling || firstCell.previousSibling;
|
92
|
+
}
|
93
|
+
// It can happen that table cells have no siblings in a row, for instance, when there are row spans
|
94
|
+
// in the table (in the previous row). Then just look for the closest cell that is in a column
|
95
|
+
// that will not be removed to put the selection there.
|
96
|
+
else {
|
97
|
+
// Look for any cell in a column that precedes the first removed column.
|
98
|
+
if ( removedColumnIndexes.first ) {
|
99
|
+
return tableMap.reverse().find( ( { column } ) => {
|
100
|
+
return column < removedColumnIndexes.first;
|
101
|
+
} ).cell;
|
102
|
+
}
|
103
|
+
// If the first removed column is the first column of the table, then
|
104
|
+
// look for any cell that is in a column that follows the last removed column.
|
105
|
+
else {
|
106
|
+
return tableMap.reverse().find( ( { column } ) => {
|
107
|
+
return column > removedColumnIndexes.last;
|
108
|
+
} ).cell;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
// 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 );
|
116
|
+
const firstCell = referenceCells[ 0 ];
|
117
|
+
const lastCell = referenceCells.pop();
|
118
|
+
|
119
|
+
const returnValue = [ firstCell, lastCell ];
|
120
|
+
|
121
|
+
return firstCell.isBefore( lastCell ) ? returnValue : returnValue.reverse();
|
122
|
+
}
|