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/commands/mergecellcommand
|
7 | */
|
8 | import type { Node } from 'ckeditor5/src/engine';
|
9 | import { Command, type Editor } from 'ckeditor5/src/core';
|
10 | import type { ArrowKeyCodeDirection } from 'ckeditor5/src/utils';
|
11 | /**
|
12 | * The merge cell command.
|
13 | *
|
14 | * The command is registered by {@link module:table/tableediting~TableEditing} as the `'mergeTableCellRight'`, `'mergeTableCellLeft'`,
|
15 | * `'mergeTableCellUp'` and `'mergeTableCellDown'` editor commands.
|
16 | *
|
17 | * To merge a table cell at the current selection with another cell, execute the command corresponding with the preferred direction.
|
18 | *
|
19 | * For example, to merge with a cell to the right:
|
20 | *
|
21 | * ```ts
|
22 | * editor.execute( 'mergeTableCellRight' );
|
23 | * ```
|
24 | *
|
25 | * **Note**: If a table cell has a different [`rowspan`](https://www.w3.org/TR/html50/tabular-data.html#attr-tdth-rowspan)
|
26 | * (for `'mergeTableCellRight'` and `'mergeTableCellLeft'`) or [`colspan`](https://www.w3.org/TR/html50/tabular-data.html#attr-tdth-colspan)
|
27 | * (for `'mergeTableCellUp'` and `'mergeTableCellDown'`), the command will be disabled.
|
28 | */
|
29 | export default class MergeCellCommand extends Command {
|
30 | /**
|
31 | * The direction that indicates which cell will be merged with the currently selected one.
|
32 | */
|
33 | readonly direction: ArrowKeyCodeDirection;
|
34 | /**
|
35 | * Whether the merge is horizontal (left/right) or vertical (up/down).
|
36 | */
|
37 | readonly isHorizontal: boolean;
|
38 | /**
|
39 | * @inheritDoc
|
40 | */
|
41 | value: Node | undefined;
|
42 | /**
|
43 | * Creates a new `MergeCellCommand` instance.
|
44 | *
|
45 | * @param editor The editor on which this command will be used.
|
46 | * @param options.direction Indicates which cell to merge with the currently selected one.
|
47 | * Possible values are: `'left'`, `'right'`, `'up'` and `'down'`.
|
48 | */
|
49 | constructor(editor: Editor, options: {
|
50 | direction: ArrowKeyCodeDirection;
|
51 | });
|
52 | /**
|
53 | * @inheritDoc
|
54 | */
|
55 | refresh(): void;
|
56 | /**
|
57 | * Executes the command.
|
58 | *
|
59 | * Depending on the command's {`'left'`, `'right'`, `'up'` or `'down'`.
#direction} value, it will merge the cell that is to the |
60 | *
|
61 | * execute
|
62 | */
|
63 | execute(): void;
|
64 | /**
|
65 | * Returns a cell that can be merged with the current cell depending on the command's direction.
|
66 | */
|
67 | private _getMergeableCell;
|
68 | }
|