@ckeditor/ckeditor5-table 35.0.1 → 35.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/table.js +1 -1
- package/build/table.js.map +1 -0
- package/build/translations/ko.js +1 -1
- package/build/translations/tt.js +1 -0
- package/build/translations/ur.js +1 -1
- package/lang/translations/ko.po +1 -1
- package/lang/translations/tt.po +261 -0
- package/lang/translations/ur.po +9 -9
- package/package.json +26 -26
- package/src/index.js +1 -0
- package/src/tablecaption/tablecaptionui.js +2 -0
- package/src/tablecellproperties/tablecellpropertiesediting.js +4 -30
- package/src/tablecellproperties/tablecellpropertiesui.js +1 -1
- package/src/tablecellproperties/ui/tablecellpropertiesview.js +2 -0
- package/src/{tablecellproperties → tablecellwidth}/commands/tablecellwidthcommand.js +2 -3
- package/src/tablecellwidth/tablecellwidthediting.js +58 -0
- package/src/tablecolumnresize/constants.js +0 -2
- package/src/tablecolumnresize/converters.js +29 -28
- package/src/tablecolumnresize/tablecolumnresizeediting.js +399 -425
- package/src/tablecolumnresize/tablecolumnwidthscommand.js +55 -0
- package/src/tablecolumnresize/tablewidthresizecommand.js +60 -0
- package/src/tablecolumnresize/utils.js +131 -167
- package/src/tablecolumnresize.js +4 -3
- package/src/tableproperties/ui/tablepropertiesview.js +2 -0
- package/src/tableui.js +0 -6
- package/src/ui/colorinputview.js +88 -51
- package/src/ui/inserttableview.js +86 -50
- package/src/utils/common.js +24 -0
- package/src/utils/ui/table-properties.js +7 -7
- package/theme/tablecolumnresize.css +13 -10
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2022, 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
|
+
/**
|
|
7
|
+
* @module table/tablecolumnresize/tablecolumnwidthscommand
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import TablePropertyCommand from '../tableproperties/commands/tablepropertycommand';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @extends module:table/tableproperties/commands/tablepropertycommand~TablePropertyCommand
|
|
14
|
+
*/
|
|
15
|
+
export default class TableColumnWidthsCommand extends TablePropertyCommand {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new `TableColumnWidthsCommand` instance.
|
|
18
|
+
*
|
|
19
|
+
* @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
|
|
20
|
+
* @param {String} defaultValue The default value of the attribute.
|
|
21
|
+
*/
|
|
22
|
+
constructor( editor, defaultValue ) {
|
|
23
|
+
super( editor, 'columnWidths', defaultValue );
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
refresh() {
|
|
30
|
+
// The command is always enabled as it doesn't care about the actual selection - table can be resized
|
|
31
|
+
// even if the selection is elsewhere.
|
|
32
|
+
this.isEnabled = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Changes the `columnWidths` attribute value for the given or currently selected table.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} options
|
|
39
|
+
* @param {String} [options.columnWidths] New value of the `columnWidths` attribute.
|
|
40
|
+
* @param {module:engine/model/element~Element} [options.table] The table that is having the columns resized.
|
|
41
|
+
*/
|
|
42
|
+
execute( options = {} ) {
|
|
43
|
+
const model = this.editor.model;
|
|
44
|
+
const table = options.table || model.document.selection.getSelectedElement();
|
|
45
|
+
const { columnWidths } = options;
|
|
46
|
+
|
|
47
|
+
model.change( writer => {
|
|
48
|
+
if ( columnWidths ) {
|
|
49
|
+
writer.setAttribute( this.attributeName, columnWidths, table );
|
|
50
|
+
} else {
|
|
51
|
+
writer.removeAttribute( this.attributeName, table );
|
|
52
|
+
}
|
|
53
|
+
} );
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2022, 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
|
+
/**
|
|
7
|
+
* @module table/tablecolumnresize/tablewidthresizecommand
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import TablePropertyCommand from '../tableproperties/commands/tablepropertycommand';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @extends module:table/tableproperties/commands/tablepropertycommand~TablePropertyCommand
|
|
14
|
+
*/
|
|
15
|
+
export default class TableWidthResizeCommand extends TablePropertyCommand {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new `TableWidthResizeCommand` instance.
|
|
18
|
+
*
|
|
19
|
+
* @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
|
|
20
|
+
* @param {String} defaultValue The default value of the attribute.
|
|
21
|
+
*/
|
|
22
|
+
constructor( editor, defaultValue ) {
|
|
23
|
+
// We create a custom command instead of using the existing `TableWidthCommand`
|
|
24
|
+
// as we also need to change the `columnWidths` property and running both commands
|
|
25
|
+
// separately would make the integration with Track Changes feature more troublesome.
|
|
26
|
+
super( editor, 'tableWidth', defaultValue );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
refresh() {
|
|
33
|
+
// The command is always enabled as it doesn't care about the actual selection - table can be resized
|
|
34
|
+
// even if the selection is elsewhere.
|
|
35
|
+
this.isEnabled = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Changes the `tableWidth` and `columnWidths` attribute values for the given or currently selected table.
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} options
|
|
42
|
+
* @param {String} [options.tableWidth] The new table width.
|
|
43
|
+
* @param {String} [options.columnWidths] The new table column widths.
|
|
44
|
+
* @param {module:engine/model/element~Element} [options.table] The table that is affected by the resize.
|
|
45
|
+
*/
|
|
46
|
+
execute( options = {} ) {
|
|
47
|
+
const model = this.editor.model;
|
|
48
|
+
const table = options.table || model.document.selection.getSelectedElement();
|
|
49
|
+
const { tableWidth, columnWidths } = options;
|
|
50
|
+
|
|
51
|
+
model.change( writer => {
|
|
52
|
+
if ( tableWidth ) {
|
|
53
|
+
writer.setAttribute( this.attributeName, tableWidth, table );
|
|
54
|
+
writer.setAttribute( 'columnWidths', columnWidths, table );
|
|
55
|
+
} else {
|
|
56
|
+
writer.removeAttribute( this.attributeName, table );
|
|
57
|
+
}
|
|
58
|
+
} );
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* @module table/tablecolumnresize/utils
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
/* istanbul ignore file */
|
|
11
|
-
|
|
12
10
|
import { global } from 'ckeditor5/src/utils';
|
|
13
11
|
import {
|
|
14
12
|
COLUMN_WIDTH_PRECISION,
|
|
@@ -17,16 +15,18 @@ import {
|
|
|
17
15
|
} from './constants';
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
|
-
*
|
|
18
|
+
* Returns all the inserted or changed table model elements in a given change set. Only the tables
|
|
19
|
+
* with 'columnsWidth' attribute are taken into account. The returned set may be empty.
|
|
20
|
+
*
|
|
21
|
+
* Most notably if an entire table is removed it will not be included in returned set.
|
|
21
22
|
*
|
|
22
|
-
* @param {
|
|
23
|
-
* @
|
|
24
|
-
* @returns {Set.<module:engine/model/element~Element>}
|
|
23
|
+
* @param {module:engine/model/model~Model} model The model to collect the affected elements from.
|
|
24
|
+
* @returns {Set.<module:engine/model/element~Element>} A set of table model elements.
|
|
25
25
|
*/
|
|
26
|
-
export function
|
|
27
|
-
const
|
|
26
|
+
export function getChangedResizedTables( model ) {
|
|
27
|
+
const affectedTables = new Set();
|
|
28
28
|
|
|
29
|
-
for ( const change of
|
|
29
|
+
for ( const change of model.document.differ.getChanges() ) {
|
|
30
30
|
let referencePosition = null;
|
|
31
31
|
|
|
32
32
|
// Checks if the particular change from the differ is:
|
|
@@ -34,13 +34,20 @@ export function getAffectedTables( changes, model ) {
|
|
|
34
34
|
// - an attribute change on a table, a row or a cell.
|
|
35
35
|
switch ( change.type ) {
|
|
36
36
|
case 'insert':
|
|
37
|
-
case 'remove':
|
|
38
37
|
referencePosition = [ 'table', 'tableRow', 'tableCell' ].includes( change.name ) ?
|
|
39
38
|
change.position :
|
|
40
39
|
null;
|
|
41
40
|
|
|
42
41
|
break;
|
|
43
42
|
|
|
43
|
+
case 'remove':
|
|
44
|
+
// If the whole table is removed, there's no need to update its column widths (#12201).
|
|
45
|
+
referencePosition = [ 'tableRow', 'tableCell' ].includes( change.name ) ?
|
|
46
|
+
change.position :
|
|
47
|
+
null;
|
|
48
|
+
|
|
49
|
+
break;
|
|
50
|
+
|
|
44
51
|
case 'attribute':
|
|
45
52
|
if ( change.range.start.nodeAfter ) {
|
|
46
53
|
referencePosition = [ 'table', 'tableRow', 'tableCell' ].includes( change.range.start.nodeAfter.name ) ?
|
|
@@ -51,102 +58,99 @@ export function getAffectedTables( changes, model ) {
|
|
|
51
58
|
break;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if ( referencePosition ) {
|
|
57
|
-
const tableNode = ( referencePosition.nodeAfter && referencePosition.nodeAfter.name === 'table' ) ?
|
|
58
|
-
referencePosition.nodeAfter : referencePosition.findAncestor( 'table' );
|
|
59
|
-
|
|
60
|
-
if ( tableNode ) {
|
|
61
|
-
const range = model.createRangeOn( tableNode );
|
|
62
|
-
|
|
63
|
-
for ( const node of range.getItems() ) {
|
|
64
|
-
if ( node.is( 'element' ) && node.name === 'table' ) {
|
|
65
|
-
affectedTables.push( node );
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
61
|
+
if ( !referencePosition ) {
|
|
62
|
+
continue;
|
|
69
63
|
}
|
|
70
64
|
|
|
71
|
-
const
|
|
65
|
+
const tableNode = ( referencePosition.nodeAfter && referencePosition.nodeAfter.name === 'table' ) ?
|
|
66
|
+
referencePosition.nodeAfter : referencePosition.findAncestor( 'table' );
|
|
72
67
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
// We iterate over the whole table looking for the nested tables that are also affected.
|
|
69
|
+
for ( const node of model.createRangeOn( tableNode ).getItems() ) {
|
|
70
|
+
if ( node.is( 'element' ) && node.name === 'table' && node.hasAttribute( 'columnWidths' ) ) {
|
|
71
|
+
affectedTables.add( node );
|
|
76
72
|
}
|
|
77
73
|
}
|
|
78
74
|
}
|
|
79
75
|
|
|
80
|
-
return
|
|
76
|
+
return affectedTables;
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
/**
|
|
84
|
-
*
|
|
80
|
+
* Calculates the percentage of the minimum column width given in pixels for a given table.
|
|
85
81
|
*
|
|
86
|
-
* @param {
|
|
87
|
-
* @
|
|
82
|
+
* @param {module:engine/model/element~Element} modelTable A table model element.
|
|
83
|
+
* @param {module:core/editor/editor~Editor} editor The editor instance.
|
|
84
|
+
* @returns {Number} The minimal column width in percentage.
|
|
88
85
|
*/
|
|
89
|
-
export function
|
|
90
|
-
return
|
|
86
|
+
export function getColumnMinWidthAsPercentage( modelTable, editor ) {
|
|
87
|
+
return COLUMN_MIN_WIDTH_IN_PIXELS * 100 / getTableWidthInPixels( modelTable, editor );
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
/**
|
|
94
91
|
* Calculates the table width in pixels.
|
|
95
92
|
*
|
|
96
|
-
* @param {module:engine/model/element~Element} table
|
|
97
|
-
* @param {module:core/editor/editor~Editor} editor
|
|
98
|
-
* @returns {Number}
|
|
93
|
+
* @param {module:engine/model/element~Element} modelTable A table model element.
|
|
94
|
+
* @param {module:core/editor/editor~Editor} editor The editor instance.
|
|
95
|
+
* @returns {Number} The width of the table in pixels.
|
|
99
96
|
*/
|
|
100
|
-
export function getTableWidthInPixels(
|
|
101
|
-
|
|
102
|
-
const
|
|
97
|
+
export function getTableWidthInPixels( modelTable, editor ) {
|
|
98
|
+
// It is possible for a table to not have a <tbody> element - see #11878.
|
|
99
|
+
const referenceElement = getChildrenViewElement( modelTable, 'tbody', editor ) || getChildrenViewElement( modelTable, 'thead', editor );
|
|
100
|
+
const domReferenceElement = editor.editing.view.domConverter.mapViewToDom( referenceElement );
|
|
103
101
|
|
|
104
|
-
return getElementWidthInPixels(
|
|
102
|
+
return getElementWidthInPixels( domReferenceElement );
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
.split( ',' )
|
|
121
|
-
.map( columnWidth => columnWidth.trim() )
|
|
122
|
-
.map( columnWidth => {
|
|
123
|
-
return columnWidth.endsWith( 'px' ) ?
|
|
124
|
-
parseFloat( columnWidth ) :
|
|
125
|
-
parseFloat( columnWidth ) * tableWidthInPixels / 100;
|
|
126
|
-
} );
|
|
105
|
+
// Returns the a view element with a given name that is nested directly in a `<table>` element
|
|
106
|
+
// related to a given `modelTable`.
|
|
107
|
+
//
|
|
108
|
+
// @private
|
|
109
|
+
// @param {module:engine/model/element~Element} table
|
|
110
|
+
// @param {module:core/editor/editor~Editor} editor
|
|
111
|
+
// @param {String} elementName Name of a view to be looked for, e.g. `'colgroup`', `'thead`'.
|
|
112
|
+
// @returns {module:engine/view/element~Element|undefined} Matched view or `undefined` otherwise.
|
|
113
|
+
function getChildrenViewElement( modelTable, elementName, editor ) {
|
|
114
|
+
const viewFigure = editor.editing.mapper.toViewElement( modelTable );
|
|
115
|
+
const viewTable = [ ...viewFigure.getChildren() ].find( viewChild => viewChild.is( 'element', 'table' ) );
|
|
116
|
+
|
|
117
|
+
return [ ...viewTable.getChildren() ].find( viewChild => viewChild.is( 'element', elementName ) );
|
|
127
118
|
}
|
|
128
119
|
|
|
129
120
|
/**
|
|
130
|
-
*
|
|
121
|
+
* Returns the computed width (in pixels) of the DOM element without padding and borders.
|
|
131
122
|
*
|
|
132
|
-
* @param {
|
|
133
|
-
* @
|
|
134
|
-
* @returns {Number}
|
|
123
|
+
* @param {HTMLElement} domElement A DOM element.
|
|
124
|
+
* @returns {Number} The width of the DOM element in pixels.
|
|
135
125
|
*/
|
|
136
|
-
export function
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
export function getElementWidthInPixels( domElement ) {
|
|
127
|
+
const styles = global.window.getComputedStyle( domElement );
|
|
128
|
+
|
|
129
|
+
// In the 'border-box' box sizing algorithm, the element's width
|
|
130
|
+
// already includes the padding and border width (#12335).
|
|
131
|
+
if ( styles.boxSizing === 'border-box' ) {
|
|
132
|
+
return parseFloat( styles.width ) -
|
|
133
|
+
parseFloat( styles.paddingLeft ) -
|
|
134
|
+
parseFloat( styles.paddingRight ) -
|
|
135
|
+
parseFloat( styles.borderLeftWidth ) -
|
|
136
|
+
parseFloat( styles.borderRightWidth );
|
|
137
|
+
} else {
|
|
138
|
+
return parseFloat( styles.width );
|
|
139
|
+
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
|
-
* Returns the column indexes on the left and right edges of a cell.
|
|
143
|
+
* Returns the column indexes on the left and right edges of a cell. They differ if the cell spans
|
|
144
|
+
* across multiple columns.
|
|
144
145
|
*
|
|
145
|
-
* @param {module:engine/model/element~Element} cell
|
|
146
|
-
* @
|
|
146
|
+
* @param {module:engine/model/element~Element} cell A table cell model element.
|
|
147
|
+
* @param {module:table/tableutils~TableUtils} tableUtils The Table Utils plugin instance.
|
|
148
|
+
* @returns {Object} An object containing the indexes of the left and right edges of the cell.
|
|
149
|
+
* @returns {Number} return.leftEdge The index of the left edge of the cell.
|
|
150
|
+
* @returns {Number} return.rightEdge The index of the right edge of the cell.
|
|
147
151
|
*/
|
|
148
|
-
export function
|
|
149
|
-
const cellColumnIndex =
|
|
152
|
+
export function getColumnEdgesIndexes( cell, tableUtils ) {
|
|
153
|
+
const cellColumnIndex = tableUtils.getCellLocation( cell ).column;
|
|
150
154
|
const cellWidth = cell.getAttribute( 'colspan' ) || 1;
|
|
151
155
|
|
|
152
156
|
return {
|
|
@@ -155,59 +159,11 @@ export function getColumnIndex( cell, columnIndexMap ) {
|
|
|
155
159
|
};
|
|
156
160
|
}
|
|
157
161
|
|
|
158
|
-
/**
|
|
159
|
-
* Returns the total number of columns in a table.
|
|
160
|
-
*
|
|
161
|
-
* @param {module:engine/model/element~Element} table
|
|
162
|
-
* @param {module:core/editor/editor~Editor} editor
|
|
163
|
-
* @returns {Number}
|
|
164
|
-
*/
|
|
165
|
-
export function getNumberOfColumn( table, editor ) {
|
|
166
|
-
return editor.plugins.get( 'TableUtils' ).getColumns( table );
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Checks if the table is already fully rendered, with the `<colgroup>` element that defines the widths for each column.
|
|
171
|
-
*
|
|
172
|
-
* @param {module:engine/model/element~Element} table
|
|
173
|
-
* @param {module:core/editor/editor~Editor} editor
|
|
174
|
-
* @returns {Number}
|
|
175
|
-
*/
|
|
176
|
-
export function isTableRendered( table, editor ) {
|
|
177
|
-
return !!getColgroupViewElement( table, editor );
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Returns the `<colgroup>` view element, if it exists in a table. Returns `undefined` otherwise.
|
|
181
|
-
//
|
|
182
|
-
// @private
|
|
183
|
-
// @param {module:engine/model/element~Element} table
|
|
184
|
-
// @param {module:core/editor/editor~Editor} editor
|
|
185
|
-
// @returns {module:engine/view/element~Element|undefined}
|
|
186
|
-
function getColgroupViewElement( table, editor ) {
|
|
187
|
-
const viewFigure = editor.editing.mapper.toViewElement( table );
|
|
188
|
-
const viewTable = [ ...viewFigure.getChildren() ].find( viewChild => viewChild.is( 'element', 'table' ) );
|
|
189
|
-
|
|
190
|
-
return [ ...viewTable.getChildren() ].find( viewChild => viewChild.is( 'element', 'colgroup' ) );
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Returns the `<tbody>` view element, if it exists in a table. Returns `undefined` otherwise.
|
|
194
|
-
//
|
|
195
|
-
// @private
|
|
196
|
-
// @param {module:engine/model/element~Element} table
|
|
197
|
-
// @param {module:core/editor/editor~Editor} editor
|
|
198
|
-
// @returns {module:engine/view/element~Element|undefined}
|
|
199
|
-
function getTbodyViewElement( table, editor ) {
|
|
200
|
-
const viewFigure = editor.editing.mapper.toViewElement( table );
|
|
201
|
-
const viewTable = [ ...viewFigure.getChildren() ].find( viewChild => viewChild.is( 'element', 'table' ) );
|
|
202
|
-
|
|
203
|
-
return [ ...viewTable.getChildren() ].find( viewChild => viewChild.is( 'element', 'tbody' ) );
|
|
204
|
-
}
|
|
205
|
-
|
|
206
162
|
/**
|
|
207
163
|
* Rounds the provided value to a fixed-point number with defined number of digits after the decimal point.
|
|
208
164
|
*
|
|
209
|
-
* @param {Number|String} value
|
|
210
|
-
* @returns {Number}
|
|
165
|
+
* @param {Number|String} value A number to be rounded.
|
|
166
|
+
* @returns {Number} The rounded number.
|
|
211
167
|
*/
|
|
212
168
|
export function toPrecision( value ) {
|
|
213
169
|
const multiplier = Math.pow( 10, COLUMN_WIDTH_PRECISION );
|
|
@@ -220,10 +176,10 @@ export function toPrecision( value ) {
|
|
|
220
176
|
* Clamps the number within the inclusive lower (min) and upper (max) bounds. Returned number is rounded using the
|
|
221
177
|
* {@link ~toPrecision `toPrecision()`} function.
|
|
222
178
|
*
|
|
223
|
-
* @param {Number} number
|
|
224
|
-
* @param {Number} min
|
|
225
|
-
* @param {Number} max
|
|
226
|
-
* @returns {Number}
|
|
179
|
+
* @param {Number} number A number to be clamped.
|
|
180
|
+
* @param {Number} min A lower bound.
|
|
181
|
+
* @param {Number} max An upper bound.
|
|
182
|
+
* @returns {Number} The clamped number.
|
|
227
183
|
*/
|
|
228
184
|
export function clamp( number, min, max ) {
|
|
229
185
|
if ( number <= min ) {
|
|
@@ -240,19 +196,19 @@ export function clamp( number, min, max ) {
|
|
|
240
196
|
/**
|
|
241
197
|
* Creates an array with defined length and fills all elements with defined value.
|
|
242
198
|
*
|
|
243
|
-
* @param {Number} length
|
|
244
|
-
* @param {*} value
|
|
245
|
-
* @returns {Array.<*>}
|
|
199
|
+
* @param {Number} length The length of the array.
|
|
200
|
+
* @param {*} value The value to fill the array with.
|
|
201
|
+
* @returns {Array.<*>} An array with defined length and filled with defined value.
|
|
246
202
|
*/
|
|
247
|
-
export function
|
|
203
|
+
export function createFilledArray( length, value ) {
|
|
248
204
|
return Array( length ).fill( value );
|
|
249
205
|
}
|
|
250
206
|
|
|
251
207
|
/**
|
|
252
208
|
* Sums all array values that can be parsed to a float.
|
|
253
209
|
*
|
|
254
|
-
* @param {Array.<Number>} array
|
|
255
|
-
* @returns {Number}
|
|
210
|
+
* @param {Array.<Number>} array An array of numbers.
|
|
211
|
+
* @returns {Number} The sum of all array values.
|
|
256
212
|
*/
|
|
257
213
|
export function sumArray( array ) {
|
|
258
214
|
return array
|
|
@@ -263,15 +219,16 @@ export function sumArray( array ) {
|
|
|
263
219
|
|
|
264
220
|
/**
|
|
265
221
|
* Makes sure that the sum of the widths from all columns is 100%. If the sum of all the widths is not equal 100%, all the widths are
|
|
266
|
-
* changed proportionally so that they all sum back to 100%.
|
|
222
|
+
* changed proportionally so that they all sum back to 100%. If there are columns without specified width, the amount remaining
|
|
223
|
+
* after assigning the known widths will be distributed equally between them.
|
|
267
224
|
*
|
|
268
225
|
* Currently, only widths provided as percentage values are supported.
|
|
269
226
|
*
|
|
270
|
-
* @param {
|
|
271
|
-
* @returns {Array.<Number>}
|
|
227
|
+
* @param {Array.<Number>} columnWidths An array of column widths.
|
|
228
|
+
* @returns {Array.<Number>} An array of column widths guaranteed to sum up to 100%.
|
|
272
229
|
*/
|
|
273
|
-
export function
|
|
274
|
-
|
|
230
|
+
export function normalizeColumnWidths( columnWidths ) {
|
|
231
|
+
columnWidths = calculateMissingColumnWidths( columnWidths );
|
|
275
232
|
const totalWidth = sumArray( columnWidths );
|
|
276
233
|
|
|
277
234
|
if ( totalWidth === 100 ) {
|
|
@@ -301,16 +258,12 @@ export function normalizeColumnWidthsAttribute( columnWidthsAttribute ) {
|
|
|
301
258
|
// - If there is enough free space in the table for all uninitialized columns to have at least the minimum allowed width for all of them,
|
|
302
259
|
// then set this width equally for all uninitialized columns.
|
|
303
260
|
// - Otherwise, just set the minimum allowed width for all uninitialized columns. The sum of all column widths will be greater than 100%,
|
|
304
|
-
// but then it will be adjusted proportionally to 100% in {@link #
|
|
261
|
+
// but then it will be adjusted proportionally to 100% in {@link #normalizeColumnWidths `normalizeColumnWidths()`}.
|
|
305
262
|
//
|
|
306
263
|
// @private
|
|
307
|
-
// @param {
|
|
308
|
-
// @returns {Array.<Number>}
|
|
309
|
-
function
|
|
310
|
-
const columnWidths = columnWidthsAttribute
|
|
311
|
-
.split( ',' )
|
|
312
|
-
.map( columnWidth => columnWidth.trim() );
|
|
313
|
-
|
|
264
|
+
// @param {Array.<Number>} columnWidths An array of column widths.
|
|
265
|
+
// @returns {Array.<Number>} An array with 'auto' values replaced with calculated widths.
|
|
266
|
+
function calculateMissingColumnWidths( columnWidths ) {
|
|
314
267
|
const numberOfUninitializedColumns = columnWidths.filter( columnWidth => columnWidth === 'auto' ).length;
|
|
315
268
|
|
|
316
269
|
if ( numberOfUninitializedColumns === 0 ) {
|
|
@@ -329,20 +282,22 @@ function prepareColumnWidths( columnWidthsAttribute ) {
|
|
|
329
282
|
.map( columnWidth => toPrecision( columnWidth ) );
|
|
330
283
|
}
|
|
331
284
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Inserts column resizer element into a view cell if it is missing.
|
|
287
|
+
*
|
|
288
|
+
* @param {module:engine/view/downcastwriter~DowncastWriter} viewWriter View writer instance.
|
|
289
|
+
* @param {module:engine/view/element~Element} viewCell View cell where resizer should be put.
|
|
290
|
+
*/
|
|
291
|
+
export function ensureColumnResizerElement( viewWriter, viewCell ) {
|
|
337
292
|
let viewTableColumnResizerElement = [ ...viewCell.getChildren() ]
|
|
338
|
-
.find( viewElement => viewElement.hasClass( 'table-column-resizer' ) );
|
|
293
|
+
.find( viewElement => viewElement.hasClass( 'ck-table-column-resizer' ) );
|
|
339
294
|
|
|
340
295
|
if ( viewTableColumnResizerElement ) {
|
|
341
296
|
return;
|
|
342
297
|
}
|
|
343
298
|
|
|
344
299
|
viewTableColumnResizerElement = viewWriter.createUIElement( 'div', {
|
|
345
|
-
class: 'table-column-resizer'
|
|
300
|
+
class: 'ck-table-column-resizer'
|
|
346
301
|
} );
|
|
347
302
|
|
|
348
303
|
viewWriter.insert(
|
|
@@ -351,17 +306,26 @@ export function insertColumnResizerElements( viewWriter, viewCell ) {
|
|
|
351
306
|
);
|
|
352
307
|
}
|
|
353
308
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Calculates the total horizontal space taken by the cell. That includes:
|
|
311
|
+
* * width,
|
|
312
|
+
* * left and red padding,
|
|
313
|
+
* * border width.
|
|
314
|
+
*
|
|
315
|
+
* @param {HTMLElement} domCell A DOM cell element.
|
|
316
|
+
* @returns {Number} Width in pixels without `px` at the end.
|
|
317
|
+
*/
|
|
318
|
+
export function getDomCellOuterWidth( domCell ) {
|
|
319
|
+
const styles = global.window.getComputedStyle( domCell );
|
|
320
|
+
|
|
321
|
+
// In the 'border-box' box sizing algorithm, the element's width
|
|
322
|
+
// already includes the padding and border width (#12335).
|
|
323
|
+
if ( styles.boxSizing === 'border-box' ) {
|
|
324
|
+
return parseInt( styles.width );
|
|
325
|
+
} else {
|
|
326
|
+
return parseFloat( styles.width ) +
|
|
327
|
+
parseFloat( styles.paddingLeft ) +
|
|
328
|
+
parseFloat( styles.paddingRight ) +
|
|
329
|
+
parseFloat( styles.borderWidth );
|
|
364
330
|
}
|
|
365
|
-
|
|
366
|
-
viewWriter.remove( viewTableColumnResizerElement );
|
|
367
331
|
}
|
package/src/tablecolumnresize.js
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
|
|
10
10
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
11
|
import TableColumnResizeEditing from './tablecolumnresize/tablecolumnresizeediting';
|
|
12
|
+
import TableCellWidthEditing from './tablecellwidth/tablecellwidthediting';
|
|
12
13
|
|
|
13
14
|
import '../theme/tablecolumnresize.css';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* The table column
|
|
17
|
+
* The table column resize feature.
|
|
17
18
|
*
|
|
18
|
-
* It provides the possibility to set the width of each column in a table using a resize
|
|
19
|
+
* It provides the possibility to set the width of each column in a table using a resize handler.
|
|
19
20
|
*
|
|
20
21
|
* @extends module:core/plugin~Plugin
|
|
21
22
|
*/
|
|
@@ -24,7 +25,7 @@ export default class TableColumnResize extends Plugin {
|
|
|
24
25
|
* @inheritDoc
|
|
25
26
|
*/
|
|
26
27
|
static get requires() {
|
|
27
|
-
return [ TableColumnResizeEditing ];
|
|
28
|
+
return [ TableColumnResizeEditing, TableCellWidthEditing ];
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -360,8 +360,10 @@ export default class TablePropertiesView extends View {
|
|
|
360
360
|
[
|
|
361
361
|
this.borderStyleDropdown,
|
|
362
362
|
this.borderColorInput,
|
|
363
|
+
this.borderColorInput.fieldView.dropdownView.buttonView,
|
|
363
364
|
this.borderWidthInput,
|
|
364
365
|
this.backgroundInput,
|
|
366
|
+
this.backgroundInput.fieldView.dropdownView.buttonView,
|
|
365
367
|
this.widthInput,
|
|
366
368
|
this.heightInput,
|
|
367
369
|
this.alignmentToolbar,
|
package/src/tableui.js
CHANGED
|
@@ -73,12 +73,6 @@ export default class TableUI extends Plugin {
|
|
|
73
73
|
|
|
74
74
|
insertTableView.delegate( 'execute' ).to( dropdownView );
|
|
75
75
|
|
|
76
|
-
dropdownView.buttonView.on( 'open', () => {
|
|
77
|
-
// Reset the chooser before showing it to the user.
|
|
78
|
-
insertTableView.rows = 0;
|
|
79
|
-
insertTableView.columns = 0;
|
|
80
|
-
} );
|
|
81
|
-
|
|
82
76
|
dropdownView.on( 'execute', () => {
|
|
83
77
|
editor.execute( 'insertTable', { rows: insertTableView.rows, columns: insertTableView.columns } );
|
|
84
78
|
editor.editing.view.focus();
|