UNPKG

3.26 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, 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/list/listcommand
7 */
8import type { Element } from 'ckeditor5/src/engine.js';
9import { Command, type Editor } from 'ckeditor5/src/core.js';
10import { type ListType } from './listediting.js';
11/**
12 * The list command. It is used by the {@link module:list/list~List list feature}.
13 */
14export default class ListCommand extends Command {
15 /**
16 * The type of the list created by the command.
17 */
18 readonly type: ListType;
19 /**
20 * A flag indicating whether the command is active, which means that the selection starts in a list of the same type.
21 *
22 * @observable
23 * @readonly
24 */
25 value: boolean;
26 /**
27 * List Walker options that change the range of the list items to be changed when the selection is collapsed within a list item.
28 *
29 * In a multi-level list, when the selection is collapsed within a list item, instead of changing only the list items of the same list
30 * type and current indent level, the entire list structure is changed (all list items at all indent levels of any list type).
31 */
32 private readonly _listWalkerOptions?;
33 /**
34 * Creates an instance of the command.
35 *
36 * @param editor The editor instance.
37 * @param type List type that will be handled by this command.
38 */
39 constructor(editor: Editor, type: ListType, options?: {
40 multiLevel?: boolean;
41 });
42 /**
43 * @inheritDoc
44 */
45 refresh(): void;
46 /**
47 * Executes the list command.
48 *
49 * @fires execute
50 * @fires afterExecute
51 * @param options Command options.
52 * @param options.forceValue If set, it will force the command behavior. If `true`, the command will try to convert the
53 * selected items and potentially the neighbor elements to the proper list items. If set to `false` it will convert selected elements
54 * to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
55 * @param options.additionalAttributes Additional attributes that are set for list items when the command is executed.
56 */
57 execute(options?: {
58 forceValue?: boolean;
59 additionalAttributes?: Record<string, unknown>;
60 }): void;
61 /**
62 * Fires the `afterExecute` event.
63 *
64 * @param changedBlocks The changed list elements.
65 */
66 private _fireAfterExecute;
67 /**
68 * Checks the command's {@link #value}.
69 *
70 * @returns The current value.
71 */
72 private _getValue;
73 /**
74 * Checks whether the command can be enabled in the current context.
75 *
76 * @returns Whether the command should be enabled.
77 */
78 private _checkEnabled;
79}
80/**
81 * Event fired by the {@link ~ListCommand#execute} method.
82 *
83 * It allows to execute an action after executing the {@link ~ListCommand#execute} method,
84 * for example adjusting attributes of changed list items.
85 *
86 * @internal
87 * @eventName ~ListCommand#afterExecute
88 */
89export type ListCommandAfterExecuteEvent = {
90 name: 'afterExecute';
91 args: [changedBlocks: Array<Element>];
92};