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 | import TablePropertyCommand from './tablepropertycommand';
|
6 | import { addDefaultUnitToNumericValue, getSingleValue } from '../../utils/table-properties';
|
7 | /**
|
8 | * The table width border command.
|
9 | *
|
10 | * The command is registered by the {@link module:table/tableproperties/tablepropertiesediting~TablePropertiesEditing} as
|
11 | * the `'tableBorderWidth'` editor command.
|
12 | *
|
13 | * To change the border width of the selected table, execute the command:
|
14 | *
|
15 | * ```ts
|
16 | * editor.execute( 'tableBorderWidth', {
|
17 | * value: '5px'
|
18 | * } );
|
19 | * ```
|
20 | *
|
21 | * **Note**: This command adds the default `'px'` unit to numeric values. Executing:
|
22 | *
|
23 | * ```ts
|
24 | * editor.execute( 'tableBorderWidth', {
|
25 | * value: '5'
|
26 | * } );
|
27 | * ```
|
28 | *
|
29 | * will set the `borderWidth` attribute to `'5px'` in the model.
|
30 | */
|
31 | export default class TableBorderWidthCommand extends TablePropertyCommand {
|
32 | /**
|
33 | * Creates a new `TableBorderWidthCommand` 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, 'tableBorderWidth', defaultValue);
|
40 | }
|
41 | /**
|
42 | * @inheritDoc
|
43 | */
|
44 | _getValue(table) {
|
45 | if (!table) {
|
46 | return;
|
47 | }
|
48 | const value = getSingleValue(table.getAttribute(this.attributeName));
|
49 | if (value === this._defaultValue) {
|
50 | return;
|
51 | }
|
52 | return value;
|
53 | }
|
54 | /**
|
55 | * @inheritDoc
|
56 | */
|
57 | _getValueToSet(value) {
|
58 | const newValue = addDefaultUnitToNumericValue(value, 'px');
|
59 | if (newValue === this._defaultValue) {
|
60 | return;
|
61 | }
|
62 | return newValue;
|
63 | }
|
64 | }
|