@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
|
@@ -13,7 +13,7 @@ import TablePropertiesView from './ui/tablepropertiesview.js';
|
|
|
13
13
|
import { colorFieldValidator, getLocalizedColorErrorText, getLocalizedLengthErrorText, lengthFieldValidator, lineWidthFieldValidator, defaultColors } from '../utils/ui/table-properties.js';
|
|
14
14
|
import { getSelectionAffectedTableWidget } from '../utils/ui/widget.js';
|
|
15
15
|
import { getBalloonTablePositionData, repositionContextualBalloon } from '../utils/ui/contextualballoon.js';
|
|
16
|
-
import { getNormalizedDefaultTableProperties } from '../utils/table-properties.js';
|
|
16
|
+
import { getNormalizedDefaultProperties, getNormalizedDefaultTableProperties } 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 = {
|
|
@@ -35,7 +35,11 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
35
35
|
/**
|
|
36
36
|
* The default table properties.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
_defaultContentTableProperties;
|
|
39
|
+
/**
|
|
40
|
+
* The default layout table properties.
|
|
41
|
+
*/
|
|
42
|
+
_defaultLayoutTableProperties;
|
|
39
43
|
/**
|
|
40
44
|
* The contextual balloon plugin instance.
|
|
41
45
|
*/
|
|
@@ -44,6 +48,14 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
44
48
|
* The properties form view displayed inside the balloon.
|
|
45
49
|
*/
|
|
46
50
|
view = null;
|
|
51
|
+
/**
|
|
52
|
+
* The properties form view displayed inside the balloon (content table).
|
|
53
|
+
*/
|
|
54
|
+
_viewWithContentTableDefaults = null;
|
|
55
|
+
/**
|
|
56
|
+
* The properties form view displayed inside the balloon (layout table).
|
|
57
|
+
*/
|
|
58
|
+
_viewWithLayoutTableDefaults = null;
|
|
47
59
|
/**
|
|
48
60
|
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
49
61
|
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|
|
@@ -87,9 +99,10 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
87
99
|
*/
|
|
88
100
|
init() {
|
|
89
101
|
const editor = this.editor;
|
|
90
|
-
this.
|
|
102
|
+
this._defaultContentTableProperties = getNormalizedDefaultTableProperties(editor.config.get('table.tableProperties.defaultProperties'), {
|
|
91
103
|
includeAlignmentProperty: true
|
|
92
104
|
});
|
|
105
|
+
this._defaultLayoutTableProperties = getNormalizedDefaultProperties();
|
|
93
106
|
this._balloon = editor.plugins.get(ContextualBalloon);
|
|
94
107
|
editor.ui.componentFactory.add('tableProperties', () => this._createTablePropertiesButton());
|
|
95
108
|
}
|
|
@@ -129,7 +142,7 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
129
142
|
*
|
|
130
143
|
* @returns The table properties form view instance.
|
|
131
144
|
*/
|
|
132
|
-
_createPropertiesView() {
|
|
145
|
+
_createPropertiesView(defaultTableProperties) {
|
|
133
146
|
const editor = this.editor;
|
|
134
147
|
const config = editor.config.get('table.tableProperties');
|
|
135
148
|
const borderColorsConfig = normalizeColorOptions(config.borderColors);
|
|
@@ -140,7 +153,7 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
140
153
|
const view = new TablePropertiesView(editor.locale, {
|
|
141
154
|
borderColors: localizedBorderColors,
|
|
142
155
|
backgroundColors: localizedBackgroundColors,
|
|
143
|
-
defaultTableProperties
|
|
156
|
+
defaultTableProperties,
|
|
144
157
|
colorPickerConfig: hasColorPicker ? (config.colorPicker || {}) : false
|
|
145
158
|
});
|
|
146
159
|
const t = editor.t;
|
|
@@ -223,7 +236,9 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
223
236
|
Object.entries(propertyToCommandMap)
|
|
224
237
|
.map(([property, commandName]) => {
|
|
225
238
|
const propertyKey = property;
|
|
226
|
-
const defaultValue = this.
|
|
239
|
+
const defaultValue = this.view === this._viewWithContentTableDefaults ?
|
|
240
|
+
this._defaultContentTableProperties[propertyKey] || '' :
|
|
241
|
+
this._defaultLayoutTableProperties[propertyKey] || '';
|
|
227
242
|
return [propertyKey, (commands.get(commandName).value || defaultValue)];
|
|
228
243
|
})
|
|
229
244
|
.forEach(([property, value]) => {
|
|
@@ -244,9 +259,16 @@ export default class TablePropertiesUI extends Plugin {
|
|
|
244
259
|
*/
|
|
245
260
|
_showView() {
|
|
246
261
|
const editor = this.editor;
|
|
247
|
-
|
|
248
|
-
|
|
262
|
+
const viewTable = getSelectionAffectedTableWidget(editor.editing.view.document.selection);
|
|
263
|
+
const modelTable = viewTable && editor.editing.mapper.toModelElement(viewTable);
|
|
264
|
+
const useDefaults = !modelTable || modelTable.getAttribute('tableType') !== 'layout';
|
|
265
|
+
if (useDefaults && !this._viewWithContentTableDefaults) {
|
|
266
|
+
this._viewWithContentTableDefaults = this._createPropertiesView(this._defaultContentTableProperties);
|
|
267
|
+
}
|
|
268
|
+
else if (!useDefaults && !this._viewWithLayoutTableDefaults) {
|
|
269
|
+
this._viewWithLayoutTableDefaults = this._createPropertiesView(this._defaultLayoutTableProperties);
|
|
249
270
|
}
|
|
271
|
+
this.view = useDefaults ? this._viewWithContentTableDefaults : this._viewWithLayoutTableDefaults;
|
|
250
272
|
this.listenTo(editor.ui, 'update', () => {
|
|
251
273
|
this._updateView();
|
|
252
274
|
});
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { ButtonView, FocusCycler, LabeledFieldView, ToolbarView, View, ViewCollection, type DropdownView, type InputTextView, type NormalizedColorOption, type ColorPickerConfig, type FocusableView } from 'ckeditor5/src/ui.js';
|
|
9
9
|
import { FocusTracker, KeystrokeHandler, type Locale } from 'ckeditor5/src/utils.js';
|
|
10
|
+
import type ColorInputView from '../../ui/colorinputview.js';
|
|
11
|
+
import type { TablePropertiesOptions } from '../../tableconfig.js';
|
|
10
12
|
import '@ckeditor/ckeditor5-ui/theme/components/form/form.css';
|
|
11
13
|
import '../../../theme/formrow.css';
|
|
12
14
|
import '../../../theme/tableform.css';
|
|
13
15
|
import '../../../theme/tableproperties.css';
|
|
14
|
-
import type ColorInputView from '../../ui/colorinputview.js';
|
|
15
|
-
import type { TablePropertiesOptions } from '../../tableconfig.js';
|
|
16
16
|
/**
|
|
17
17
|
* Additional configuration of the view.
|
|
18
18
|
*/
|
|
@@ -80,18 +80,18 @@ export type NormalizeTableDefaultPropertiesOptions = {
|
|
|
80
80
|
* @param config The configuration to normalize.
|
|
81
81
|
* @param options Options used to determine which properties should be added.
|
|
82
82
|
*/
|
|
83
|
-
export declare function getNormalizedDefaultProperties(config
|
|
83
|
+
export declare function getNormalizedDefaultProperties(config?: Partial<NormalizedDefaultProperties>, options?: NormalizeTableDefaultPropertiesOptions): NormalizedDefaultProperties;
|
|
84
84
|
/**
|
|
85
85
|
* Returns the normalized default table properties.
|
|
86
86
|
*
|
|
87
87
|
* @param config The configuration to normalize.
|
|
88
88
|
* @param options Options used to determine which properties should be added.
|
|
89
89
|
*/
|
|
90
|
-
export declare function getNormalizedDefaultTableProperties(config
|
|
90
|
+
export declare function getNormalizedDefaultTableProperties(config?: Partial<NormalizedDefaultProperties>, options?: NormalizeTableDefaultPropertiesOptions): NormalizedDefaultProperties;
|
|
91
91
|
/**
|
|
92
92
|
* Returns the normalized default cell properties.
|
|
93
93
|
*
|
|
94
94
|
* @param config The configuration to normalize.
|
|
95
95
|
* @param options Options used to determine which properties should be added.
|
|
96
96
|
*/
|
|
97
|
-
export declare function getNormalizedDefaultCellProperties(config
|
|
97
|
+
export declare function getNormalizedDefaultCellProperties(config?: Partial<NormalizedDefaultProperties>, options?: NormalizeTableDefaultPropertiesOptions): NormalizedDefaultProperties;
|
|
@@ -146,7 +146,13 @@ export function fillToolbar(options) {
|
|
|
146
146
|
return buttonValue === valueToCompare;
|
|
147
147
|
});
|
|
148
148
|
button.on('execute', () => {
|
|
149
|
-
|
|
149
|
+
// Allow toggling alignment if there is no default value specified (especially for layout tables).
|
|
150
|
+
if (!defaultValue && buttonValue && view[propertyName] === buttonValue) {
|
|
151
|
+
view[propertyName] = undefined;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
view[propertyName] = buttonValue;
|
|
155
|
+
}
|
|
150
156
|
});
|
|
151
157
|
toolbar.items.add(button);
|
|
152
158
|
}
|