@ckeditor/ckeditor5-table 33.0.0 → 34.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/LICENSE.md +2 -2
- package/README.md +2 -1
- package/build/table.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/hr.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/pt.js +1 -0
- package/build/translations/sk.js +1 -1
- package/build/translations/ur.js +1 -0
- package/build/translations/zh-cn.js +1 -1
- package/ckeditor5-metadata.json +19 -0
- package/lang/translations/en-au.po +3 -3
- package/lang/translations/es.po +1 -1
- package/lang/translations/fr.po +1 -1
- package/lang/translations/hr.po +3 -3
- package/lang/translations/it.po +1 -1
- package/lang/translations/lv.po +40 -40
- package/lang/translations/pt-br.po +1 -1
- package/lang/translations/pt.po +261 -0
- package/lang/translations/sk.po +3 -3
- package/lang/translations/ur.po +261 -0
- package/lang/translations/zh-cn.po +3 -3
- package/package.json +26 -23
- package/src/commands/inserttablecommand.js +1 -5
- package/src/index.js +3 -0
- package/src/tablecolumnresize/constants.js +32 -0
- package/src/tablecolumnresize/converters.js +126 -0
- package/src/tablecolumnresize/tablecolumnresizeediting.js +758 -0
- package/src/tablecolumnresize/utils.js +367 -0
- package/src/tablecolumnresize.js +36 -0
- package/src/tableediting.js +3 -5
- package/src/tablekeyboard.js +68 -66
- package/theme/tablecolumnresize.css +59 -0
- package/build/table.js.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
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/constants
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* istanbul ignore file */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The minimum column width given as a percentage value. Used in situations when the table is not yet rendered, so it is impossible to
|
|
14
|
+
* calculate how many percentage of the table width would be {@link ~COLUMN_MIN_WIDTH_IN_PIXELS minimum column width in pixels}.
|
|
15
|
+
*
|
|
16
|
+
* @const {Number}
|
|
17
|
+
*/
|
|
18
|
+
export const COLUMN_MIN_WIDTH_AS_PERCENTAGE = 5;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The minimum column width in pixels when the maximum table width is known.
|
|
22
|
+
*
|
|
23
|
+
* @const {Number}
|
|
24
|
+
*/
|
|
25
|
+
export const COLUMN_MIN_WIDTH_IN_PIXELS = 40;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Determines how many digits after the decimal point are used to store the column width as a percentage value.
|
|
29
|
+
*
|
|
30
|
+
* @const {Number}
|
|
31
|
+
*/
|
|
32
|
+
export const COLUMN_WIDTH_PRECISION = 2;
|
|
@@ -0,0 +1,126 @@
|
|
|
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/converters
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* istanbul ignore file */
|
|
11
|
+
|
|
12
|
+
import { getNumberOfColumn } from './utils';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns a helper for converting a view `<colgroup>` and `<col>` elements to the model table `columnWidths` attribute.
|
|
16
|
+
*
|
|
17
|
+
* Only the inline width, provided as a percentage value, in the `<col>` element is taken into account. If there are not enough `<col>`
|
|
18
|
+
* elements matching this condition, the special value 'auto' is returned. It indicates that the width of a column will be automatically
|
|
19
|
+
* calculated in the
|
|
20
|
+
* {@link module:table/tablecolumnresize/tablecolumnresizeediting~TableColumnResizeEditing#_setupPostFixer post-fixer}, depending
|
|
21
|
+
* on the available table space.
|
|
22
|
+
*
|
|
23
|
+
* @param {module:core/editor/editor~Editor} editor The editor instance.
|
|
24
|
+
* @returns {Function} Conversion helper.
|
|
25
|
+
*/
|
|
26
|
+
export function upcastColgroupElement( editor ) {
|
|
27
|
+
return dispatcher => dispatcher.on( 'element:colgroup', ( evt, data, conversionApi ) => {
|
|
28
|
+
const modelTable = data.modelCursor.findAncestor( 'table' );
|
|
29
|
+
|
|
30
|
+
if ( !modelTable ) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const modelWriter = conversionApi.writer;
|
|
35
|
+
const viewColgroupElement = data.viewItem;
|
|
36
|
+
const numberOfColumns = getNumberOfColumn( modelTable, editor );
|
|
37
|
+
|
|
38
|
+
const columnWidthsAttribute = [ ...Array( numberOfColumns ).keys() ]
|
|
39
|
+
.map( columnIndex => {
|
|
40
|
+
const viewChild = viewColgroupElement.getChild( columnIndex );
|
|
41
|
+
|
|
42
|
+
if ( !viewChild || !viewChild.is( 'element', 'col' ) ) {
|
|
43
|
+
return 'auto';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const viewColWidth = viewChild.getStyle( 'width' );
|
|
47
|
+
|
|
48
|
+
if ( !viewColWidth || !viewColWidth.endsWith( '%' ) ) {
|
|
49
|
+
return 'auto';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return viewColWidth;
|
|
53
|
+
} )
|
|
54
|
+
.join( ',' );
|
|
55
|
+
|
|
56
|
+
modelWriter.setAttribute( 'columnWidths', columnWidthsAttribute, modelTable );
|
|
57
|
+
} );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns a helper for converting a model table `columnWidths` attribute to view `<colgroup>` and `<col>` elements.
|
|
62
|
+
*
|
|
63
|
+
* @returns {Function} Conversion helper.
|
|
64
|
+
*/
|
|
65
|
+
export function downcastTableColumnWidthsAttribute() {
|
|
66
|
+
return dispatcher => dispatcher.on( 'attribute:columnWidths:table', ( evt, data, conversionApi ) => {
|
|
67
|
+
const viewWriter = conversionApi.writer;
|
|
68
|
+
const modelTable = data.item;
|
|
69
|
+
|
|
70
|
+
const viewTable = [ ...conversionApi.mapper.toViewElement( modelTable ).getChildren() ]
|
|
71
|
+
.find( viewChild => viewChild.is( 'element', 'table' ) );
|
|
72
|
+
|
|
73
|
+
if ( data.attributeNewValue ) {
|
|
74
|
+
if ( data.attributeNewValue !== data.attributeOldValue ) {
|
|
75
|
+
insertColgroupElement( viewWriter, viewTable, data.attributeNewValue );
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
removeColgroupElement( viewWriter, viewTable );
|
|
79
|
+
}
|
|
80
|
+
} );
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Inserts the `<colgroup>` with `<col>` elements as the first child in the view table. Each `<col>` element represents a single column
|
|
84
|
+
// and it has the inline width style set, taken from the appropriate slot from the `columnWidths` table attribute.
|
|
85
|
+
//
|
|
86
|
+
// @private
|
|
87
|
+
// @param {module:engine/view/downcastwriter~DowncastWriter} viewWriter View writer instance.
|
|
88
|
+
// @param {module:engine/view/element~Element} viewTable View table.
|
|
89
|
+
// @param {String} columnWidthsAttribute Column width attribute from model table.
|
|
90
|
+
function insertColgroupElement( viewWriter, viewTable, columnWidthsAttribute ) {
|
|
91
|
+
const columnWidths = columnWidthsAttribute.split( ',' );
|
|
92
|
+
|
|
93
|
+
let viewColgroupElement = [ ...viewTable.getChildren() ].find( viewElement => viewElement.is( 'element', 'colgroup' ) );
|
|
94
|
+
|
|
95
|
+
if ( !viewColgroupElement ) {
|
|
96
|
+
viewColgroupElement = viewWriter.createContainerElement( 'colgroup' );
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for ( const viewChild of [ ...viewColgroupElement.getChildren() ] ) {
|
|
100
|
+
viewWriter.remove( viewChild );
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for ( const columnIndex of Array( columnWidths.length ).keys() ) {
|
|
104
|
+
const viewColElement = viewWriter.createEmptyElement( 'col' );
|
|
105
|
+
|
|
106
|
+
viewWriter.setStyle( 'width', columnWidths[ columnIndex ], viewColElement );
|
|
107
|
+
viewWriter.insert( viewWriter.createPositionAt( viewColgroupElement, 'end' ), viewColElement );
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
viewWriter.insert( viewWriter.createPositionAt( viewTable, 'start' ), viewColgroupElement );
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Removes the `<colgroup>` with `<col>` elements from the view table.
|
|
114
|
+
//
|
|
115
|
+
// @private
|
|
116
|
+
// @param {module:engine/view/downcastwriter~DowncastWriter} viewWriter View writer instance.
|
|
117
|
+
// @param {module:engine/view/element~Element} viewTable View table.
|
|
118
|
+
function removeColgroupElement( viewWriter, viewTable ) {
|
|
119
|
+
const viewColgroupElement = [ ...viewTable.getChildren() ].find( viewElement => viewElement.is( 'element', 'colgroup' ) );
|
|
120
|
+
|
|
121
|
+
if ( !viewColgroupElement ) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
viewWriter.remove( viewColgroupElement );
|
|
126
|
+
}
|