UNPKG

1.57 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5import TableCellPropertyCommand from './tablecellpropertycommand.js';
6import { addDefaultUnitToNumericValue } from '../../utils/table-properties.js';
7/**
8 * The table cell height command.
9 *
10 * The command is registered by the {@link module:table/tablecellproperties/tablecellpropertiesediting~TableCellPropertiesEditing} as
11 * the `'tableCellHeight'` editor command.
12 *
13 * To change the height of selected cells, execute the command:
14 *
15 * ```ts
16 * editor.execute( 'tableCellHeight', {
17 * value: '50px'
18 * } );
19 * ```
20 *
21 * **Note**: This command adds the default `'px'` unit to numeric values. Executing:
22 *
23 * ```ts
24 * editor.execute( 'tableCellHeight', {
25 * value: '50'
26 * } );
27 * ```
28 *
29 * will set the `height` attribute to `'50px'` in the model.
30 */
31export default class TableCellHeightCommand extends TableCellPropertyCommand {
32 /**
33 * Creates a new `TableCellHeightCommand` instance.
34 *
35 * @param editor An editor in which this command will be used.
36 * @param defaultValue The default value of the attribute.
37 */
38 constructor(editor, defaultValue) {
39 super(editor, 'tableCellHeight', defaultValue);
40 }
41 /**
42 * @inheritDoc
43 */
44 _getValueToSet(value) {
45 const newValue = addDefaultUnitToNumericValue(value, 'px');
46 if (newValue === this._defaultValue) {
47 return;
48 }
49 return newValue;
50 }
51}