UNPKG

9.27 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/list/converters
7 */
8import { type DowncastAttributeEvent, type DowncastInsertEvent, type DowncastRemoveEvent, type Element, type MapperModelToViewPositionEvent, type MapperViewToModelPositionEvent, type Model, type ModelInsertContentEvent, type UpcastElementEvent, type View, type Writer } from 'ckeditor5/src/engine';
9import type { GetCallback } from 'ckeditor5/src/utils';
10/**
11 * A model-to-view converter for the `listItem` model element insertion.
12 *
13 * It creates a `<ul><li></li><ul>` (or `<ol>`) view structure out of a `listItem` model element, inserts it at the correct
14 * position, and merges the list with surrounding lists (if available).
15 *
16 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert
17 * @param model Model instance.
18 */
19export declare function modelViewInsertion(model: Model): GetCallback<DowncastInsertEvent<Element>>;
20/**
21 * A model-to-view converter for the `listItem` model element removal.
22 *
23 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:remove
24 * @param model Model instance.
25 * @returns Returns a conversion callback.
26 */
27export declare function modelViewRemove(model: Model): GetCallback<DowncastRemoveEvent>;
28/**
29 * A model-to-view converter for the `type` attribute change on the `listItem` model element.
30 *
31 * This change means that the `<li>` element parent changes from `<ul>` to `<ol>` (or vice versa). This is accomplished
32 * by breaking view elements and changing their name. The next {@link module:list/list/converters~modelViewMergeAfterChangeType}
33 * converter will attempt to merge split nodes.
34 *
35 * Splitting this conversion into 2 steps makes it possible to add an additional conversion in the middle.
36 * Check {@link module:list/todolist/todolistconverters~modelViewChangeType} to see an example of it.
37 *
38 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute
39 */
40export declare const modelViewChangeType: GetCallback<DowncastAttributeEvent<Element>>;
41/**
42 * A model-to-view converter that attempts to merge nodes split by {@link module:list/list/converters~modelViewChangeType}.
43 *
44 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute
45 */
46export declare const modelViewMergeAfterChangeType: GetCallback<DowncastAttributeEvent<Element>>;
47/**
48 * A model-to-view converter for the `listIndent` attribute change on the `listItem` model element.
49 *
50 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute
51 * @param model Model instance.
52 * @returns Returns a conversion callback.
53 */
54export declare function modelViewChangeIndent(model: Model): GetCallback<DowncastAttributeEvent<Element>>;
55/**
56 * A special model-to-view converter introduced by the {@link module:list/list~List list feature}. This converter is fired for
57 * insert change of every model item, and should be fired before the actual converter. The converter checks whether the inserted
58 * model item is a non-`listItem` element. If it is, and it is inserted inside a view list, the converter breaks the
59 * list so the model element is inserted to the view parent element corresponding to its model parent element.
60 *
61 * The converter prevents such situations:
62 *
63 * ```xml
64 * // Model: // View:
65 * <listItem>foo</listItem> <ul>
66 * <listItem>bar</listItem> <li>foo</li>
67 * <li>bar</li>
68 * </ul>
69 *
70 * // After change: // Correct view guaranteed by this converter:
71 * <listItem>foo</listItem> <ul><li>foo</li></ul><p>xxx</p><ul><li>bar</li></ul>
72 * <paragraph>xxx</paragraph> // Instead of this wrong view state:
73 * <listItem>bar</listItem> <ul><li>foo</li><p>xxx</p><li>bar</li></ul>
74 * ```
75 *
76 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert
77 */
78export declare const modelViewSplitOnInsert: GetCallback<DowncastInsertEvent<Element>>;
79/**
80 * A special model-to-view converter introduced by the {@link module:list/list~List list feature}. This converter takes care of
81 * merging view lists after something is removed or moved from near them.
82 *
83 * Example:
84 *
85 * ```xml
86 * // Model: // View:
87 * <listItem>foo</listItem> <ul><li>foo</li></ul>
88 * <paragraph>xxx</paragraph> <p>xxx</p>
89 * <listItem>bar</listItem> <ul><li>bar</li></ul>
90 *
91 * // After change: // Correct view guaranteed by this converter:
92 * <listItem>foo</listItem> <ul>
93 * <listItem>bar</listItem> <li>foo</li>
94 * <li>bar</li>
95 * </ul>
96 * ```
97 *
98 * @see module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:remove
99 */
100export declare const modelViewMergeAfter: GetCallback<DowncastRemoveEvent>;
101/**
102 * A view-to-model converter that converts the `<li>` view elements into the `listItem` model elements.
103 *
104 * To set correct values of the `listType` and `listIndent` attributes the converter:
105 * * checks `<li>`'s parent,
106 * * stores and increases the `conversionApi.store.indent` value when `<li>`'s sub-items are converted.
107 *
108 * @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
109 */
110export declare const viewModelConverter: GetCallback<UpcastElementEvent>;
111/**
112 * A view-to-model converter for the `<ul>` and `<ol>` view elements that cleans the input view of garbage.
113 * This is mostly to clean whitespaces from between the `<li>` view elements inside the view list element, however, also
114 * incorrect data can be cleared if the view was incorrect.
115 *
116 * @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
117 */
118export declare const cleanList: GetCallback<UpcastElementEvent>;
119/**
120 * A view-to-model converter for the `<li>` elements that cleans whitespace formatting from the input view.
121 *
122 * @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
123 */
124export declare const cleanListItem: GetCallback<UpcastElementEvent>;
125/**
126 * Returns a callback for model position to view position mapping for {@link module:engine/conversion/mapper~Mapper}. The callback fixes
127 * positions between the `listItem` elements that would be incorrectly mapped because of how list items are represented in the model
128 * and in the view.
129 */
130export declare function modelToViewPosition(view: View): GetCallback<MapperModelToViewPositionEvent>;
131/**
132 * The callback for view position to model position mapping for {@link module:engine/conversion/mapper~Mapper}. The callback fixes
133 * positions between the `<li>` elements that would be incorrectly mapped because of how list items are represented in the model
134 * and in the view.
135 *
136 * @see module:engine/conversion/mapper~Mapper#event:viewToModelPosition
137 * @param model Model instance.
138 * @returns Returns a conversion callback.
139 */
140export declare function viewToModelPosition(model: Model): GetCallback<MapperViewToModelPositionEvent>;
141/**
142 * Post-fixer that reacts to changes on document and fixes incorrect model states.
143 *
144 * In the example below, there is a correct list structure.
145 * Then the middle element is removed so the list structure will become incorrect:
146 *
147 * ```xml
148 * <listItem listType="bulleted" listIndent=0>Item 1</listItem>
149 * <listItem listType="bulleted" listIndent=1>Item 2</listItem> <--- this is removed.
150 * <listItem listType="bulleted" listIndent=2>Item 3</listItem>
151 * ```
152 *
153 * The list structure after the middle element is removed:
154 *
155 * ```xml
156 * <listItem listType="bulleted" listIndent=0>Item 1</listItem>
157 * <listItem listType="bulleted" listIndent=2>Item 3</listItem>
158 * ```
159 *
160 * Should become:
161 *
162 * ```xml
163 * <listItem listType="bulleted" listIndent=0>Item 1</listItem>
164 * <listItem listType="bulleted" listIndent=1>Item 3</listItem> <--- note that indent got post-fixed.
165 * ```
166 *
167 * @param model The data model.
168 * @param writer The writer to do changes with.
169 * @returns `true` if any change has been applied, `false` otherwise.
170 */
171export declare function modelChangePostFixer(model: Model, writer: Writer): boolean;
172/**
173 * A fixer for pasted content that includes list items.
174 *
175 * It fixes indentation of pasted list items so the pasted items match correctly to the context they are pasted into.
176 *
177 * Example:
178 *
179 * ```xml
180 * <listItem listType="bulleted" listIndent=0>A</listItem>
181 * <listItem listType="bulleted" listIndent=1>B^</listItem>
182 * // At ^ paste: <listItem listType="bulleted" listIndent=4>X</listItem>
183 * // <listItem listType="bulleted" listIndent=5>Y</listItem>
184 * <listItem listType="bulleted" listIndent=2>C</listItem>
185 * ```
186 *
187 * Should become:
188 *
189 * ```xml
190 * <listItem listType="bulleted" listIndent=0>A</listItem>
191 * <listItem listType="bulleted" listIndent=1>BX</listItem>
192 * <listItem listType="bulleted" listIndent=2>Y/listItem>
193 * <listItem listType="bulleted" listIndent=2>C</listItem>
194 * ```
195 */
196export declare const modelIndentPasteFixer: GetCallback<ModelInsertContentEvent>;