@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/dist/index.js
CHANGED
|
@@ -12,11 +12,6 @@ import { DomEventObserver, isColor, isLength, isPercentage, addBorderRules, addP
|
|
|
12
12
|
import { isObject, debounce, isEqual, throttle } from 'es-toolkit/compat';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
16
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
17
|
-
*/ /**
|
|
18
|
-
* @module table/converters/tableproperties
|
|
19
|
-
*/ /**
|
|
20
15
|
* Conversion helper for upcasting attributes using normalized styles.
|
|
21
16
|
*
|
|
22
17
|
* @param options.modelAttribute The attribute to set.
|
|
@@ -35,13 +30,26 @@ import { isObject, debounce, isEqual, throttle } from 'es-toolkit/compat';
|
|
|
35
30
|
},
|
|
36
31
|
model: {
|
|
37
32
|
key: modelAttribute,
|
|
38
|
-
value: (viewElement)=>{
|
|
33
|
+
value: (viewElement, conversionApi, data)=>{
|
|
39
34
|
if (!shouldUpcast(viewElement)) {
|
|
40
35
|
return;
|
|
41
36
|
}
|
|
37
|
+
let localDefaultValue = defaultValue;
|
|
38
|
+
// Adjust default for layout tables.
|
|
39
|
+
if (data.modelRange) {
|
|
40
|
+
const modelElement = first(data.modelRange.getItems({
|
|
41
|
+
shallow: true
|
|
42
|
+
}));
|
|
43
|
+
const tableElement = modelElement && modelElement.is('element') && modelElement.findAncestor('table', {
|
|
44
|
+
includeSelf: true
|
|
45
|
+
});
|
|
46
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
47
|
+
localDefaultValue = '';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
42
50
|
const normalized = viewElement.getNormalizedStyle(styleName);
|
|
43
51
|
const value = reduceBoxSides ? reduceBoxSidesValue(normalized) : normalized;
|
|
44
|
-
if (
|
|
52
|
+
if (localDefaultValue !== value) {
|
|
45
53
|
return value;
|
|
46
54
|
}
|
|
47
55
|
}
|
|
@@ -93,6 +101,17 @@ import { isObject, debounce, isEqual, throttle } from 'es-toolkit/compat';
|
|
|
93
101
|
shallow: true
|
|
94
102
|
})
|
|
95
103
|
].pop();
|
|
104
|
+
const tableElement = modelElement.findAncestor('table', {
|
|
105
|
+
includeSelf: true
|
|
106
|
+
});
|
|
107
|
+
let localDefaultBorder = defaultBorder;
|
|
108
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
109
|
+
localDefaultBorder = {
|
|
110
|
+
style: 'none',
|
|
111
|
+
color: '',
|
|
112
|
+
width: ''
|
|
113
|
+
};
|
|
114
|
+
}
|
|
96
115
|
conversionApi.consumable.consume(data.viewItem, matcherPattern);
|
|
97
116
|
const normalizedBorder = {
|
|
98
117
|
style: data.viewItem.getNormalizedStyle('border-style'),
|
|
@@ -104,13 +123,13 @@ import { isObject, debounce, isEqual, throttle } from 'es-toolkit/compat';
|
|
|
104
123
|
color: reduceBoxSidesValue(normalizedBorder.color),
|
|
105
124
|
width: reduceBoxSidesValue(normalizedBorder.width)
|
|
106
125
|
};
|
|
107
|
-
if (reducedBorder.style !==
|
|
126
|
+
if (reducedBorder.style !== localDefaultBorder.style) {
|
|
108
127
|
conversionApi.writer.setAttribute(modelAttributes.style, reducedBorder.style, modelElement);
|
|
109
128
|
}
|
|
110
|
-
if (reducedBorder.color !==
|
|
129
|
+
if (reducedBorder.color !== localDefaultBorder.color) {
|
|
111
130
|
conversionApi.writer.setAttribute(modelAttributes.color, reducedBorder.color, modelElement);
|
|
112
131
|
}
|
|
113
|
-
if (reducedBorder.width !==
|
|
132
|
+
if (reducedBorder.width !== localDefaultBorder.width) {
|
|
114
133
|
conversionApi.writer.setAttribute(modelAttributes.width, reducedBorder.width, modelElement);
|
|
115
134
|
}
|
|
116
135
|
}));
|
|
@@ -7073,7 +7092,12 @@ const isEmpty = (val)=>val === '';
|
|
|
7073
7092
|
return buttonValue === valueToCompare;
|
|
7074
7093
|
});
|
|
7075
7094
|
button.on('execute', ()=>{
|
|
7076
|
-
|
|
7095
|
+
// Allow toggling alignment if there is no default value specified (especially for layout tables).
|
|
7096
|
+
if (!defaultValue && buttonValue && view[propertyName] === buttonValue) {
|
|
7097
|
+
view[propertyName] = undefined;
|
|
7098
|
+
} else {
|
|
7099
|
+
view[propertyName] = buttonValue;
|
|
7100
|
+
}
|
|
7077
7101
|
});
|
|
7078
7102
|
toolbar.items.add(button);
|
|
7079
7103
|
}
|
|
@@ -8088,13 +8112,22 @@ const propertyToCommandMap$1 = {
|
|
|
8088
8112
|
*/ class TableCellPropertiesUI extends Plugin {
|
|
8089
8113
|
/**
|
|
8090
8114
|
* The default table cell properties.
|
|
8091
|
-
*/
|
|
8115
|
+
*/ _defaultContentTableCellProperties;
|
|
8116
|
+
/**
|
|
8117
|
+
* The default layout table cell properties.
|
|
8118
|
+
*/ _defaultLayoutTableCellProperties;
|
|
8092
8119
|
/**
|
|
8093
8120
|
* The contextual balloon plugin instance.
|
|
8094
8121
|
*/ _balloon;
|
|
8095
8122
|
/**
|
|
8096
8123
|
* The cell properties form view displayed inside the balloon.
|
|
8097
8124
|
*/ view;
|
|
8125
|
+
/**
|
|
8126
|
+
* The cell properties form view displayed inside the balloon (content table).
|
|
8127
|
+
*/ _viewWithContentTableDefaults;
|
|
8128
|
+
/**
|
|
8129
|
+
* The cell properties form view displayed inside the balloon (layout table).
|
|
8130
|
+
*/ _viewWithLayoutTableDefaults;
|
|
8098
8131
|
/**
|
|
8099
8132
|
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
8100
8133
|
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|
|
@@ -8134,12 +8167,17 @@ const propertyToCommandMap$1 = {
|
|
|
8134
8167
|
*/ init() {
|
|
8135
8168
|
const editor = this.editor;
|
|
8136
8169
|
const t = editor.t;
|
|
8137
|
-
this.
|
|
8170
|
+
this._defaultContentTableCellProperties = getNormalizedDefaultCellProperties(editor.config.get('table.tableCellProperties.defaultProperties'), {
|
|
8138
8171
|
includeVerticalAlignmentProperty: true,
|
|
8139
8172
|
includeHorizontalAlignmentProperty: true,
|
|
8140
8173
|
includePaddingProperty: true,
|
|
8141
8174
|
isRightToLeftContent: editor.locale.contentLanguageDirection === 'rtl'
|
|
8142
8175
|
});
|
|
8176
|
+
this._defaultLayoutTableCellProperties = getNormalizedDefaultProperties(undefined, {
|
|
8177
|
+
includeVerticalAlignmentProperty: true,
|
|
8178
|
+
includeHorizontalAlignmentProperty: true,
|
|
8179
|
+
isRightToLeftContent: editor.locale.contentLanguageDirection === 'rtl'
|
|
8180
|
+
});
|
|
8143
8181
|
this._balloon = editor.plugins.get(ContextualBalloon);
|
|
8144
8182
|
this.view = null;
|
|
8145
8183
|
this._isReady = false;
|
|
@@ -8170,7 +8208,7 @@ const propertyToCommandMap$1 = {
|
|
|
8170
8208
|
* Creates the {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView} instance.
|
|
8171
8209
|
*
|
|
8172
8210
|
* @returns The cell properties form view instance.
|
|
8173
|
-
*/ _createPropertiesView() {
|
|
8211
|
+
*/ _createPropertiesView(defaultTableCellProperties) {
|
|
8174
8212
|
const editor = this.editor;
|
|
8175
8213
|
const config = editor.config.get('table.tableCellProperties');
|
|
8176
8214
|
const borderColorsConfig = normalizeColorOptions(config.borderColors);
|
|
@@ -8181,7 +8219,7 @@ const propertyToCommandMap$1 = {
|
|
|
8181
8219
|
const view = new TableCellPropertiesView(editor.locale, {
|
|
8182
8220
|
borderColors: localizedBorderColors,
|
|
8183
8221
|
backgroundColors: localizedBackgroundColors,
|
|
8184
|
-
defaultTableCellProperties
|
|
8222
|
+
defaultTableCellProperties,
|
|
8185
8223
|
colorPickerConfig: hasColorPicker ? config.colorPicker || {} : false
|
|
8186
8224
|
});
|
|
8187
8225
|
const t = editor.t;
|
|
@@ -8270,7 +8308,8 @@ const propertyToCommandMap$1 = {
|
|
|
8270
8308
|
const commands = this.editor.commands;
|
|
8271
8309
|
const borderStyleCommand = commands.get('tableCellBorderStyle');
|
|
8272
8310
|
Object.entries(propertyToCommandMap$1).map(([property, commandName])=>{
|
|
8273
|
-
const
|
|
8311
|
+
const propertyKey = property;
|
|
8312
|
+
const defaultValue = this.view === this._viewWithContentTableDefaults ? this._defaultContentTableCellProperties[propertyKey] || '' : this._defaultLayoutTableCellProperties[propertyKey] || '';
|
|
8274
8313
|
return [
|
|
8275
8314
|
property,
|
|
8276
8315
|
commands.get(commandName).value || defaultValue
|
|
@@ -8292,9 +8331,15 @@ const propertyToCommandMap$1 = {
|
|
|
8292
8331
|
* for all of them.
|
|
8293
8332
|
*/ _showView() {
|
|
8294
8333
|
const editor = this.editor;
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8334
|
+
const viewTable = getSelectionAffectedTableWidget(editor.editing.view.document.selection);
|
|
8335
|
+
const modelTable = viewTable && editor.editing.mapper.toModelElement(viewTable);
|
|
8336
|
+
const useDefaults = !modelTable || modelTable.getAttribute('tableType') !== 'layout';
|
|
8337
|
+
if (useDefaults && !this._viewWithContentTableDefaults) {
|
|
8338
|
+
this._viewWithContentTableDefaults = this._createPropertiesView(this._defaultContentTableCellProperties);
|
|
8339
|
+
} else if (!useDefaults && !this._viewWithLayoutTableDefaults) {
|
|
8340
|
+
this._viewWithLayoutTableDefaults = this._createPropertiesView(this._defaultLayoutTableCellProperties);
|
|
8341
|
+
}
|
|
8342
|
+
this.view = useDefaults ? this._viewWithContentTableDefaults : this._viewWithLayoutTableDefaults;
|
|
8298
8343
|
this.listenTo(editor.ui, 'update', ()=>{
|
|
8299
8344
|
this._updateView();
|
|
8300
8345
|
});
|
|
@@ -8398,7 +8443,15 @@ const propertyToCommandMap$1 = {
|
|
|
8398
8443
|
*/ attributeName;
|
|
8399
8444
|
/**
|
|
8400
8445
|
* The default value for the attribute.
|
|
8446
|
+
*
|
|
8447
|
+
* @readonly
|
|
8401
8448
|
*/ _defaultValue;
|
|
8449
|
+
/**
|
|
8450
|
+
* The default value for the attribute for the content table.
|
|
8451
|
+
*/ _defaultContentTableValue;
|
|
8452
|
+
/**
|
|
8453
|
+
* The default value for the attribute for the layout table.
|
|
8454
|
+
*/ _defaultLayoutTableValue;
|
|
8402
8455
|
/**
|
|
8403
8456
|
* Creates a new `TableCellPropertyCommand` instance.
|
|
8404
8457
|
*
|
|
@@ -8408,14 +8461,31 @@ const propertyToCommandMap$1 = {
|
|
|
8408
8461
|
*/ constructor(editor, attributeName, defaultValue){
|
|
8409
8462
|
super(editor);
|
|
8410
8463
|
this.attributeName = attributeName;
|
|
8411
|
-
this.
|
|
8464
|
+
this._defaultContentTableValue = defaultValue;
|
|
8465
|
+
// Hardcoded defaults for layout table.
|
|
8466
|
+
switch(attributeName){
|
|
8467
|
+
case 'tableCellBorderStyle':
|
|
8468
|
+
this._defaultLayoutTableValue = 'none';
|
|
8469
|
+
break;
|
|
8470
|
+
case 'tableCellHorizontalAlignment':
|
|
8471
|
+
this._defaultLayoutTableValue = 'left';
|
|
8472
|
+
break;
|
|
8473
|
+
case 'tableCellVerticalAlignment':
|
|
8474
|
+
this._defaultLayoutTableValue = 'middle';
|
|
8475
|
+
break;
|
|
8476
|
+
default:
|
|
8477
|
+
this._defaultLayoutTableValue = undefined;
|
|
8478
|
+
}
|
|
8412
8479
|
}
|
|
8413
8480
|
/**
|
|
8414
8481
|
* @inheritDoc
|
|
8415
8482
|
*/ refresh() {
|
|
8416
8483
|
const editor = this.editor;
|
|
8484
|
+
const selection = editor.model.document.selection;
|
|
8417
8485
|
const tableUtils = this.editor.plugins.get('TableUtils');
|
|
8418
|
-
const selectedTableCells = tableUtils.getSelectionAffectedTableCells(
|
|
8486
|
+
const selectedTableCells = tableUtils.getSelectionAffectedTableCells(selection);
|
|
8487
|
+
const table = getSelectionAffectedTable(selection);
|
|
8488
|
+
this._defaultValue = !table || table.getAttribute('tableType') !== 'layout' ? this._defaultContentTableValue : this._defaultLayoutTableValue;
|
|
8419
8489
|
this.isEnabled = !!selectedTableCells.length;
|
|
8420
8490
|
this.value = this._getSingleValue(selectedTableCells);
|
|
8421
8491
|
}
|
|
@@ -9010,9 +9080,22 @@ const ALIGN_VALUES_REG_EXP$1 = /^(left|center|right|justify)$/;
|
|
|
9010
9080
|
},
|
|
9011
9081
|
model: {
|
|
9012
9082
|
key: 'tableCellHorizontalAlignment',
|
|
9013
|
-
value: (viewElement)=>{
|
|
9083
|
+
value: (viewElement, conversionApi, data)=>{
|
|
9084
|
+
let localDefaultValue = defaultValue;
|
|
9085
|
+
// Adjust default for layout tables.
|
|
9086
|
+
if (data.modelRange) {
|
|
9087
|
+
const modelElement = first(data.modelRange.getItems({
|
|
9088
|
+
shallow: true
|
|
9089
|
+
}));
|
|
9090
|
+
const tableElement = modelElement && modelElement.is('element') && modelElement.findAncestor('table', {
|
|
9091
|
+
includeSelf: true
|
|
9092
|
+
});
|
|
9093
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
9094
|
+
localDefaultValue = 'left';
|
|
9095
|
+
}
|
|
9096
|
+
}
|
|
9014
9097
|
const align = viewElement.getStyle('text-align');
|
|
9015
|
-
return align ===
|
|
9098
|
+
return align === localDefaultValue ? null : align;
|
|
9016
9099
|
}
|
|
9017
9100
|
}
|
|
9018
9101
|
})// Support for the `align` attribute as the backward compatibility while pasting from other sources.
|
|
@@ -9025,9 +9108,22 @@ const ALIGN_VALUES_REG_EXP$1 = /^(left|center|right|justify)$/;
|
|
|
9025
9108
|
},
|
|
9026
9109
|
model: {
|
|
9027
9110
|
key: 'tableCellHorizontalAlignment',
|
|
9028
|
-
value: (viewElement)=>{
|
|
9111
|
+
value: (viewElement, conversionApi, data)=>{
|
|
9112
|
+
let localDefaultValue = defaultValue;
|
|
9113
|
+
// Adjust default for layout tables.
|
|
9114
|
+
if (data.modelRange) {
|
|
9115
|
+
const modelElement = first(data.modelRange.getItems({
|
|
9116
|
+
shallow: true
|
|
9117
|
+
}));
|
|
9118
|
+
const tableElement = modelElement && modelElement.is('element') && modelElement.findAncestor('table', {
|
|
9119
|
+
includeSelf: true
|
|
9120
|
+
});
|
|
9121
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
9122
|
+
localDefaultValue = 'left';
|
|
9123
|
+
}
|
|
9124
|
+
}
|
|
9029
9125
|
const align = viewElement.getAttribute('align');
|
|
9030
|
-
return align ===
|
|
9126
|
+
return align === localDefaultValue ? null : align;
|
|
9031
9127
|
}
|
|
9032
9128
|
}
|
|
9033
9129
|
});
|
|
@@ -9064,9 +9160,22 @@ const ALIGN_VALUES_REG_EXP$1 = /^(left|center|right|justify)$/;
|
|
|
9064
9160
|
},
|
|
9065
9161
|
model: {
|
|
9066
9162
|
key: 'tableCellVerticalAlignment',
|
|
9067
|
-
value: (viewElement)=>{
|
|
9163
|
+
value: (viewElement, conversionApi, data)=>{
|
|
9164
|
+
let localDefaultValue = defaultValue;
|
|
9165
|
+
// Adjust default for layout tables.
|
|
9166
|
+
if (data.modelRange) {
|
|
9167
|
+
const modelElement = first(data.modelRange.getItems({
|
|
9168
|
+
shallow: true
|
|
9169
|
+
}));
|
|
9170
|
+
const tableElement = modelElement && modelElement.is('element') && modelElement.findAncestor('table', {
|
|
9171
|
+
includeSelf: true
|
|
9172
|
+
});
|
|
9173
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
9174
|
+
localDefaultValue = 'middle';
|
|
9175
|
+
}
|
|
9176
|
+
}
|
|
9068
9177
|
const align = viewElement.getStyle('vertical-align');
|
|
9069
|
-
return align ===
|
|
9178
|
+
return align === localDefaultValue ? null : align;
|
|
9070
9179
|
}
|
|
9071
9180
|
}
|
|
9072
9181
|
})// Support for the `align` attribute as the backward compatibility while pasting from other sources.
|
|
@@ -9079,9 +9188,22 @@ const ALIGN_VALUES_REG_EXP$1 = /^(left|center|right|justify)$/;
|
|
|
9079
9188
|
},
|
|
9080
9189
|
model: {
|
|
9081
9190
|
key: 'tableCellVerticalAlignment',
|
|
9082
|
-
value: (viewElement)=>{
|
|
9191
|
+
value: (viewElement, conversionApi, data)=>{
|
|
9192
|
+
let localDefaultValue = defaultValue;
|
|
9193
|
+
// Adjust default for layout tables.
|
|
9194
|
+
if (data.modelRange) {
|
|
9195
|
+
const modelElement = first(data.modelRange.getItems({
|
|
9196
|
+
shallow: true
|
|
9197
|
+
}));
|
|
9198
|
+
const tableElement = modelElement && modelElement.is('element') && modelElement.findAncestor('table', {
|
|
9199
|
+
includeSelf: true
|
|
9200
|
+
});
|
|
9201
|
+
if (tableElement && tableElement.getAttribute('tableType') == 'layout') {
|
|
9202
|
+
localDefaultValue = 'middle';
|
|
9203
|
+
}
|
|
9204
|
+
}
|
|
9083
9205
|
const valign = viewElement.getAttribute('valign');
|
|
9084
|
-
return valign ===
|
|
9206
|
+
return valign === localDefaultValue ? null : valign;
|
|
9085
9207
|
}
|
|
9086
9208
|
}
|
|
9087
9209
|
});
|
|
@@ -10447,7 +10569,15 @@ const TABLE_TYPES = [
|
|
|
10447
10569
|
*/ attributeName;
|
|
10448
10570
|
/**
|
|
10449
10571
|
* The default value for the attribute.
|
|
10572
|
+
*
|
|
10573
|
+
* @readonly
|
|
10450
10574
|
*/ _defaultValue;
|
|
10575
|
+
/**
|
|
10576
|
+
* The default value for the attribute for the content table.
|
|
10577
|
+
*/ _defaultContentTableValue;
|
|
10578
|
+
/**
|
|
10579
|
+
* The default value for the attribute for the layout table.
|
|
10580
|
+
*/ _defaultLayoutTableValue;
|
|
10451
10581
|
/**
|
|
10452
10582
|
* Creates a new `TablePropertyCommand` instance.
|
|
10453
10583
|
*
|
|
@@ -10457,7 +10587,8 @@ const TABLE_TYPES = [
|
|
|
10457
10587
|
*/ constructor(editor, attributeName, defaultValue){
|
|
10458
10588
|
super(editor);
|
|
10459
10589
|
this.attributeName = attributeName;
|
|
10460
|
-
this.
|
|
10590
|
+
this._defaultContentTableValue = defaultValue;
|
|
10591
|
+
this._defaultLayoutTableValue = attributeName === 'tableBorderStyle' ? 'none' : undefined;
|
|
10461
10592
|
}
|
|
10462
10593
|
/**
|
|
10463
10594
|
* @inheritDoc
|
|
@@ -10465,6 +10596,7 @@ const TABLE_TYPES = [
|
|
|
10465
10596
|
const editor = this.editor;
|
|
10466
10597
|
const selection = editor.model.document.selection;
|
|
10467
10598
|
const table = getSelectionAffectedTable(selection);
|
|
10599
|
+
this._defaultValue = !table || table.getAttribute('tableType') !== 'layout' ? this._defaultContentTableValue : this._defaultLayoutTableValue;
|
|
10468
10600
|
this.isEnabled = !!table;
|
|
10469
10601
|
this.value = this._getValue(table);
|
|
10470
10602
|
}
|
|
@@ -10894,15 +11026,40 @@ const FLOAT_VALUES_REG_EXP = /^(left|none|right)$/;
|
|
|
10894
11026
|
conversion.for('downcast').attributeToAttribute({
|
|
10895
11027
|
model: {
|
|
10896
11028
|
name: 'table',
|
|
10897
|
-
key: 'tableAlignment'
|
|
11029
|
+
key: 'tableAlignment',
|
|
11030
|
+
values: [
|
|
11031
|
+
'left',
|
|
11032
|
+
'center',
|
|
11033
|
+
'right'
|
|
11034
|
+
]
|
|
10898
11035
|
},
|
|
10899
|
-
view:
|
|
11036
|
+
view: {
|
|
11037
|
+
left: {
|
|
10900
11038
|
key: 'style',
|
|
10901
11039
|
value: {
|
|
10902
|
-
|
|
10903
|
-
float: alignment === 'center' ? 'none' : alignment
|
|
11040
|
+
float: 'left'
|
|
10904
11041
|
}
|
|
10905
|
-
}
|
|
11042
|
+
},
|
|
11043
|
+
right: {
|
|
11044
|
+
key: 'style',
|
|
11045
|
+
value: {
|
|
11046
|
+
float: 'right'
|
|
11047
|
+
}
|
|
11048
|
+
},
|
|
11049
|
+
center: (alignment, conversionApi, data)=>{
|
|
11050
|
+
const value = data.item.getAttribute('tableType') !== 'layout' ? {
|
|
11051
|
+
// Model: `alignment:center` => CSS: `float:none`.
|
|
11052
|
+
float: 'none'
|
|
11053
|
+
} : {
|
|
11054
|
+
'margin-left': 'auto',
|
|
11055
|
+
'margin-right': 'auto'
|
|
11056
|
+
};
|
|
11057
|
+
return {
|
|
11058
|
+
key: 'style',
|
|
11059
|
+
value
|
|
11060
|
+
};
|
|
11061
|
+
}
|
|
11062
|
+
},
|
|
10906
11063
|
converterPriority: 'high'
|
|
10907
11064
|
});
|
|
10908
11065
|
conversion.for('upcast')// Support for the `float:*;` CSS definition for the table alignment.
|
|
@@ -10915,13 +11072,23 @@ const FLOAT_VALUES_REG_EXP = /^(left|none|right)$/;
|
|
|
10915
11072
|
},
|
|
10916
11073
|
model: {
|
|
10917
11074
|
key: 'tableAlignment',
|
|
10918
|
-
value: (viewElement)=>{
|
|
11075
|
+
value: (viewElement, conversionApi, data)=>{
|
|
11076
|
+
let localDefaultValue = defaultValue;
|
|
11077
|
+
// Adjust default for layout tables.
|
|
11078
|
+
if (data.modelRange) {
|
|
11079
|
+
const modelElement = first(data.modelRange.getItems({
|
|
11080
|
+
shallow: true
|
|
11081
|
+
}));
|
|
11082
|
+
if (modelElement && modelElement.is('element') && modelElement.getAttribute('tableType') == 'layout') {
|
|
11083
|
+
localDefaultValue = '';
|
|
11084
|
+
}
|
|
11085
|
+
}
|
|
10919
11086
|
let align = viewElement.getStyle('float');
|
|
10920
11087
|
// CSS: `float:none` => Model: `alignment:center`.
|
|
10921
11088
|
if (align === 'none') {
|
|
10922
11089
|
align = 'center';
|
|
10923
11090
|
}
|
|
10924
|
-
return align ===
|
|
11091
|
+
return align === localDefaultValue ? null : align;
|
|
10925
11092
|
}
|
|
10926
11093
|
}
|
|
10927
11094
|
})// Support for the `align` attribute as the backward compatibility while pasting from other sources.
|
|
@@ -10934,9 +11101,19 @@ const FLOAT_VALUES_REG_EXP = /^(left|none|right)$/;
|
|
|
10934
11101
|
model: {
|
|
10935
11102
|
name: 'table',
|
|
10936
11103
|
key: 'tableAlignment',
|
|
10937
|
-
value: (viewElement)=>{
|
|
11104
|
+
value: (viewElement, conversionApi, data)=>{
|
|
11105
|
+
let localDefaultValue = defaultValue;
|
|
11106
|
+
// Adjust default for layout tables.
|
|
11107
|
+
if (data.modelRange) {
|
|
11108
|
+
const modelElement = first(data.modelRange.getItems({
|
|
11109
|
+
shallow: true
|
|
11110
|
+
}));
|
|
11111
|
+
if (modelElement && modelElement.is('element') && modelElement.getAttribute('tableType') == 'layout') {
|
|
11112
|
+
localDefaultValue = '';
|
|
11113
|
+
}
|
|
11114
|
+
}
|
|
10938
11115
|
const align = viewElement.getAttribute('align');
|
|
10939
|
-
return align ===
|
|
11116
|
+
return align === localDefaultValue ? null : align;
|
|
10940
11117
|
}
|
|
10941
11118
|
}
|
|
10942
11119
|
});
|
|
@@ -11489,13 +11666,22 @@ const propertyToCommandMap = {
|
|
|
11489
11666
|
*/ class TablePropertiesUI extends Plugin {
|
|
11490
11667
|
/**
|
|
11491
11668
|
* The default table properties.
|
|
11492
|
-
*/
|
|
11669
|
+
*/ _defaultContentTableProperties;
|
|
11670
|
+
/**
|
|
11671
|
+
* The default layout table properties.
|
|
11672
|
+
*/ _defaultLayoutTableProperties;
|
|
11493
11673
|
/**
|
|
11494
11674
|
* The contextual balloon plugin instance.
|
|
11495
11675
|
*/ _balloon;
|
|
11496
11676
|
/**
|
|
11497
11677
|
* The properties form view displayed inside the balloon.
|
|
11498
11678
|
*/ view = null;
|
|
11679
|
+
/**
|
|
11680
|
+
* The properties form view displayed inside the balloon (content table).
|
|
11681
|
+
*/ _viewWithContentTableDefaults = null;
|
|
11682
|
+
/**
|
|
11683
|
+
* The properties form view displayed inside the balloon (layout table).
|
|
11684
|
+
*/ _viewWithLayoutTableDefaults = null;
|
|
11499
11685
|
/**
|
|
11500
11686
|
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
11501
11687
|
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|
|
@@ -11534,9 +11720,10 @@ const propertyToCommandMap = {
|
|
|
11534
11720
|
* @inheritDoc
|
|
11535
11721
|
*/ init() {
|
|
11536
11722
|
const editor = this.editor;
|
|
11537
|
-
this.
|
|
11723
|
+
this._defaultContentTableProperties = getNormalizedDefaultTableProperties(editor.config.get('table.tableProperties.defaultProperties'), {
|
|
11538
11724
|
includeAlignmentProperty: true
|
|
11539
11725
|
});
|
|
11726
|
+
this._defaultLayoutTableProperties = getNormalizedDefaultProperties();
|
|
11540
11727
|
this._balloon = editor.plugins.get(ContextualBalloon);
|
|
11541
11728
|
editor.ui.componentFactory.add('tableProperties', ()=>this._createTablePropertiesButton());
|
|
11542
11729
|
}
|
|
@@ -11572,7 +11759,7 @@ const propertyToCommandMap = {
|
|
|
11572
11759
|
* Creates the {@link module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView} instance.
|
|
11573
11760
|
*
|
|
11574
11761
|
* @returns The table properties form view instance.
|
|
11575
|
-
*/ _createPropertiesView() {
|
|
11762
|
+
*/ _createPropertiesView(defaultTableProperties) {
|
|
11576
11763
|
const editor = this.editor;
|
|
11577
11764
|
const config = editor.config.get('table.tableProperties');
|
|
11578
11765
|
const borderColorsConfig = normalizeColorOptions(config.borderColors);
|
|
@@ -11583,7 +11770,7 @@ const propertyToCommandMap = {
|
|
|
11583
11770
|
const view = new TablePropertiesView(editor.locale, {
|
|
11584
11771
|
borderColors: localizedBorderColors,
|
|
11585
11772
|
backgroundColors: localizedBackgroundColors,
|
|
11586
|
-
defaultTableProperties
|
|
11773
|
+
defaultTableProperties,
|
|
11587
11774
|
colorPickerConfig: hasColorPicker ? config.colorPicker || {} : false
|
|
11588
11775
|
});
|
|
11589
11776
|
const t = editor.t;
|
|
@@ -11666,7 +11853,7 @@ const propertyToCommandMap = {
|
|
|
11666
11853
|
const borderStyleCommand = commands.get('tableBorderStyle');
|
|
11667
11854
|
Object.entries(propertyToCommandMap).map(([property, commandName])=>{
|
|
11668
11855
|
const propertyKey = property;
|
|
11669
|
-
const defaultValue = this.
|
|
11856
|
+
const defaultValue = this.view === this._viewWithContentTableDefaults ? this._defaultContentTableProperties[propertyKey] || '' : this._defaultLayoutTableProperties[propertyKey] || '';
|
|
11670
11857
|
return [
|
|
11671
11858
|
propertyKey,
|
|
11672
11859
|
commands.get(commandName).value || defaultValue
|
|
@@ -11688,9 +11875,15 @@ const propertyToCommandMap = {
|
|
|
11688
11875
|
* for all of them.
|
|
11689
11876
|
*/ _showView() {
|
|
11690
11877
|
const editor = this.editor;
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11878
|
+
const viewTable = getSelectionAffectedTableWidget(editor.editing.view.document.selection);
|
|
11879
|
+
const modelTable = viewTable && editor.editing.mapper.toModelElement(viewTable);
|
|
11880
|
+
const useDefaults = !modelTable || modelTable.getAttribute('tableType') !== 'layout';
|
|
11881
|
+
if (useDefaults && !this._viewWithContentTableDefaults) {
|
|
11882
|
+
this._viewWithContentTableDefaults = this._createPropertiesView(this._defaultContentTableProperties);
|
|
11883
|
+
} else if (!useDefaults && !this._viewWithLayoutTableDefaults) {
|
|
11884
|
+
this._viewWithLayoutTableDefaults = this._createPropertiesView(this._defaultLayoutTableProperties);
|
|
11885
|
+
}
|
|
11886
|
+
this.view = useDefaults ? this._viewWithContentTableDefaults : this._viewWithLayoutTableDefaults;
|
|
11694
11887
|
this.listenTo(editor.ui, 'update', ()=>{
|
|
11695
11888
|
this._updateView();
|
|
11696
11889
|
});
|