UNPKG

3.03 kBTypeScriptView Raw
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 list/documentlist/documentlistmergecommand
7 */
8import { Command, type Editor } from 'ckeditor5/src/core';
9import type { Element } from 'ckeditor5/src/engine';
10/**
11 * The document list merge command. It is used by the {@link module:list/documentlist~DocumentList list feature}.
12 */
13export default class DocumentListMergeCommand extends Command {
14 /**
15 * Whether list item should be merged before or after the selected block.
16 */
17 private readonly _direction;
18 /**
19 * Creates an instance of the command.
20 *
21 * @param editor The editor instance.
22 * @param direction Whether list item should be merged before or after the selected block.
23 */
24 constructor(editor: Editor, direction: 'forward' | 'backward');
25 /**
26 * @inheritDoc
27 */
28 refresh(): void;
29 /**
30 * Merges list blocks together (depending on the {@link #constructor}'s `direction` parameter).
31 *
32 * @fires execute
33 * @fires afterExecute
34 * @param options Command options.
35 * @param options.shouldMergeOnBlocksContentLevel When set `true`, merging will be performed together
36 * with {@link module:engine/model/model~Model#deleteContent} to get rid of the inline content in the selection or take advantage
37 * of the heuristics in `deleteContent()` that helps convert lists into paragraphs in certain cases.
38 */
39 execute({ shouldMergeOnBlocksContentLevel }?: {
40 shouldMergeOnBlocksContentLevel?: boolean;
41 }): void;
42 /**
43 * Fires the `afterExecute` event.
44 *
45 * @param changedBlocks The changed list elements.
46 */
47 private _fireAfterExecute;
48 /**
49 * Checks whether the command can be enabled in the current context.
50 *
51 * @returns Whether the command should be enabled.
52 */
53 private _checkEnabled;
54 /**
55 * Returns the boundary elements the merge should be executed for. These are not necessarily selection's first
56 * and last position parents but sometimes sibling or even further blocks depending on the context.
57 *
58 * @param selection The selection the merge is executed for.
59 * @param shouldMergeOnBlocksContentLevel When `true`, merge is performed together with
60 * {@link module:engine/model/model~Model#deleteContent} to remove the inline content within the selection.
61 */
62 private _getMergeSubjectElements;
63}
64/**
65 * Event fired by the {@link ~DocumentListMergeCommand#execute} method.
66 *
67 * It allows to execute an action after executing the {@link module:list/documentlist/documentlistcommand~DocumentListCommand#execute}
68 * method, for example adjusting attributes of changed list items.
69 *
70 * @internal
71 * @eventName ~DocumentListMergeCommand#afterExecute
72 */
73export type DocumentListMergeCommandAfterExecuteEvent = {
74 name: 'afterExecute';
75 args: [changedBlocks: Array<Element>];
76};