1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
9 | import type { DowncastWriter, Element, ViewElement, ViewAttributeElement, Writer } from 'ckeditor5/src/engine.js';
|
10 | import { Delete } from 'ckeditor5/src/typing.js';
|
11 | import { Enter } from 'ckeditor5/src/enter.js';
|
12 | import ListUtils from './listutils.js';
|
13 | import { ListBlocksIterable } from './utils/listwalker.js';
|
14 | import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
|
15 | import '../../theme/documentlist.css';
|
16 | import '../../theme/list.css';
|
17 | export type ListType = 'numbered' | 'bulleted' | 'todo' | 'customNumbered' | 'customBulleted';
|
18 |
|
19 |
|
20 |
|
21 | export interface ListItemAttributesMap {
|
22 | listType?: ListType;
|
23 | listIndent?: number;
|
24 | listItemId?: string;
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | export default class ListEditing extends Plugin {
|
30 | |
31 |
|
32 |
|
33 | private readonly _downcastStrategies;
|
34 | |
35 |
|
36 |
|
37 | static get pluginName(): "ListEditing";
|
38 | |
39 |
|
40 |
|
41 | static get requires(): readonly [typeof Enter, typeof Delete, typeof ListUtils, typeof ClipboardPipeline];
|
42 | |
43 |
|
44 |
|
45 | constructor(editor: Editor);
|
46 | /**
|
47 | * @inheritDoc
|
48 | */
|
49 | init(): void;
|
50 | /**
|
51 | * @inheritDoc
|
52 | */
|
53 | afterInit(): void;
|
54 | /**
|
55 | * Registers a downcast strategy.
|
56 | *
|
57 | * **Note**: Strategies must be registered in the `Plugin#init()` phase so that it can be applied
|
58 | * in the `ListEditing#afterInit()`.
|
59 | *
|
60 | * @param strategy The downcast strategy to register.
|
61 | */
|
62 | registerDowncastStrategy(strategy: DowncastStrategy): void;
|
63 | /**
|
64 | * Returns list of model attribute names that should affect downcast conversion.
|
65 | */
|
66 | getListAttributeNames(): Array<string>;
|
67 | /**
|
68 | * Attaches the listener to the {@link module:engine/view/document~Document#event:delete} event and handles backspace/delete
|
69 | * keys in and around document lists.
|
70 | */
|
71 | private _setupDeleteIntegration;
|
72 | /**
|
73 | * Attaches a listener to the {@link module:engine/view/document~Document#event:enter} event and handles enter key press
|
74 | * in document lists.
|
75 | */
|
76 | private _setupEnterIntegration;
|
77 | /**
|
78 | * Attaches a listener to the {@link module:engine/view/document~Document#event:tab} event and handles tab key and tab+shift keys
|
79 | * presses in document lists.
|
80 | */
|
81 | private _setupTabIntegration;
|
82 | /**
|
83 | * Registers the conversion helpers for the document-list feature.
|
84 | */
|
85 | private _setupConversion;
|
86 | /**
|
87 | * Registers model post-fixers.
|
88 | */
|
89 | private _setupModelPostFixing;
|
90 | /**
|
91 | * Integrates the feature with the clipboard via {@link module:engine/model/model~Model#insertContent} and
|
92 | * {@link module:engine/model/model~Model#getSelectedContent}.
|
93 | */
|
94 | private _setupClipboardIntegration;
|
95 | /**
|
96 | * Informs editor accessibility features about keystrokes brought by the plugin.
|
97 | */
|
98 | private _setupAccessibilityIntegration;
|
99 | }
|
100 | /**
|
101 | * The attribute to attribute downcast strategy for UL, OL, LI elements.
|
102 | */
|
103 | export interface AttributeDowncastStrategy {
|
104 | |
105 |
|
106 |
|
107 | scope: 'list' | 'item';
|
108 | |
109 |
|
110 |
|
111 | attributeName: string;
|
112 | |
113 |
|
114 |
|
115 | setAttributeOnDowncast(writer: DowncastWriter, value: unknown, element: ViewElement): void;
|
116 | }
|
117 |
|
118 |
|
119 |
|
120 | export interface ItemMarkerDowncastStrategy {
|
121 | |
122 |
|
123 |
|
124 | scope: 'itemMarker';
|
125 | |
126 |
|
127 |
|
128 | attributeName: string;
|
129 | |
130 |
|
131 |
|
132 | createElement(writer: DowncastWriter, modelElement: Element, { dataPipeline }: {
|
133 | dataPipeline?: boolean;
|
134 | }): ViewElement | null;
|
135 | |
136 |
|
137 |
|
138 | createWrapperElement?(writer: DowncastWriter, modelElement: Element, { dataPipeline }: {
|
139 | dataPipeline?: boolean;
|
140 | }): ViewAttributeElement;
|
141 | |
142 |
|
143 |
|
144 |
|
145 | canWrapElement?(modelElement: Element): boolean;
|
146 | |
147 |
|
148 |
|
149 |
|
150 | canInjectMarkerIntoElement?(modelElement: Element): boolean;
|
151 | }
|
152 |
|
153 |
|
154 |
|
155 | export type DowncastStrategy = AttributeDowncastStrategy | ItemMarkerDowncastStrategy;
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | export type ListEditingPostFixerEvent = {
|
170 | name: 'postFixer';
|
171 | args: [
|
172 | {
|
173 | listNodes: ListBlocksIterable;
|
174 | listHead: Element;
|
175 | writer: Writer;
|
176 | seenIds: Set<string>;
|
177 | }
|
178 | ];
|
179 | return: boolean;
|
180 | };
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | export type ListEditingCheckAttributesEvent = {
|
193 | name: 'checkAttributes' | 'checkAttributes:list' | 'checkAttributes:item';
|
194 | args: [
|
195 | {
|
196 | viewElement: ViewElement & {
|
197 | id?: string;
|
198 | };
|
199 | modelAttributes: ListItemAttributesMap;
|
200 | }
|
201 | ];
|
202 | return: boolean;
|
203 | };
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 | export type ListEditingCheckElementEvent = {
|
214 | name: 'checkElement';
|
215 | args: [
|
216 | {
|
217 | viewElement: ViewElement;
|
218 | modelElement: Element;
|
219 | }
|
220 | ];
|
221 | return: boolean;
|
222 | };
|