@ckeditor/ckeditor5-table 45.0.0-alpha.0 → 45.0.0-alpha.1
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/dist/index.js +240 -47
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/converters/tableproperties.js +25 -5
- package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +11 -1
- package/src/tablecellproperties/commands/tablecellpropertycommand.js +32 -2
- package/src/tablecellproperties/tablecellpropertiesediting.js +50 -9
- package/src/tablecellproperties/tablecellpropertiesui.d.ts +13 -1
- package/src/tablecellproperties/tablecellpropertiesui.js +36 -9
- package/src/tableproperties/commands/tablepropertycommand.d.ts +11 -1
- package/src/tableproperties/commands/tablepropertycommand.js +15 -1
- package/src/tableproperties/tablepropertiesediting.js +49 -11
- package/src/tableproperties/tablepropertiesui.d.ts +13 -1
- package/src/tableproperties/tablepropertiesui.js +30 -8
- package/src/tableproperties/ui/tablepropertiesview.d.ts +2 -2
- package/src/utils/table-properties.d.ts +3 -3
- package/src/utils/ui/table-properties.js +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-table",
|
|
3
|
-
"version": "45.0.0-alpha.
|
|
3
|
+
"version": "45.0.0-alpha.1",
|
|
4
4
|
"description": "Table feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"ckeditor5": "45.0.0-alpha.
|
|
17
|
-
"@ckeditor/ckeditor5-clipboard": "45.0.0-alpha.
|
|
18
|
-
"@ckeditor/ckeditor5-core": "45.0.0-alpha.
|
|
19
|
-
"@ckeditor/ckeditor5-engine": "45.0.0-alpha.
|
|
20
|
-
"@ckeditor/ckeditor5-icons": "45.0.0-alpha.
|
|
21
|
-
"@ckeditor/ckeditor5-ui": "45.0.0-alpha.
|
|
22
|
-
"@ckeditor/ckeditor5-utils": "45.0.0-alpha.
|
|
23
|
-
"@ckeditor/ckeditor5-widget": "45.0.0-alpha.
|
|
16
|
+
"ckeditor5": "45.0.0-alpha.1",
|
|
17
|
+
"@ckeditor/ckeditor5-clipboard": "45.0.0-alpha.1",
|
|
18
|
+
"@ckeditor/ckeditor5-core": "45.0.0-alpha.1",
|
|
19
|
+
"@ckeditor/ckeditor5-engine": "45.0.0-alpha.1",
|
|
20
|
+
"@ckeditor/ckeditor5-icons": "45.0.0-alpha.1",
|
|
21
|
+
"@ckeditor/ckeditor5-ui": "45.0.0-alpha.1",
|
|
22
|
+
"@ckeditor/ckeditor5-utils": "45.0.0-alpha.1",
|
|
23
|
+
"@ckeditor/ckeditor5-widget": "45.0.0-alpha.1",
|
|
24
24
|
"es-toolkit": "1.32.0"
|
|
25
25
|
},
|
|
26
26
|
"author": "CKSource (http://cksource.com/)",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
+
import { first } from 'ckeditor5/src/utils.js';
|
|
5
6
|
/**
|
|
6
7
|
* Conversion helper for upcasting attributes using normalized styles.
|
|
7
8
|
*
|
|
@@ -22,13 +23,23 @@ export function upcastStyleToAttribute(conversion, options) {
|
|
|
22
23
|
},
|
|
23
24
|
model: {
|
|
24
25
|
key: modelAttribute,
|
|
25
|
-
value: (viewElement) => {
|
|
26
|
+
value: (viewElement, conversionApi, data) => {
|
|
26
27
|
if (!shouldUpcast(viewElement)) {
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
30
|
+
let localDefaultValue = defaultValue;
|
|
31
|
+
// Adjust default for layout tables.
|
|
32
|
+
if (data.modelRange) {
|
|
33
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
34
|
+
const tableElement = modelElement && modelElement.is('element') &&
|
|
35
|
+
modelElement.findAncestor('table', { includeSelf: true });
|
|
36
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
37
|
+
localDefaultValue = '';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
29
40
|
const normalized = viewElement.getNormalizedStyle(styleName);
|
|
30
41
|
const value = reduceBoxSides ? reduceBoxSidesValue(normalized) : normalized;
|
|
31
|
-
if (
|
|
42
|
+
if (localDefaultValue !== value) {
|
|
32
43
|
return value;
|
|
33
44
|
}
|
|
34
45
|
}
|
|
@@ -77,6 +88,15 @@ export function upcastBorderStyles(conversion, viewElementName, modelAttributes,
|
|
|
77
88
|
return;
|
|
78
89
|
}
|
|
79
90
|
const modelElement = [...data.modelRange.getItems({ shallow: true })].pop();
|
|
91
|
+
const tableElement = modelElement.findAncestor('table', { includeSelf: true });
|
|
92
|
+
let localDefaultBorder = defaultBorder;
|
|
93
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
94
|
+
localDefaultBorder = {
|
|
95
|
+
style: 'none',
|
|
96
|
+
color: '',
|
|
97
|
+
width: ''
|
|
98
|
+
};
|
|
99
|
+
}
|
|
80
100
|
conversionApi.consumable.consume(data.viewItem, matcherPattern);
|
|
81
101
|
const normalizedBorder = {
|
|
82
102
|
style: data.viewItem.getNormalizedStyle('border-style'),
|
|
@@ -88,13 +108,13 @@ export function upcastBorderStyles(conversion, viewElementName, modelAttributes,
|
|
|
88
108
|
color: reduceBoxSidesValue(normalizedBorder.color),
|
|
89
109
|
width: reduceBoxSidesValue(normalizedBorder.width)
|
|
90
110
|
};
|
|
91
|
-
if (reducedBorder.style !==
|
|
111
|
+
if (reducedBorder.style !== localDefaultBorder.style) {
|
|
92
112
|
conversionApi.writer.setAttribute(modelAttributes.style, reducedBorder.style, modelElement);
|
|
93
113
|
}
|
|
94
|
-
if (reducedBorder.color !==
|
|
114
|
+
if (reducedBorder.color !== localDefaultBorder.color) {
|
|
95
115
|
conversionApi.writer.setAttribute(modelAttributes.color, reducedBorder.color, modelElement);
|
|
96
116
|
}
|
|
97
|
-
if (reducedBorder.width !==
|
|
117
|
+
if (reducedBorder.width !== localDefaultBorder.width) {
|
|
98
118
|
conversionApi.writer.setAttribute(modelAttributes.width, reducedBorder.width, modelElement);
|
|
99
119
|
}
|
|
100
120
|
}));
|
|
@@ -19,8 +19,18 @@ export default class TableCellPropertyCommand extends Command {
|
|
|
19
19
|
readonly attributeName: string;
|
|
20
20
|
/**
|
|
21
21
|
* The default value for the attribute.
|
|
22
|
+
*
|
|
23
|
+
* @readonly
|
|
24
|
+
*/
|
|
25
|
+
protected _defaultValue: string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The default value for the attribute for the content table.
|
|
28
|
+
*/
|
|
29
|
+
private readonly _defaultContentTableValue;
|
|
30
|
+
/**
|
|
31
|
+
* The default value for the attribute for the layout table.
|
|
22
32
|
*/
|
|
23
|
-
|
|
33
|
+
private readonly _defaultLayoutTableValue;
|
|
24
34
|
/**
|
|
25
35
|
* Creates a new `TableCellPropertyCommand` instance.
|
|
26
36
|
*
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @module table/tablecellproperties/commands/tablecellpropertycommand
|
|
7
7
|
*/
|
|
8
8
|
import { Command } from 'ckeditor5/src/core.js';
|
|
9
|
+
import { getSelectionAffectedTable } from '../../utils/common.js';
|
|
9
10
|
/**
|
|
10
11
|
* The table cell attribute command.
|
|
11
12
|
*
|
|
@@ -18,8 +19,18 @@ export default class TableCellPropertyCommand extends Command {
|
|
|
18
19
|
attributeName;
|
|
19
20
|
/**
|
|
20
21
|
* The default value for the attribute.
|
|
22
|
+
*
|
|
23
|
+
* @readonly
|
|
21
24
|
*/
|
|
22
25
|
_defaultValue;
|
|
26
|
+
/**
|
|
27
|
+
* The default value for the attribute for the content table.
|
|
28
|
+
*/
|
|
29
|
+
_defaultContentTableValue;
|
|
30
|
+
/**
|
|
31
|
+
* The default value for the attribute for the layout table.
|
|
32
|
+
*/
|
|
33
|
+
_defaultLayoutTableValue;
|
|
23
34
|
/**
|
|
24
35
|
* Creates a new `TableCellPropertyCommand` instance.
|
|
25
36
|
*
|
|
@@ -30,15 +41,34 @@ export default class TableCellPropertyCommand extends Command {
|
|
|
30
41
|
constructor(editor, attributeName, defaultValue) {
|
|
31
42
|
super(editor);
|
|
32
43
|
this.attributeName = attributeName;
|
|
33
|
-
this.
|
|
44
|
+
this._defaultContentTableValue = defaultValue;
|
|
45
|
+
// Hardcoded defaults for layout table.
|
|
46
|
+
switch (attributeName) {
|
|
47
|
+
case 'tableCellBorderStyle':
|
|
48
|
+
this._defaultLayoutTableValue = 'none';
|
|
49
|
+
break;
|
|
50
|
+
case 'tableCellHorizontalAlignment':
|
|
51
|
+
this._defaultLayoutTableValue = 'left';
|
|
52
|
+
break;
|
|
53
|
+
case 'tableCellVerticalAlignment':
|
|
54
|
+
this._defaultLayoutTableValue = 'middle';
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
this._defaultLayoutTableValue = undefined;
|
|
58
|
+
}
|
|
34
59
|
}
|
|
35
60
|
/**
|
|
36
61
|
* @inheritDoc
|
|
37
62
|
*/
|
|
38
63
|
refresh() {
|
|
39
64
|
const editor = this.editor;
|
|
65
|
+
const selection = editor.model.document.selection;
|
|
40
66
|
const tableUtils = this.editor.plugins.get('TableUtils');
|
|
41
|
-
const selectedTableCells = tableUtils.getSelectionAffectedTableCells(
|
|
67
|
+
const selectedTableCells = tableUtils.getSelectionAffectedTableCells(selection);
|
|
68
|
+
const table = getSelectionAffectedTable(selection);
|
|
69
|
+
this._defaultValue = !table || table.getAttribute('tableType') !== 'layout' ?
|
|
70
|
+
this._defaultContentTableValue :
|
|
71
|
+
this._defaultLayoutTableValue;
|
|
42
72
|
this.isEnabled = !!selectedTableCells.length;
|
|
43
73
|
this.value = this._getSingleValue(selectedTableCells);
|
|
44
74
|
}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* @module table/tablecellproperties/tablecellpropertiesediting
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
+
import { first } from 'ckeditor5/src/utils.js';
|
|
9
10
|
import { addBorderRules, addPaddingRules, addBackgroundRules } from 'ckeditor5/src/engine.js';
|
|
10
|
-
import { downcastAttributeToStyle, upcastBorderStyles } from '
|
|
11
|
+
import { downcastAttributeToStyle, upcastBorderStyles } from '../converters/tableproperties.js';
|
|
11
12
|
import TableEditing from './../tableediting.js';
|
|
12
13
|
import TableCellWidthEditing from '../tablecellwidth/tablecellwidthediting.js';
|
|
13
14
|
import TableCellPaddingCommand from './commands/tablecellpaddingcommand.js';
|
|
@@ -166,9 +167,19 @@ function enableHorizontalAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
166
167
|
},
|
|
167
168
|
model: {
|
|
168
169
|
key: 'tableCellHorizontalAlignment',
|
|
169
|
-
value: (viewElement) => {
|
|
170
|
+
value: (viewElement, conversionApi, data) => {
|
|
171
|
+
let localDefaultValue = defaultValue;
|
|
172
|
+
// Adjust default for layout tables.
|
|
173
|
+
if (data.modelRange) {
|
|
174
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
175
|
+
const tableElement = modelElement && modelElement.is('element') &&
|
|
176
|
+
modelElement.findAncestor('table', { includeSelf: true });
|
|
177
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
178
|
+
localDefaultValue = 'left';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
170
181
|
const align = viewElement.getStyle('text-align');
|
|
171
|
-
return align ===
|
|
182
|
+
return align === localDefaultValue ? null : align;
|
|
172
183
|
}
|
|
173
184
|
}
|
|
174
185
|
})
|
|
@@ -182,9 +193,19 @@ function enableHorizontalAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
182
193
|
},
|
|
183
194
|
model: {
|
|
184
195
|
key: 'tableCellHorizontalAlignment',
|
|
185
|
-
value: (viewElement) => {
|
|
196
|
+
value: (viewElement, conversionApi, data) => {
|
|
197
|
+
let localDefaultValue = defaultValue;
|
|
198
|
+
// Adjust default for layout tables.
|
|
199
|
+
if (data.modelRange) {
|
|
200
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
201
|
+
const tableElement = modelElement && modelElement.is('element') &&
|
|
202
|
+
modelElement.findAncestor('table', { includeSelf: true });
|
|
203
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
204
|
+
localDefaultValue = 'left';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
186
207
|
const align = viewElement.getAttribute('align');
|
|
187
|
-
return align ===
|
|
208
|
+
return align === localDefaultValue ? null : align;
|
|
188
209
|
}
|
|
189
210
|
}
|
|
190
211
|
});
|
|
@@ -222,9 +243,19 @@ function enableVerticalAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
222
243
|
},
|
|
223
244
|
model: {
|
|
224
245
|
key: 'tableCellVerticalAlignment',
|
|
225
|
-
value: (viewElement) => {
|
|
246
|
+
value: (viewElement, conversionApi, data) => {
|
|
247
|
+
let localDefaultValue = defaultValue;
|
|
248
|
+
// Adjust default for layout tables.
|
|
249
|
+
if (data.modelRange) {
|
|
250
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
251
|
+
const tableElement = modelElement && modelElement.is('element') &&
|
|
252
|
+
modelElement.findAncestor('table', { includeSelf: true });
|
|
253
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
254
|
+
localDefaultValue = 'middle';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
226
257
|
const align = viewElement.getStyle('vertical-align');
|
|
227
|
-
return align ===
|
|
258
|
+
return align === localDefaultValue ? null : align;
|
|
228
259
|
}
|
|
229
260
|
}
|
|
230
261
|
})
|
|
@@ -238,9 +269,19 @@ function enableVerticalAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
238
269
|
},
|
|
239
270
|
model: {
|
|
240
271
|
key: 'tableCellVerticalAlignment',
|
|
241
|
-
value: (viewElement) => {
|
|
272
|
+
value: (viewElement, conversionApi, data) => {
|
|
273
|
+
let localDefaultValue = defaultValue;
|
|
274
|
+
// Adjust default for layout tables.
|
|
275
|
+
if (data.modelRange) {
|
|
276
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
277
|
+
const tableElement = modelElement && modelElement.is('element') &&
|
|
278
|
+
modelElement.findAncestor('table', { includeSelf: true });
|
|
279
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
280
|
+
localDefaultValue = 'middle';
|
|
281
|
+
}
|
|
282
|
+
}
|
|
242
283
|
const valign = viewElement.getAttribute('valign');
|
|
243
|
-
return valign ===
|
|
284
|
+
return valign === localDefaultValue ? null : valign;
|
|
244
285
|
}
|
|
245
286
|
}
|
|
246
287
|
});
|
|
@@ -18,7 +18,11 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
18
18
|
/**
|
|
19
19
|
* The default table cell properties.
|
|
20
20
|
*/
|
|
21
|
-
private
|
|
21
|
+
private _defaultContentTableCellProperties;
|
|
22
|
+
/**
|
|
23
|
+
* The default layout table cell properties.
|
|
24
|
+
*/
|
|
25
|
+
private _defaultLayoutTableCellProperties;
|
|
22
26
|
/**
|
|
23
27
|
* The contextual balloon plugin instance.
|
|
24
28
|
*/
|
|
@@ -27,6 +31,14 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
27
31
|
* The cell properties form view displayed inside the balloon.
|
|
28
32
|
*/
|
|
29
33
|
view?: TableCellPropertiesView | null;
|
|
34
|
+
/**
|
|
35
|
+
* The cell properties form view displayed inside the balloon (content table).
|
|
36
|
+
*/
|
|
37
|
+
private _viewWithContentTableDefaults?;
|
|
38
|
+
/**
|
|
39
|
+
* The cell properties form view displayed inside the balloon (layout table).
|
|
40
|
+
*/
|
|
41
|
+
private _viewWithLayoutTableDefaults?;
|
|
30
42
|
/**
|
|
31
43
|
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
32
44
|
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|
|
@@ -11,9 +11,9 @@ import { ButtonView, clickOutsideHandler, ContextualBalloon, getLocalizedColorOp
|
|
|
11
11
|
import TableCellPropertiesView from './ui/tablecellpropertiesview.js';
|
|
12
12
|
import { colorFieldValidator, getLocalizedColorErrorText, getLocalizedLengthErrorText, defaultColors, lengthFieldValidator, lineWidthFieldValidator } from '../utils/ui/table-properties.js';
|
|
13
13
|
import { debounce } from 'es-toolkit/compat';
|
|
14
|
-
import { getTableWidgetAncestor } from '../utils/ui/widget.js';
|
|
14
|
+
import { getSelectionAffectedTableWidget, getTableWidgetAncestor } from '../utils/ui/widget.js';
|
|
15
15
|
import { getBalloonCellPositionData, repositionContextualBalloon } from '../utils/ui/contextualballoon.js';
|
|
16
|
-
import { getNormalizedDefaultCellProperties } from '../utils/table-properties.js';
|
|
16
|
+
import { getNormalizedDefaultCellProperties, getNormalizedDefaultProperties } from '../utils/table-properties.js';
|
|
17
17
|
const ERROR_TEXT_TIMEOUT = 500;
|
|
18
18
|
// Map of view properties and related commands.
|
|
19
19
|
const propertyToCommandMap = {
|
|
@@ -37,7 +37,11 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
37
37
|
/**
|
|
38
38
|
* The default table cell properties.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
_defaultContentTableCellProperties;
|
|
41
|
+
/**
|
|
42
|
+
* The default layout table cell properties.
|
|
43
|
+
*/
|
|
44
|
+
_defaultLayoutTableCellProperties;
|
|
41
45
|
/**
|
|
42
46
|
* The contextual balloon plugin instance.
|
|
43
47
|
*/
|
|
@@ -46,6 +50,14 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
46
50
|
* The cell properties form view displayed inside the balloon.
|
|
47
51
|
*/
|
|
48
52
|
view;
|
|
53
|
+
/**
|
|
54
|
+
* The cell properties form view displayed inside the balloon (content table).
|
|
55
|
+
*/
|
|
56
|
+
_viewWithContentTableDefaults;
|
|
57
|
+
/**
|
|
58
|
+
* The cell properties form view displayed inside the balloon (layout table).
|
|
59
|
+
*/
|
|
60
|
+
_viewWithLayoutTableDefaults;
|
|
49
61
|
/**
|
|
50
62
|
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
51
63
|
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|
|
@@ -90,12 +102,17 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
90
102
|
init() {
|
|
91
103
|
const editor = this.editor;
|
|
92
104
|
const t = editor.t;
|
|
93
|
-
this.
|
|
105
|
+
this._defaultContentTableCellProperties = getNormalizedDefaultCellProperties(editor.config.get('table.tableCellProperties.defaultProperties'), {
|
|
94
106
|
includeVerticalAlignmentProperty: true,
|
|
95
107
|
includeHorizontalAlignmentProperty: true,
|
|
96
108
|
includePaddingProperty: true,
|
|
97
109
|
isRightToLeftContent: editor.locale.contentLanguageDirection === 'rtl'
|
|
98
110
|
});
|
|
111
|
+
this._defaultLayoutTableCellProperties = getNormalizedDefaultProperties(undefined, {
|
|
112
|
+
includeVerticalAlignmentProperty: true,
|
|
113
|
+
includeHorizontalAlignmentProperty: true,
|
|
114
|
+
isRightToLeftContent: editor.locale.contentLanguageDirection === 'rtl'
|
|
115
|
+
});
|
|
99
116
|
this._balloon = editor.plugins.get(ContextualBalloon);
|
|
100
117
|
this.view = null;
|
|
101
118
|
this._isReady = false;
|
|
@@ -129,7 +146,7 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
129
146
|
*
|
|
130
147
|
* @returns The cell properties form view instance.
|
|
131
148
|
*/
|
|
132
|
-
_createPropertiesView() {
|
|
149
|
+
_createPropertiesView(defaultTableCellProperties) {
|
|
133
150
|
const editor = this.editor;
|
|
134
151
|
const config = editor.config.get('table.tableCellProperties');
|
|
135
152
|
const borderColorsConfig = normalizeColorOptions(config.borderColors);
|
|
@@ -140,7 +157,7 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
140
157
|
const view = new TableCellPropertiesView(editor.locale, {
|
|
141
158
|
borderColors: localizedBorderColors,
|
|
142
159
|
backgroundColors: localizedBackgroundColors,
|
|
143
|
-
defaultTableCellProperties
|
|
160
|
+
defaultTableCellProperties,
|
|
144
161
|
colorPickerConfig: hasColorPicker ? (config.colorPicker || {}) : false
|
|
145
162
|
});
|
|
146
163
|
const t = editor.t;
|
|
@@ -229,7 +246,10 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
229
246
|
const borderStyleCommand = commands.get('tableCellBorderStyle');
|
|
230
247
|
Object.entries(propertyToCommandMap)
|
|
231
248
|
.map(([property, commandName]) => {
|
|
232
|
-
const
|
|
249
|
+
const propertyKey = property;
|
|
250
|
+
const defaultValue = this.view === this._viewWithContentTableDefaults ?
|
|
251
|
+
this._defaultContentTableCellProperties[propertyKey] || '' :
|
|
252
|
+
this._defaultLayoutTableCellProperties[propertyKey] || '';
|
|
233
253
|
return [
|
|
234
254
|
property,
|
|
235
255
|
commands.get(commandName).value || defaultValue
|
|
@@ -253,9 +273,16 @@ export default class TableCellPropertiesUI extends Plugin {
|
|
|
253
273
|
*/
|
|
254
274
|
_showView() {
|
|
255
275
|
const editor = this.editor;
|
|
256
|
-
|
|
257
|
-
|
|
276
|
+
const viewTable = getSelectionAffectedTableWidget(editor.editing.view.document.selection);
|
|
277
|
+
const modelTable = viewTable && editor.editing.mapper.toModelElement(viewTable);
|
|
278
|
+
const useDefaults = !modelTable || modelTable.getAttribute('tableType') !== 'layout';
|
|
279
|
+
if (useDefaults && !this._viewWithContentTableDefaults) {
|
|
280
|
+
this._viewWithContentTableDefaults = this._createPropertiesView(this._defaultContentTableCellProperties);
|
|
281
|
+
}
|
|
282
|
+
else if (!useDefaults && !this._viewWithLayoutTableDefaults) {
|
|
283
|
+
this._viewWithLayoutTableDefaults = this._createPropertiesView(this._defaultLayoutTableCellProperties);
|
|
258
284
|
}
|
|
285
|
+
this.view = useDefaults ? this._viewWithContentTableDefaults : this._viewWithLayoutTableDefaults;
|
|
259
286
|
this.listenTo(editor.ui, 'update', () => {
|
|
260
287
|
this._updateView();
|
|
261
288
|
});
|
|
@@ -26,8 +26,18 @@ export default class TablePropertyCommand extends Command {
|
|
|
26
26
|
readonly attributeName: string;
|
|
27
27
|
/**
|
|
28
28
|
* The default value for the attribute.
|
|
29
|
+
*
|
|
30
|
+
* @readonly
|
|
31
|
+
*/
|
|
32
|
+
protected _defaultValue: string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The default value for the attribute for the content table.
|
|
35
|
+
*/
|
|
36
|
+
private readonly _defaultContentTableValue;
|
|
37
|
+
/**
|
|
38
|
+
* The default value for the attribute for the layout table.
|
|
29
39
|
*/
|
|
30
|
-
|
|
40
|
+
private readonly _defaultLayoutTableValue;
|
|
31
41
|
/**
|
|
32
42
|
* Creates a new `TablePropertyCommand` instance.
|
|
33
43
|
*
|
|
@@ -16,8 +16,18 @@ export default class TablePropertyCommand extends Command {
|
|
|
16
16
|
attributeName;
|
|
17
17
|
/**
|
|
18
18
|
* The default value for the attribute.
|
|
19
|
+
*
|
|
20
|
+
* @readonly
|
|
19
21
|
*/
|
|
20
22
|
_defaultValue;
|
|
23
|
+
/**
|
|
24
|
+
* The default value for the attribute for the content table.
|
|
25
|
+
*/
|
|
26
|
+
_defaultContentTableValue;
|
|
27
|
+
/**
|
|
28
|
+
* The default value for the attribute for the layout table.
|
|
29
|
+
*/
|
|
30
|
+
_defaultLayoutTableValue;
|
|
21
31
|
/**
|
|
22
32
|
* Creates a new `TablePropertyCommand` instance.
|
|
23
33
|
*
|
|
@@ -28,7 +38,8 @@ export default class TablePropertyCommand extends Command {
|
|
|
28
38
|
constructor(editor, attributeName, defaultValue) {
|
|
29
39
|
super(editor);
|
|
30
40
|
this.attributeName = attributeName;
|
|
31
|
-
this.
|
|
41
|
+
this._defaultContentTableValue = defaultValue;
|
|
42
|
+
this._defaultLayoutTableValue = attributeName === 'tableBorderStyle' ? 'none' : undefined;
|
|
32
43
|
}
|
|
33
44
|
/**
|
|
34
45
|
* @inheritDoc
|
|
@@ -37,6 +48,9 @@ export default class TablePropertyCommand extends Command {
|
|
|
37
48
|
const editor = this.editor;
|
|
38
49
|
const selection = editor.model.document.selection;
|
|
39
50
|
const table = getSelectionAffectedTable(selection);
|
|
51
|
+
this._defaultValue = !table || table.getAttribute('tableType') !== 'layout' ?
|
|
52
|
+
this._defaultContentTableValue :
|
|
53
|
+
this._defaultLayoutTableValue;
|
|
40
54
|
this.isEnabled = !!table;
|
|
41
55
|
this.value = this._getValue(table);
|
|
42
56
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @module table/tableproperties/tablepropertiesediting
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
+
import { first } from 'ckeditor5/src/utils.js';
|
|
9
10
|
import { addBackgroundRules, addBorderRules } from 'ckeditor5/src/engine.js';
|
|
10
11
|
import TableEditing from '../tableediting.js';
|
|
11
12
|
import { downcastAttributeToStyle, downcastTableAttribute, upcastBorderStyles, upcastStyleToAttribute } from '../converters/tableproperties.js';
|
|
@@ -133,15 +134,36 @@ function enableAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
133
134
|
.attributeToAttribute({
|
|
134
135
|
model: {
|
|
135
136
|
name: 'table',
|
|
136
|
-
key: 'tableAlignment'
|
|
137
|
+
key: 'tableAlignment',
|
|
138
|
+
values: ['left', 'center', 'right']
|
|
137
139
|
},
|
|
138
|
-
view:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
view: {
|
|
141
|
+
left: {
|
|
142
|
+
key: 'style',
|
|
143
|
+
value: {
|
|
144
|
+
float: 'left'
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
right: {
|
|
148
|
+
key: 'style',
|
|
149
|
+
value: {
|
|
150
|
+
float: 'right'
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
center: (alignment, conversionApi, data) => {
|
|
154
|
+
const value = data.item.getAttribute('tableType') !== 'layout' ? {
|
|
155
|
+
// Model: `alignment:center` => CSS: `float:none`.
|
|
156
|
+
float: 'none'
|
|
157
|
+
} : {
|
|
158
|
+
'margin-left': 'auto',
|
|
159
|
+
'margin-right': 'auto'
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
key: 'style',
|
|
163
|
+
value
|
|
164
|
+
};
|
|
143
165
|
}
|
|
144
|
-
}
|
|
166
|
+
},
|
|
145
167
|
converterPriority: 'high'
|
|
146
168
|
});
|
|
147
169
|
conversion.for('upcast')
|
|
@@ -155,13 +177,21 @@ function enableAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
155
177
|
},
|
|
156
178
|
model: {
|
|
157
179
|
key: 'tableAlignment',
|
|
158
|
-
value: (viewElement) => {
|
|
180
|
+
value: (viewElement, conversionApi, data) => {
|
|
181
|
+
let localDefaultValue = defaultValue;
|
|
182
|
+
// Adjust default for layout tables.
|
|
183
|
+
if (data.modelRange) {
|
|
184
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
185
|
+
if (modelElement && modelElement.is('element') && modelElement.getAttribute('tableType') == 'layout') {
|
|
186
|
+
localDefaultValue = '';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
159
189
|
let align = viewElement.getStyle('float');
|
|
160
190
|
// CSS: `float:none` => Model: `alignment:center`.
|
|
161
191
|
if (align === 'none') {
|
|
162
192
|
align = 'center';
|
|
163
193
|
}
|
|
164
|
-
return align ===
|
|
194
|
+
return align === localDefaultValue ? null : align;
|
|
165
195
|
}
|
|
166
196
|
}
|
|
167
197
|
})
|
|
@@ -175,9 +205,17 @@ function enableAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
175
205
|
model: {
|
|
176
206
|
name: 'table',
|
|
177
207
|
key: 'tableAlignment',
|
|
178
|
-
value: (viewElement) => {
|
|
208
|
+
value: (viewElement, conversionApi, data) => {
|
|
209
|
+
let localDefaultValue = defaultValue;
|
|
210
|
+
// Adjust default for layout tables.
|
|
211
|
+
if (data.modelRange) {
|
|
212
|
+
const modelElement = first(data.modelRange.getItems({ shallow: true }));
|
|
213
|
+
if (modelElement && modelElement.is('element') && modelElement.getAttribute('tableType') == 'layout') {
|
|
214
|
+
localDefaultValue = '';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
179
217
|
const align = viewElement.getAttribute('align');
|
|
180
|
-
return align ===
|
|
218
|
+
return align === localDefaultValue ? null : align;
|
|
181
219
|
}
|
|
182
220
|
}
|
|
183
221
|
});
|
|
@@ -18,7 +18,11 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
18
18
|
/**
|
|
19
19
|
* The default table properties.
|
|
20
20
|
*/
|
|
21
|
-
private
|
|
21
|
+
private _defaultContentTableProperties;
|
|
22
|
+
/**
|
|
23
|
+
* The default layout table properties.
|
|
24
|
+
*/
|
|
25
|
+
private _defaultLayoutTableProperties;
|
|
22
26
|
/**
|
|
23
27
|
* The contextual balloon plugin instance.
|
|
24
28
|
*/
|
|
@@ -27,6 +31,14 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
27
31
|
* The properties form view displayed inside the balloon.
|
|
28
32
|
*/
|
|
29
33
|
view: TablePropertiesView | null;
|
|
34
|
+
/**
|
|
35
|
+
* The properties form view displayed inside the balloon (content table).
|
|
36
|
+
*/
|
|
37
|
+
private _viewWithContentTableDefaults;
|
|
38
|
+
/**
|
|
39
|
+
* The properties form view displayed inside the balloon (layout table).
|
|
40
|
+
*/
|
|
41
|
+
private _viewWithLayoutTableDefaults;
|
|
30
42
|
/**
|
|
31
43
|
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
32
44
|
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|