UNPKG

2.62 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/documentlistcommand
7 */
8import type { Element } from 'ckeditor5/src/engine';
9import { Command, type Editor } from 'ckeditor5/src/core';
10/**
11 * The list command. It is used by the {@link module:list/documentlist~DocumentList document list feature}.
12 */
13export default class DocumentListCommand extends Command {
14 /**
15 * The type of the list created by the command.
16 */
17 readonly type: 'numbered' | 'bulleted';
18 /**
19 * A flag indicating whether the command is active, which means that the selection starts in a list of the same type.
20 *
21 * @observable
22 * @readonly
23 */
24 value: boolean;
25 /**
26 * Creates an instance of the command.
27 *
28 * @param editor The editor instance.
29 * @param type List type that will be handled by this command.
30 */
31 constructor(editor: Editor, type: 'numbered' | 'bulleted');
32 /**
33 * @inheritDoc
34 */
35 refresh(): void;
36 /**
37 * Executes the list command.
38 *
39 * @fires execute
40 * @fires afterExecute
41 * @param options Command options.
42 * @param options.forceValue If set, it will force the command behavior. If `true`, the command will try to convert the
43 * selected items and potentially the neighbor elements to the proper list items. If set to `false` it will convert selected elements
44 * to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
45 */
46 execute(options?: {
47 forceValue?: boolean;
48 }): void;
49 /**
50 * Fires the `afterExecute` event.
51 *
52 * @param changedBlocks The changed list elements.
53 */
54 private _fireAfterExecute;
55 /**
56 * Checks the command's {@link #value}.
57 *
58 * @returns The current value.
59 */
60 private _getValue;
61 /**
62 * Checks whether the command can be enabled in the current context.
63 *
64 * @returns Whether the command should be enabled.
65 */
66 private _checkEnabled;
67}
68/**
69 * Event fired by the {@link ~DocumentListCommand#execute} method.
70 *
71 * It allows to execute an action after executing the {@link ~DocumentListCommand#execute} method,
72 * for example adjusting attributes of changed list items.
73 *
74 * @internal
75 * @eventName ~DocumentListCommand#afterExecute
76 */
77export type DocumentListCommandAfterExecuteEvent = {
78 name: 'afterExecute';
79 args: [changedBlocks: Array<Element>];
80};