1 | /**
|
2 | * @license Copyright (c) 2003-2023, 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 | * @module table/tableproperties/commands/tableheightcommand
|
7 | */
|
8 | import TablePropertyCommand from './tablepropertycommand';
|
9 | import { addDefaultUnitToNumericValue } from '../../utils/table-properties';
|
10 | /**
|
11 | * The table height command.
|
12 | *
|
13 | * The command is registered by the {@link module:table/tableproperties/tablepropertiesediting~TablePropertiesEditing} as
|
14 | * the `'tableHeight'` editor command.
|
15 | *
|
16 | * To change the height of the selected table, execute the command:
|
17 | *
|
18 | * ```ts
|
19 | * editor.execute( 'tableHeight', {
|
20 | * value: '500px'
|
21 | * } );
|
22 | * ```
|
23 | *
|
24 | * **Note**: This command adds the default `'px'` unit to numeric values. Executing:
|
25 | *
|
26 | * ```ts
|
27 | * editor.execute( 'tableHeight', {
|
28 | * value: '50'
|
29 | * } );
|
30 | * ```
|
31 | *
|
32 | * will set the `height` attribute to `'50px'` in the model.
|
33 | */
|
34 | export default class TableHeightCommand extends TablePropertyCommand {
|
35 | /**
|
36 | * Creates a new `TableHeightCommand` instance.
|
37 | *
|
38 | * @param editor An editor in which this command will be used.
|
39 | * @param defaultValue The default value of the attribute.
|
40 | */
|
41 | constructor(editor, defaultValue) {
|
42 | super(editor, 'tableHeight', defaultValue);
|
43 | }
|
44 | /**
|
45 | * @inheritDoc
|
46 | */
|
47 | _getValueToSet(value) {
|
48 | value = addDefaultUnitToNumericValue(value, 'px');
|
49 | if (value === this._defaultValue) {
|
50 | return;
|
51 | }
|
52 | return value;
|
53 | }
|
54 | }
|