@ckeditor/ckeditor5-list 47.6.1-alpha.1 → 48.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/ckeditor5-metadata.json +21 -18
- package/dist/index-content.css +135 -111
- package/dist/index-editor.css +152 -73
- package/dist/index.css +204 -238
- package/dist/index.css.map +1 -1
- package/dist/index.js.map +1 -1
- package/{src → dist}/legacylist/legacyconverters.d.ts +2 -2
- package/{src → dist}/legacylist/legacyindentcommand.d.ts +1 -1
- package/{src → dist}/legacylist/legacylistcommand.d.ts +1 -1
- package/{src → dist}/legacylist/legacylistediting.d.ts +3 -3
- package/{src → dist}/legacylist/legacylistutils.d.ts +2 -2
- package/{src → dist}/legacylist/legacyutils.d.ts +1 -1
- package/{src → dist}/legacylist.d.ts +1 -1
- package/{src → dist}/legacylistproperties/legacylistpropertiesediting.d.ts +1 -1
- package/{src → dist}/legacylistproperties/legacylistreversedcommand.d.ts +1 -1
- package/{src → dist}/legacylistproperties/legacyliststartcommand.d.ts +1 -1
- package/{src → dist}/legacylistproperties/legacyliststylecommand.d.ts +1 -1
- package/{src → dist}/legacylistproperties.d.ts +1 -1
- package/{src → dist}/legacytodolist/legacychecktodolistcommand.d.ts +2 -2
- package/{src → dist}/legacytodolist/legacytodolistconverters.d.ts +2 -2
- package/{src → dist}/legacytodolist/legacytodolistediting.d.ts +1 -1
- package/{src → dist}/legacytodolist.d.ts +1 -1
- package/{src → dist}/list/adjacentlistssupport.d.ts +1 -1
- package/{src → dist}/list/converters.d.ts +2 -2
- package/{src → dist}/list/listcommand.d.ts +2 -2
- package/{src → dist}/list/listediting.d.ts +5 -5
- package/{src → dist}/list/listindentcommand.d.ts +2 -2
- package/{src → dist}/list/listmergecommand.d.ts +2 -2
- package/{src → dist}/list/listsplitcommand.d.ts +2 -2
- package/{src → dist}/list/listui.d.ts +1 -1
- package/{src → dist}/list/listutils.d.ts +3 -3
- package/{src → dist}/list/utils/listwalker.d.ts +2 -2
- package/{src → dist}/list/utils/model.d.ts +2 -2
- package/{src → dist}/list/utils/postfixers.d.ts +1 -1
- package/{src → dist}/list/utils/view.d.ts +1 -1
- package/{src → dist}/list/utils.d.ts +1 -1
- package/{src → dist}/list.d.ts +1 -1
- package/{src → dist}/listconfig.d.ts +1 -1
- package/{src → dist}/listformatting/listitemboldintegration.d.ts +1 -1
- package/{src → dist}/listformatting/listitemfontcolorintegration.d.ts +1 -1
- package/{src → dist}/listformatting/listitemfontfamilyintegration.d.ts +1 -1
- package/{src → dist}/listformatting/listitemfontsizeintegration.d.ts +1 -1
- package/{src → dist}/listformatting/listitemitalicintegration.d.ts +1 -1
- package/{src → dist}/listformatting.d.ts +1 -1
- package/{src → dist}/listproperties/converters.d.ts +2 -2
- package/{src → dist}/listproperties/listpropertiesediting.d.ts +2 -2
- package/{src → dist}/listproperties/listpropertiesui.d.ts +1 -1
- package/{src → dist}/listproperties/listpropertiesutils.d.ts +1 -1
- package/{src → dist}/listproperties/listreversedcommand.d.ts +1 -1
- package/{src → dist}/listproperties/liststartcommand.d.ts +1 -1
- package/{src → dist}/listproperties/liststylecommand.d.ts +1 -1
- package/{src → dist}/listproperties/ui/listpropertiesview.d.ts +2 -2
- package/{src → dist}/listproperties.d.ts +1 -1
- package/{src → dist}/todolist/checktodolistcommand.d.ts +1 -1
- package/{src → dist}/todolist/todocheckboxchangeobserver.d.ts +1 -1
- package/{src → dist}/todolist/todolistediting.d.ts +1 -1
- package/{src → dist}/todolist/todolistui.d.ts +1 -1
- package/{src → dist}/todolist.d.ts +1 -1
- package/package.json +28 -52
- package/build/list.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/lang/contexts.json +0 -37
- package/lang/translations/af.po +0 -152
- package/lang/translations/ar.po +0 -152
- package/lang/translations/ast.po +0 -152
- package/lang/translations/az.po +0 -152
- package/lang/translations/be.po +0 -152
- package/lang/translations/bg.po +0 -152
- package/lang/translations/bn.po +0 -152
- package/lang/translations/bs.po +0 -152
- package/lang/translations/ca.po +0 -152
- package/lang/translations/cs.po +0 -152
- package/lang/translations/da.po +0 -152
- package/lang/translations/de-ch.po +0 -152
- package/lang/translations/de.po +0 -152
- package/lang/translations/el.po +0 -152
- package/lang/translations/en-au.po +0 -152
- package/lang/translations/en-gb.po +0 -152
- package/lang/translations/en.po +0 -152
- package/lang/translations/eo.po +0 -152
- package/lang/translations/es-co.po +0 -152
- package/lang/translations/es.po +0 -152
- package/lang/translations/et.po +0 -152
- package/lang/translations/eu.po +0 -152
- package/lang/translations/fa.po +0 -152
- package/lang/translations/fi.po +0 -152
- package/lang/translations/fr.po +0 -152
- package/lang/translations/gl.po +0 -152
- package/lang/translations/gu.po +0 -152
- package/lang/translations/he.po +0 -152
- package/lang/translations/hi.po +0 -152
- package/lang/translations/hr.po +0 -152
- package/lang/translations/hu.po +0 -152
- package/lang/translations/hy.po +0 -152
- package/lang/translations/id.po +0 -152
- package/lang/translations/it.po +0 -152
- package/lang/translations/ja.po +0 -152
- package/lang/translations/jv.po +0 -152
- package/lang/translations/kk.po +0 -152
- package/lang/translations/km.po +0 -152
- package/lang/translations/kn.po +0 -152
- package/lang/translations/ko.po +0 -152
- package/lang/translations/ku.po +0 -152
- package/lang/translations/lt.po +0 -152
- package/lang/translations/lv.po +0 -152
- package/lang/translations/ms.po +0 -152
- package/lang/translations/nb.po +0 -152
- package/lang/translations/ne.po +0 -152
- package/lang/translations/nl.po +0 -152
- package/lang/translations/no.po +0 -152
- package/lang/translations/oc.po +0 -152
- package/lang/translations/pl.po +0 -152
- package/lang/translations/pt-br.po +0 -152
- package/lang/translations/pt.po +0 -152
- package/lang/translations/ro.po +0 -152
- package/lang/translations/ru.po +0 -152
- package/lang/translations/si.po +0 -152
- package/lang/translations/sk.po +0 -152
- package/lang/translations/sl.po +0 -152
- package/lang/translations/sq.po +0 -152
- package/lang/translations/sr-latn.po +0 -152
- package/lang/translations/sr.po +0 -152
- package/lang/translations/sv.po +0 -152
- package/lang/translations/th.po +0 -152
- package/lang/translations/ti.po +0 -152
- package/lang/translations/tk.po +0 -152
- package/lang/translations/tr.po +0 -152
- package/lang/translations/tt.po +0 -152
- package/lang/translations/ug.po +0 -152
- package/lang/translations/uk.po +0 -152
- package/lang/translations/ur.po +0 -152
- package/lang/translations/uz.po +0 -152
- package/lang/translations/vi.po +0 -152
- package/lang/translations/zh-cn.po +0 -152
- package/lang/translations/zh.po +0 -152
- package/src/augmentation.js +0 -5
- package/src/index.js +0 -67
- package/src/legacyerrors.js +0 -28
- package/src/legacylist/legacyconverters.js +0 -921
- package/src/legacylist/legacyindentcommand.js +0 -111
- package/src/legacylist/legacylistcommand.js +0 -278
- package/src/legacylist/legacylistediting.js +0 -167
- package/src/legacylist/legacylistutils.js +0 -52
- package/src/legacylist/legacyutils.js +0 -357
- package/src/legacylist.js +0 -36
- package/src/legacylistproperties/legacylistpropertiesediting.js +0 -703
- package/src/legacylistproperties/legacylistreversedcommand.js +0 -52
- package/src/legacylistproperties/legacyliststartcommand.js +0 -52
- package/src/legacylistproperties/legacyliststylecommand.js +0 -105
- package/src/legacylistproperties.js +0 -37
- package/src/legacytodolist/legacychecktodolistcommand.js +0 -82
- package/src/legacytodolist/legacytodolistconverters.js +0 -268
- package/src/legacytodolist/legacytodolistediting.js +0 -199
- package/src/legacytodolist.js +0 -37
- package/src/list/adjacentlistssupport.js +0 -87
- package/src/list/converters.js +0 -533
- package/src/list/listcommand.js +0 -176
- package/src/list/listediting.js +0 -696
- package/src/list/listindentcommand.js +0 -136
- package/src/list/listmergecommand.js +0 -182
- package/src/list/listsplitcommand.js +0 -74
- package/src/list/listui.js +0 -42
- package/src/list/listutils.js +0 -68
- package/src/list/utils/listwalker.js +0 -236
- package/src/list/utils/model.js +0 -487
- package/src/list/utils/postfixers.js +0 -131
- package/src/list/utils/view.js +0 -117
- package/src/list/utils.js +0 -51
- package/src/list.js +0 -36
- package/src/listconfig.js +0 -5
- package/src/listformatting/listitemboldintegration.js +0 -88
- package/src/listformatting/listitemfontcolorintegration.js +0 -92
- package/src/listformatting/listitemfontfamilyintegration.js +0 -93
- package/src/listformatting/listitemfontsizeintegration.js +0 -124
- package/src/listformatting/listitemitalicintegration.js +0 -88
- package/src/listformatting.js +0 -248
- package/src/listproperties/converters.js +0 -43
- package/src/listproperties/listpropertiesediting.js +0 -291
- package/src/listproperties/listpropertiesui.js +0 -385
- package/src/listproperties/listpropertiesutils.js +0 -50
- package/src/listproperties/listreversedcommand.js +0 -55
- package/src/listproperties/liststartcommand.js +0 -61
- package/src/listproperties/liststylecommand.js +0 -121
- package/src/listproperties/ui/listpropertiesview.js +0 -318
- package/src/listproperties/utils/config.js +0 -84
- package/src/listproperties/utils/style.js +0 -85
- package/src/listproperties.js +0 -37
- package/src/todolist/checktodolistcommand.js +0 -82
- package/src/todolist/todocheckboxchangeobserver.js +0 -36
- package/src/todolist/todolistediting.js +0 -470
- package/src/todolist/todolistui.js +0 -35
- package/src/todolist.js +0 -37
- package/theme/documentlist.css +0 -8
- package/theme/list.css +0 -40
- package/theme/listformatting.css +0 -66
- package/theme/listproperties.css +0 -10
- package/theme/liststyles.css +0 -8
- package/theme/todolist.css +0 -140
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/listproperties/utils/config.d.ts +0 -0
- /package/{src → dist}/listproperties/utils/style.d.ts +0 -0
package/src/list/converters.js
DELETED
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { getAllListItemBlocks, getListItemBlocks, isListItemBlock, isFirstBlockOfListItem, ListItemUid } from './utils/model.js';
|
|
6
|
-
import { createListElement, createListItemElement, getIndent, isListView, isListItemView } from './utils/view.js';
|
|
7
|
-
import { ListWalker, SiblingListBlocksIterator } from './utils/listwalker.js';
|
|
8
|
-
import { findAndAddListHeadToMap } from './utils/postfixers.js';
|
|
9
|
-
/**
|
|
10
|
-
* Returns the upcast converter for list items. It's supposed to work after the block converters (content inside list items) are converted.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export function listItemUpcastConverter() {
|
|
15
|
-
return (evt, data, conversionApi) => {
|
|
16
|
-
const { writer, schema } = conversionApi;
|
|
17
|
-
if (!data.modelRange) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const items = Array.from(data.modelRange.getItems({ shallow: true }))
|
|
21
|
-
.filter((item) => schema.checkAttribute(item, 'listItemId'));
|
|
22
|
-
if (!items.length) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const listItemId = data.viewItem.getAttribute('data-list-item-id') || ListItemUid.next();
|
|
26
|
-
conversionApi.consumable.consume(data.viewItem, { attributes: 'data-list-item-id' });
|
|
27
|
-
const listIndent = getIndent(data.viewItem);
|
|
28
|
-
let listType = data.viewItem.parent && data.viewItem.parent.is('element', 'ol') ? 'numbered' : 'bulleted';
|
|
29
|
-
// Preserve list type if was already set (for example by to-do list feature).
|
|
30
|
-
const firstItemListType = items[0].getAttribute('listType');
|
|
31
|
-
if (firstItemListType) {
|
|
32
|
-
listType = firstItemListType;
|
|
33
|
-
}
|
|
34
|
-
const attributes = {
|
|
35
|
-
listItemId,
|
|
36
|
-
listIndent,
|
|
37
|
-
listType
|
|
38
|
-
};
|
|
39
|
-
for (const item of items) {
|
|
40
|
-
// Set list attributes only on same level items, those nested deeper are already handled by the recursive conversion.
|
|
41
|
-
if (!item.hasAttribute('listItemId')) {
|
|
42
|
-
writer.setAttributes(attributes, item);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (items.length > 1) {
|
|
46
|
-
// Make sure that list item that contain only nested list will preserve paragraph for itself:
|
|
47
|
-
// <ul>
|
|
48
|
-
// <li>
|
|
49
|
-
// <p></p> <-- this one must be kept
|
|
50
|
-
// <ul>
|
|
51
|
-
// <li></li>
|
|
52
|
-
// </ul>
|
|
53
|
-
// </li>
|
|
54
|
-
// </ul>
|
|
55
|
-
if (items[1].getAttribute('listItemId') != attributes.listItemId) {
|
|
56
|
-
conversionApi.keepEmptyElement(items[0]);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Returns a model document change:data event listener that triggers conversion of related items if needed.
|
|
63
|
-
*
|
|
64
|
-
* @internal
|
|
65
|
-
* @param model The editor model.
|
|
66
|
-
* @param editing The editing controller.
|
|
67
|
-
* @param attributeNames The list of all model list attributes (including registered strategies).
|
|
68
|
-
* @param listEditing The document list editing plugin.
|
|
69
|
-
*/
|
|
70
|
-
export function reconvertItemsOnDataChange(model, editing, attributeNames, listEditing) {
|
|
71
|
-
return () => {
|
|
72
|
-
const changes = model.document.differ.getChanges();
|
|
73
|
-
const itemsToRefresh = [];
|
|
74
|
-
const itemToListHead = new Set();
|
|
75
|
-
const changedItems = new Set();
|
|
76
|
-
const visited = new Set();
|
|
77
|
-
for (const entry of changes) {
|
|
78
|
-
if (entry.type == 'insert' && entry.name != '$text') {
|
|
79
|
-
findAndAddListHeadToMap(entry.position, itemToListHead, visited);
|
|
80
|
-
// Insert of a non-list item.
|
|
81
|
-
if (!entry.attributes.has('listItemId')) {
|
|
82
|
-
findAndAddListHeadToMap(entry.position.getShiftedBy(entry.length), itemToListHead, visited);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
changedItems.add(entry.position.nodeAfter);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// Removed list item.
|
|
89
|
-
else if (entry.type == 'remove' && entry.attributes.has('listItemId')) {
|
|
90
|
-
findAndAddListHeadToMap(entry.position, itemToListHead, visited);
|
|
91
|
-
}
|
|
92
|
-
// Changed list attribute.
|
|
93
|
-
else if (entry.type == 'attribute') {
|
|
94
|
-
const item = entry.range.start.nodeAfter;
|
|
95
|
-
if (attributeNames.includes(entry.attributeKey)) {
|
|
96
|
-
findAndAddListHeadToMap(entry.range.start, itemToListHead, visited);
|
|
97
|
-
if (entry.attributeNewValue === null) {
|
|
98
|
-
findAndAddListHeadToMap(entry.range.start.getShiftedBy(1), itemToListHead, visited);
|
|
99
|
-
// Check if paragraph should be converted from bogus to plain paragraph.
|
|
100
|
-
if (doesItemBlockRequiresRefresh(item)) {
|
|
101
|
-
itemsToRefresh.push(item);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
changedItems.add(item);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if (isListItemBlock(item)) {
|
|
109
|
-
// Some other attribute was changed on the list item,
|
|
110
|
-
// check if paragraph does not need to be converted to bogus or back.
|
|
111
|
-
if (doesItemBlockRequiresRefresh(item)) {
|
|
112
|
-
itemsToRefresh.push(item);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
for (const listHead of itemToListHead.values()) {
|
|
118
|
-
itemsToRefresh.push(...collectListItemsToRefresh(listHead, changedItems));
|
|
119
|
-
}
|
|
120
|
-
for (const item of new Set(itemsToRefresh)) {
|
|
121
|
-
editing.reconvertItem(item);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
function collectListItemsToRefresh(listHead, changedItems) {
|
|
125
|
-
const itemsToRefresh = [];
|
|
126
|
-
const visited = new Set();
|
|
127
|
-
const stack = [];
|
|
128
|
-
for (const { node, previous } of new SiblingListBlocksIterator(listHead)) {
|
|
129
|
-
if (visited.has(node)) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
const itemIndent = node.getAttribute('listIndent');
|
|
133
|
-
// Current node is at the lower indent so trim the stack.
|
|
134
|
-
if (previous && itemIndent < previous.getAttribute('listIndent')) {
|
|
135
|
-
stack.length = itemIndent + 1;
|
|
136
|
-
}
|
|
137
|
-
// Update the stack for the current indent level.
|
|
138
|
-
stack[itemIndent] = {
|
|
139
|
-
modelAttributes: Object.fromEntries(Array.from(node.getAttributes())
|
|
140
|
-
.filter(([key]) => attributeNames.includes(key))),
|
|
141
|
-
modelElement: node
|
|
142
|
-
};
|
|
143
|
-
// Find all blocks of the current node.
|
|
144
|
-
const blocks = getListItemBlocks(node, { direction: 'forward' });
|
|
145
|
-
for (const block of blocks) {
|
|
146
|
-
visited.add(block);
|
|
147
|
-
// Check if bogus vs plain paragraph needs refresh.
|
|
148
|
-
if (doesItemBlockRequiresRefresh(block, blocks)) {
|
|
149
|
-
itemsToRefresh.push(block);
|
|
150
|
-
}
|
|
151
|
-
// Check if wrapping with UL, OL, LIs needs refresh.
|
|
152
|
-
else if (doesItemWrappingRequiresRefresh(block, stack, changedItems)) {
|
|
153
|
-
itemsToRefresh.push(block);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return itemsToRefresh;
|
|
158
|
-
}
|
|
159
|
-
function doesItemBlockRequiresRefresh(item, blocks) {
|
|
160
|
-
const viewElement = editing.mapper.toViewElement(item);
|
|
161
|
-
if (!viewElement) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
if (isItemBlockInsideStructureSlot(viewElement)) {
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
const needsRefresh = listEditing.fire('checkElement', {
|
|
168
|
-
modelElement: item,
|
|
169
|
-
viewElement
|
|
170
|
-
});
|
|
171
|
-
if (needsRefresh) {
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
if (!item.is('element', 'paragraph') && !item.is('element', 'listItem')) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
const useBogus = shouldUseBogusParagraph(item, attributeNames, blocks);
|
|
178
|
-
if (useBogus && viewElement.is('element', 'p')) {
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
else if (!useBogus && viewElement.is('element', 'span')) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
function isItemBlockInsideStructureSlot(viewElement) {
|
|
187
|
-
viewElement = viewElement.parent;
|
|
188
|
-
while (viewElement.is('attributeElement') && ['ol', 'ul', 'li'].includes(viewElement.name)) {
|
|
189
|
-
viewElement = viewElement.parent;
|
|
190
|
-
}
|
|
191
|
-
// List item inside elementToStructure slot parent without mapping then it requires refresh for correct positions
|
|
192
|
-
// as structure child elements does not have mapping from model and position would land in wrong place.
|
|
193
|
-
if (viewElement.getCustomProperty('$structureSlotParent') &&
|
|
194
|
-
!editing.mapper.toModelElement(viewElement)) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
function doesItemWrappingRequiresRefresh(item, stack, changedItems) {
|
|
200
|
-
// Items directly affected by some "change" don't need a refresh, they will be converted by their own changes.
|
|
201
|
-
if (changedItems.has(item)) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
const viewElement = editing.mapper.toViewElement(item);
|
|
205
|
-
let indent = stack.length - 1;
|
|
206
|
-
// Traverse down the stack to the root to verify if all ULs, OLs, and LIs are as expected.
|
|
207
|
-
for (let element = viewElement.parent; !element.is('editableElement'); element = element.parent) {
|
|
208
|
-
const isListItemElement = isListItemView(element);
|
|
209
|
-
const isListElement = isListView(element);
|
|
210
|
-
if (!isListElement && !isListItemElement) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
const eventName = `checkAttributes:${isListItemElement ? 'item' : 'list'}`;
|
|
214
|
-
const needsRefresh = listEditing.fire(eventName, {
|
|
215
|
-
viewElement: element,
|
|
216
|
-
modelAttributes: stack[indent].modelAttributes,
|
|
217
|
-
modelReferenceElement: stack[indent].modelElement
|
|
218
|
-
});
|
|
219
|
-
if (needsRefresh) {
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
if (isListElement) {
|
|
223
|
-
indent--;
|
|
224
|
-
// Don't need to iterate further if we already know that the item is wrapped appropriately.
|
|
225
|
-
if (indent < 0) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Returns the list item downcast converter.
|
|
235
|
-
*
|
|
236
|
-
* @internal
|
|
237
|
-
* @param attributeNames A list of attribute names that should be converted if they are set.
|
|
238
|
-
* @param strategies The strategies.
|
|
239
|
-
* @param model The model.
|
|
240
|
-
*/
|
|
241
|
-
export function listItemDowncastConverter(attributeNames, strategies, model, { dataPipeline } = {}) {
|
|
242
|
-
const consumer = createAttributesConsumer(attributeNames, strategies);
|
|
243
|
-
return (evt, data, conversionApi) => {
|
|
244
|
-
const { writer, mapper, consumable } = conversionApi;
|
|
245
|
-
const listItem = data.item;
|
|
246
|
-
if (!attributeNames.includes(data.attributeKey)) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
// Test if attributes on the converted items are not consumed.
|
|
250
|
-
if (!consumer(listItem, consumable)) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const options = {
|
|
254
|
-
...conversionApi.options,
|
|
255
|
-
dataPipeline
|
|
256
|
-
};
|
|
257
|
-
// Use positions mapping instead of mapper.toViewElement( listItem ) to find outermost view element.
|
|
258
|
-
// This is for cases when mapping is using inner view element like in the code blocks (pre > code).
|
|
259
|
-
const viewElement = findMappedViewElement(listItem, mapper, model, writer);
|
|
260
|
-
// Remove custom item marker.
|
|
261
|
-
removeCustomMarkerElements(viewElement, writer, mapper);
|
|
262
|
-
// Unwrap element from current list wrappers.
|
|
263
|
-
unwrapListItemBlock(viewElement, writer);
|
|
264
|
-
// Insert custom item marker.
|
|
265
|
-
const viewRange = insertCustomMarkerElements(listItem, viewElement, strategies, writer, options);
|
|
266
|
-
// Then wrap them with the new list wrappers (UL, OL, LI).
|
|
267
|
-
wrapListItemBlock(listItem, viewRange, strategies, writer, options);
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* The 'remove' downcast converter for custom markers.
|
|
272
|
-
*
|
|
273
|
-
* @internal
|
|
274
|
-
*/
|
|
275
|
-
export function listItemDowncastRemoveConverter(schema) {
|
|
276
|
-
return (evt, data, conversionApi) => {
|
|
277
|
-
const { writer, mapper } = conversionApi;
|
|
278
|
-
const elementName = evt.name.split(':')[1];
|
|
279
|
-
// Do not remove marker if the deleted element is some inline object inside paragraph.
|
|
280
|
-
// See https://github.com/ckeditor/ckeditor5-internal/issues/3680.
|
|
281
|
-
if (!schema.checkAttribute(elementName, 'listItemId')) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
// Find the view range start position by mapping the model position at which the remove happened.
|
|
285
|
-
const viewStart = mapper.toViewPosition(data.position);
|
|
286
|
-
const modelEnd = data.position.getShiftedBy(data.length);
|
|
287
|
-
const viewEnd = mapper.toViewPosition(modelEnd, { isPhantom: true });
|
|
288
|
-
// Trim the range to remove in case some UI elements are on the view range boundaries.
|
|
289
|
-
const viewRange = writer.createRange(viewStart, viewEnd).getTrimmed();
|
|
290
|
-
// Use positions mapping instead of mapper.toViewElement( listItem ) to find outermost view element.
|
|
291
|
-
// This is for cases when mapping is using inner view element like in the code blocks (pre > code).
|
|
292
|
-
const viewElement = viewRange.end.nodeBefore;
|
|
293
|
-
/* istanbul ignore next -- @preserve */
|
|
294
|
-
if (!viewElement) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
// Remove custom item marker.
|
|
298
|
-
removeCustomMarkerElements(viewElement, writer, mapper);
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Returns the bogus paragraph view element creator. A bogus paragraph is used if a list item contains only a single block or nested list.
|
|
303
|
-
*
|
|
304
|
-
* @internal
|
|
305
|
-
* @param attributeNames The list of all model list attributes (including registered strategies).
|
|
306
|
-
*/
|
|
307
|
-
export function bogusParagraphCreator(attributeNames, { dataPipeline } = {}) {
|
|
308
|
-
return (modelElement, { writer }) => {
|
|
309
|
-
// Convert only if a bogus paragraph should be used.
|
|
310
|
-
if (!shouldUseBogusParagraph(modelElement, attributeNames)) {
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
if (!dataPipeline) {
|
|
314
|
-
return writer.createContainerElement('span', { class: 'ck-list-bogus-paragraph' });
|
|
315
|
-
}
|
|
316
|
-
// Using `<p>` in case there are some markers on it and transparentRendering will render it anyway.
|
|
317
|
-
const viewElement = writer.createContainerElement('p');
|
|
318
|
-
writer.setCustomProperty('dataPipeline:transparentRendering', true, viewElement);
|
|
319
|
-
return viewElement;
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Helper for mapping mode to view elements. It's using positions mapping instead of mapper.toViewElement( element )
|
|
324
|
-
* to find outermost view element. This is for cases when mapping is using inner view element like in the code blocks (pre > code).
|
|
325
|
-
*
|
|
326
|
-
* @internal
|
|
327
|
-
* @param element The model element.
|
|
328
|
-
* @param mapper The mapper instance.
|
|
329
|
-
* @param model The model.
|
|
330
|
-
* @param writer The view downcast writer.
|
|
331
|
-
*/
|
|
332
|
-
export function findMappedViewElement(element, mapper, model, writer) {
|
|
333
|
-
const modelRange = model.createRangeOn(element);
|
|
334
|
-
const viewRange = mapper.toViewRange(modelRange).getTrimmed();
|
|
335
|
-
const viewWalker = viewRange.getWalker();
|
|
336
|
-
for (const { item } of viewWalker) {
|
|
337
|
-
if (item.is('element') && item.getCustomProperty('listItemMarker')) {
|
|
338
|
-
viewWalker.jumpTo(writer.createPositionAfter(item));
|
|
339
|
-
}
|
|
340
|
-
else if (item.is('element') && !item.getCustomProperty('listItemWrapper')) {
|
|
341
|
-
return item;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* The model to view custom position mapping for cases when marker is injected at the beginning of a block.
|
|
347
|
-
*
|
|
348
|
-
* @internal
|
|
349
|
-
*/
|
|
350
|
-
export function createModelToViewPositionMapper(strategies, view) {
|
|
351
|
-
return (evt, data) => {
|
|
352
|
-
if (data.modelPosition.offset > 0) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
const positionParent = data.modelPosition.parent;
|
|
356
|
-
if (!isListItemBlock(positionParent)) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
if (!strategies.some(strategy => (strategy.scope == 'itemMarker' &&
|
|
360
|
-
strategy.canInjectMarkerIntoElement &&
|
|
361
|
-
strategy.canInjectMarkerIntoElement(positionParent)))) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
const viewElement = data.mapper.toViewElement(positionParent);
|
|
365
|
-
const viewRange = view.createRangeIn(viewElement);
|
|
366
|
-
const viewWalker = viewRange.getWalker();
|
|
367
|
-
let positionAfterLastMarker = viewRange.start;
|
|
368
|
-
for (const { item } of viewWalker) {
|
|
369
|
-
// Walk only over the non-mapped elements (UIElements, ViewAttributeElements, $text, or any other element without mapping).
|
|
370
|
-
if (item.is('element') && data.mapper.toModelElement(item) || item.is('$textProxy')) {
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
if (item.is('element') && item.getCustomProperty('listItemMarker')) {
|
|
374
|
-
positionAfterLastMarker = view.createPositionAfter(item);
|
|
375
|
-
// Jump over the content of the marker (this is not needed for UIElement but required for other element types).
|
|
376
|
-
viewWalker.skip(({ previousPosition }) => !previousPosition.isEqual(positionAfterLastMarker));
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
data.viewPosition = positionAfterLastMarker;
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Removes a custom marker elements and item wrappers related to that marker.
|
|
384
|
-
*/
|
|
385
|
-
function removeCustomMarkerElements(viewElement, viewWriter, mapper) {
|
|
386
|
-
// Remove item wrapper.
|
|
387
|
-
while (viewElement.parent.is('attributeElement') && viewElement.parent.getCustomProperty('listItemWrapper')) {
|
|
388
|
-
viewWriter.unwrap(viewWriter.createRangeOn(viewElement), viewElement.parent);
|
|
389
|
-
}
|
|
390
|
-
// Remove custom item markers.
|
|
391
|
-
const markersToRemove = [];
|
|
392
|
-
// Markers before a block.
|
|
393
|
-
collectMarkersToRemove(viewWriter.createPositionBefore(viewElement).getWalker({ direction: 'backward' }));
|
|
394
|
-
// Markers inside a block.
|
|
395
|
-
collectMarkersToRemove(viewWriter.createRangeIn(viewElement).getWalker());
|
|
396
|
-
for (const marker of markersToRemove) {
|
|
397
|
-
viewWriter.remove(marker);
|
|
398
|
-
}
|
|
399
|
-
function collectMarkersToRemove(viewWalker) {
|
|
400
|
-
for (const { item } of viewWalker) {
|
|
401
|
-
// Walk only over the non-mapped elements (UIElements, ViewAttributeElements, $text, or any other element without mapping).
|
|
402
|
-
if (item.is('element') && mapper.toModelElement(item)) {
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
if (item.is('element') && item.getCustomProperty('listItemMarker')) {
|
|
406
|
-
markersToRemove.push(item);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Inserts a custom marker elements and wraps first block of a list item if marker requires it.
|
|
413
|
-
*/
|
|
414
|
-
function insertCustomMarkerElements(listItem, viewElement, strategies, writer, { dataPipeline }) {
|
|
415
|
-
let viewRange = writer.createRangeOn(viewElement);
|
|
416
|
-
// Marker can be inserted only before the first block of a list item.
|
|
417
|
-
if (!isFirstBlockOfListItem(listItem)) {
|
|
418
|
-
return viewRange;
|
|
419
|
-
}
|
|
420
|
-
for (const strategy of strategies) {
|
|
421
|
-
if (strategy.scope != 'itemMarker') {
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
// Create the custom marker element and inject it before the first block of the list item.
|
|
425
|
-
const markerElement = strategy.createElement(writer, listItem, { dataPipeline });
|
|
426
|
-
if (!markerElement) {
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
writer.setCustomProperty('listItemMarker', true, markerElement);
|
|
430
|
-
if (strategy.canInjectMarkerIntoElement && strategy.canInjectMarkerIntoElement(listItem)) {
|
|
431
|
-
writer.insert(writer.createPositionAt(viewElement, 0), markerElement);
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
writer.insert(viewRange.start, markerElement);
|
|
435
|
-
viewRange = writer.createRange(writer.createPositionBefore(markerElement), writer.createPositionAfter(viewElement));
|
|
436
|
-
}
|
|
437
|
-
// Wrap the marker and optionally the first block with an attribute element (label for to-do lists).
|
|
438
|
-
if (!strategy.createWrapperElement || !strategy.canWrapElement) {
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
const wrapper = strategy.createWrapperElement(writer, listItem, { dataPipeline });
|
|
442
|
-
writer.setCustomProperty('listItemWrapper', true, wrapper);
|
|
443
|
-
// The whole block can be wrapped...
|
|
444
|
-
if (strategy.canWrapElement(listItem)) {
|
|
445
|
-
viewRange = writer.wrap(viewRange, wrapper);
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
// ... or only the marker element (if the block is downcasted to heading or block widget).
|
|
449
|
-
viewRange = writer.wrap(writer.createRangeOn(markerElement), wrapper);
|
|
450
|
-
viewRange = writer.createRange(viewRange.start, writer.createPositionAfter(viewElement));
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return viewRange;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Unwraps all ol, ul, and li attribute elements that are wrapping the provided view element.
|
|
457
|
-
*/
|
|
458
|
-
function unwrapListItemBlock(viewElement, viewWriter) {
|
|
459
|
-
let attributeElement = viewElement.parent;
|
|
460
|
-
while (attributeElement.is('attributeElement') && ['ul', 'ol', 'li'].includes(attributeElement.name)) {
|
|
461
|
-
const parentElement = attributeElement.parent;
|
|
462
|
-
viewWriter.unwrap(viewWriter.createRangeOn(viewElement), attributeElement);
|
|
463
|
-
attributeElement = parentElement;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* Wraps the given list item with appropriate attribute elements for ul, ol, and li.
|
|
468
|
-
*/
|
|
469
|
-
function wrapListItemBlock(listItem, viewRange, strategies, writer, options) {
|
|
470
|
-
if (!listItem.hasAttribute('listIndent')) {
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
const listItemIndent = listItem.getAttribute('listIndent');
|
|
474
|
-
let currentListItem = listItem;
|
|
475
|
-
for (let indent = listItemIndent; indent >= 0; indent--) {
|
|
476
|
-
const listItemViewElement = createListItemElement(writer, indent, currentListItem.getAttribute('listItemId'));
|
|
477
|
-
const listViewElement = createListElement(writer, indent, currentListItem.getAttribute('listType'));
|
|
478
|
-
for (const strategy of strategies) {
|
|
479
|
-
if ((strategy.scope == 'list' || strategy.scope == 'item') &&
|
|
480
|
-
currentListItem.hasAttribute(strategy.attributeName)) {
|
|
481
|
-
strategy.setAttributeOnDowncast(writer, currentListItem.getAttribute(strategy.attributeName), strategy.scope == 'list' ? listViewElement : listItemViewElement, options, currentListItem);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
viewRange = writer.wrap(viewRange, listItemViewElement);
|
|
485
|
-
viewRange = writer.wrap(viewRange, listViewElement);
|
|
486
|
-
if (indent == 0) {
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
currentListItem = ListWalker.first(currentListItem, { lowerIndent: true });
|
|
490
|
-
// There is no list item with lower indent, this means this is a document fragment containing
|
|
491
|
-
// only a part of nested list (like copy to clipboard) so we don't need to try to wrap it further.
|
|
492
|
-
if (!currentListItem) {
|
|
493
|
-
break;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
// Returns the function that is responsible for consuming attributes that are set on the model node.
|
|
498
|
-
function createAttributesConsumer(attributeNames, strategies) {
|
|
499
|
-
const nonConsumingAttributes = strategies
|
|
500
|
-
.filter(strategy => strategy.consume === false)
|
|
501
|
-
.map(strategy => strategy.attributeName);
|
|
502
|
-
return (node, consumable) => {
|
|
503
|
-
const events = [];
|
|
504
|
-
// Collect all set attributes that are triggering conversion.
|
|
505
|
-
for (const attributeName of attributeNames) {
|
|
506
|
-
if (node.hasAttribute(attributeName) && !nonConsumingAttributes.includes(attributeName)) {
|
|
507
|
-
events.push(`attribute:${attributeName}`);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (!events.every(event => consumable.test(node, event) !== false)) {
|
|
511
|
-
return false;
|
|
512
|
-
}
|
|
513
|
-
events.forEach(event => consumable.consume(node, event));
|
|
514
|
-
return true;
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
// Whether the given item should be rendered as a bogus paragraph.
|
|
518
|
-
function shouldUseBogusParagraph(item, attributeNames, blocks = getAllListItemBlocks(item)) {
|
|
519
|
-
if (!isListItemBlock(item)) {
|
|
520
|
-
return false;
|
|
521
|
-
}
|
|
522
|
-
for (const attributeKey of item.getAttributeKeys()) {
|
|
523
|
-
// Ignore selection attributes stored on block elements.
|
|
524
|
-
if (attributeKey.startsWith('selection:') || attributeKey == 'htmlEmptyBlock') {
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
// Don't use bogus paragraph if there are attributes from other features.
|
|
528
|
-
if (!attributeNames.includes(attributeKey)) {
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return blocks.length < 2;
|
|
533
|
-
}
|