@ckeditor/ckeditor5-list 40.0.0 → 40.1.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 +2 -2
- package/build/list.js +1 -1
- package/package.json +3 -3
- package/src/augmentation.d.ts +52 -52
- package/src/augmentation.js +5 -5
- package/src/documentlist/adjacentlistssupport.d.ts +15 -15
- package/src/documentlist/adjacentlistssupport.js +81 -81
- package/src/documentlist/converters.d.ts +65 -65
- package/src/documentlist/converters.js +441 -441
- package/src/documentlist/documentlistcommand.d.ts +80 -80
- package/src/documentlist/documentlistcommand.js +150 -150
- package/src/documentlist/documentlistediting.d.ts +212 -212
- package/src/documentlist/documentlistediting.js +646 -645
- package/src/documentlist/documentlistindentcommand.d.ts +62 -62
- package/src/documentlist/documentlistindentcommand.js +129 -129
- package/src/documentlist/documentlistmergecommand.d.ts +76 -76
- package/src/documentlist/documentlistmergecommand.js +174 -174
- package/src/documentlist/documentlistsplitcommand.d.ts +67 -67
- package/src/documentlist/documentlistsplitcommand.js +70 -70
- package/src/documentlist/documentlistutils.d.ts +46 -46
- package/src/documentlist/documentlistutils.js +50 -50
- package/src/documentlist/utils/listwalker.d.ts +145 -145
- package/src/documentlist/utils/listwalker.js +182 -182
- package/src/documentlist/utils/model.d.ts +202 -202
- package/src/documentlist/utils/model.js +455 -455
- package/src/documentlist/utils/postfixers.d.ts +37 -37
- package/src/documentlist/utils/postfixers.js +126 -126
- package/src/documentlist/utils/view.d.ts +81 -81
- package/src/documentlist/utils/view.js +117 -117
- package/src/documentlist.d.ts +26 -26
- package/src/documentlist.js +30 -30
- package/src/documentlistproperties/converters.d.ts +19 -19
- package/src/documentlistproperties/converters.js +43 -43
- package/src/documentlistproperties/documentlistpropertiesediting.d.ts +88 -88
- package/src/documentlistproperties/documentlistpropertiesediting.js +266 -266
- package/src/documentlistproperties/documentlistpropertiesutils.d.ts +33 -33
- package/src/documentlistproperties/documentlistpropertiesutils.js +44 -44
- package/src/documentlistproperties/documentlistreversedcommand.d.ts +36 -36
- package/src/documentlistproperties/documentlistreversedcommand.js +55 -55
- package/src/documentlistproperties/documentliststartcommand.d.ts +38 -38
- package/src/documentlistproperties/documentliststartcommand.js +57 -57
- package/src/documentlistproperties/documentliststylecommand.d.ts +72 -72
- package/src/documentlistproperties/documentliststylecommand.js +113 -113
- package/src/documentlistproperties/utils/style.d.ts +20 -20
- package/src/documentlistproperties/utils/style.js +54 -54
- package/src/documentlistproperties.d.ts +27 -27
- package/src/documentlistproperties.js +31 -31
- package/src/index.d.ts +43 -43
- package/src/index.js +29 -29
- package/src/list/converters.d.ts +196 -196
- package/src/list/converters.js +905 -905
- package/src/list/indentcommand.d.ts +37 -37
- package/src/list/indentcommand.js +107 -107
- package/src/list/listcommand.d.ts +55 -55
- package/src/list/listcommand.js +274 -274
- package/src/list/listediting.d.ts +32 -32
- package/src/list/listediting.js +161 -161
- package/src/list/listui.d.ts +19 -19
- package/src/list/listui.js +32 -32
- package/src/list/listutils.d.ts +41 -41
- package/src/list/listutils.js +46 -46
- package/src/list/utils.d.ts +112 -112
- package/src/list/utils.js +374 -374
- package/src/list.d.ts +26 -26
- package/src/list.js +30 -30
- package/src/listconfig.d.ts +132 -132
- package/src/listconfig.js +5 -5
- package/src/listproperties/listpropertiesediting.d.ts +72 -72
- package/src/listproperties/listpropertiesediting.js +696 -696
- package/src/listproperties/listpropertiesui.d.ts +23 -23
- package/src/listproperties/listpropertiesui.js +277 -277
- package/src/listproperties/listreversedcommand.d.ts +38 -38
- package/src/listproperties/listreversedcommand.js +52 -52
- package/src/listproperties/liststartcommand.d.ts +37 -37
- package/src/listproperties/liststartcommand.js +51 -51
- package/src/listproperties/liststylecommand.d.ts +67 -67
- package/src/listproperties/liststylecommand.js +99 -99
- package/src/listproperties/ui/collapsibleview.d.ts +63 -63
- package/src/listproperties/ui/collapsibleview.js +89 -89
- package/src/listproperties/ui/listpropertiesview.d.ts +157 -157
- package/src/listproperties/ui/listpropertiesview.js +299 -299
- package/src/listproperties.d.ts +26 -26
- package/src/listproperties.js +30 -30
- package/src/liststyle.d.ts +28 -28
- package/src/liststyle.js +36 -36
- package/src/tododocumentlist/checktododocumentlistcommand.d.ts +49 -49
- package/src/tododocumentlist/checktododocumentlistcommand.js +82 -82
- package/src/tododocumentlist/todocheckboxchangeobserver.d.ts +41 -41
- package/src/tododocumentlist/todocheckboxchangeobserver.js +37 -37
- package/src/tododocumentlist/tododocumentlistediting.d.ts +38 -38
- package/src/tododocumentlist/tododocumentlistediting.js +399 -399
- package/src/tododocumentlist.d.ts +27 -27
- package/src/tododocumentlist.js +31 -31
- package/src/todolist/checktodolistcommand.d.ts +52 -52
- package/src/todolist/checktodolistcommand.js +76 -76
- package/src/todolist/todolistconverters.d.ts +82 -82
- package/src/todolist/todolistconverters.js +260 -260
- package/src/todolist/todolistediting.d.ts +39 -39
- package/src/todolist/todolistediting.js +161 -161
- package/src/todolist/todolistui.d.ts +19 -19
- package/src/todolist/todolistui.js +29 -29
- package/src/todolist.d.ts +27 -27
- package/src/todolist.js +31 -31
- package/build/list.js.map +0 -1
|
@@ -1,266 +1,266 @@
|
|
|
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/documentlistproperties/documentlistpropertiesediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import DocumentListEditing from '../documentlist/documentlistediting';
|
|
10
|
-
import DocumentListStartCommand from './documentliststartcommand';
|
|
11
|
-
import DocumentListStyleCommand from './documentliststylecommand';
|
|
12
|
-
import DocumentListReversedCommand from './documentlistreversedcommand';
|
|
13
|
-
import { listPropertiesUpcastConverter } from './converters';
|
|
14
|
-
import { getAllSupportedStyleTypes, getListTypeFromListStyleType, getListStyleTypeFromTypeAttribute, getTypeAttributeFromListStyleType } from './utils/style';
|
|
15
|
-
import DocumentListPropertiesUtils from './documentlistpropertiesutils';
|
|
16
|
-
const DEFAULT_LIST_TYPE = 'default';
|
|
17
|
-
/**
|
|
18
|
-
* The document list properties engine feature.
|
|
19
|
-
*
|
|
20
|
-
* It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
|
|
21
|
-
* Read more in {@link module:list/listconfig~ListPropertiesConfig}.
|
|
22
|
-
*/
|
|
23
|
-
export default class DocumentListPropertiesEditing extends Plugin {
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get requires() {
|
|
28
|
-
return [DocumentListEditing, DocumentListPropertiesUtils];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
static get pluginName() {
|
|
34
|
-
return 'DocumentListPropertiesEditing';
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @inheritDoc
|
|
38
|
-
*/
|
|
39
|
-
constructor(editor) {
|
|
40
|
-
super(editor);
|
|
41
|
-
editor.config.define('list.properties', {
|
|
42
|
-
styles: true,
|
|
43
|
-
startIndex: false,
|
|
44
|
-
reversed: false
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @inheritDoc
|
|
49
|
-
*/
|
|
50
|
-
init() {
|
|
51
|
-
const editor = this.editor;
|
|
52
|
-
const model = editor.model;
|
|
53
|
-
const documentListEditing = editor.plugins.get(DocumentListEditing);
|
|
54
|
-
const enabledProperties = editor.config.get('list.properties');
|
|
55
|
-
const strategies = createAttributeStrategies(enabledProperties);
|
|
56
|
-
for (const strategy of strategies) {
|
|
57
|
-
strategy.addCommand(editor);
|
|
58
|
-
model.schema.extend('$listItem', { allowAttributes: strategy.attributeName });
|
|
59
|
-
// Register downcast strategy.
|
|
60
|
-
documentListEditing.registerDowncastStrategy({
|
|
61
|
-
scope: 'list',
|
|
62
|
-
attributeName: strategy.attributeName,
|
|
63
|
-
setAttributeOnDowncast(writer, attributeValue, viewElement) {
|
|
64
|
-
strategy.setAttributeOnDowncast(writer, attributeValue, viewElement);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
// Set up conversion.
|
|
69
|
-
editor.conversion.for('upcast').add(dispatcher => {
|
|
70
|
-
for (const strategy of strategies) {
|
|
71
|
-
dispatcher.on('element:ol', listPropertiesUpcastConverter(strategy));
|
|
72
|
-
dispatcher.on('element:ul', listPropertiesUpcastConverter(strategy));
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
// Verify if the list view element (ul or ol) requires refreshing.
|
|
76
|
-
documentListEditing.on('checkAttributes:list', (evt, { viewElement, modelAttributes }) => {
|
|
77
|
-
for (const strategy of strategies) {
|
|
78
|
-
if (strategy.getAttributeOnUpcast(viewElement) != modelAttributes[strategy.attributeName]) {
|
|
79
|
-
evt.return = true;
|
|
80
|
-
evt.stop();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
// Reset list properties after indenting list items.
|
|
85
|
-
this.listenTo(editor.commands.get('indentList'), 'afterExecute', (evt, changedBlocks) => {
|
|
86
|
-
model.change(writer => {
|
|
87
|
-
for (const node of changedBlocks) {
|
|
88
|
-
for (const strategy of strategies) {
|
|
89
|
-
if (strategy.appliesToListItem(node)) {
|
|
90
|
-
// Just reset the attribute.
|
|
91
|
-
// If there is a previous indented list that this node should be merged into,
|
|
92
|
-
// the postfixer will unify all the attributes of both sub-lists.
|
|
93
|
-
writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
// Add or remove list properties attributes depending on the list type.
|
|
100
|
-
documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
101
|
-
for (const { node } of listNodes) {
|
|
102
|
-
for (const strategy of strategies) {
|
|
103
|
-
// Check if attribute is valid.
|
|
104
|
-
if (strategy.hasValidAttribute(node)) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
// Add missing default property attributes...
|
|
108
|
-
if (strategy.appliesToListItem(node)) {
|
|
109
|
-
writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
|
|
110
|
-
}
|
|
111
|
-
// ...or remove invalid property attributes.
|
|
112
|
-
else {
|
|
113
|
-
writer.removeAttribute(strategy.attributeName, node);
|
|
114
|
-
}
|
|
115
|
-
evt.return = true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
// Make sure that all items in a single list (items at the same level & listType) have the same properties.
|
|
120
|
-
documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
121
|
-
for (const { node, previousNodeInList } of listNodes) {
|
|
122
|
-
// This is a first item of a nested list.
|
|
123
|
-
if (!previousNodeInList) {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
// This is a first block of a list of a different type.
|
|
127
|
-
if (previousNodeInList.getAttribute('listType') != node.getAttribute('listType')) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
// Copy properties from the previous one.
|
|
131
|
-
for (const strategy of strategies) {
|
|
132
|
-
const { attributeName } = strategy;
|
|
133
|
-
if (!strategy.appliesToListItem(node)) {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const value = previousNodeInList.getAttribute(attributeName);
|
|
137
|
-
if (node.getAttribute(attributeName) != value) {
|
|
138
|
-
writer.setAttribute(attributeName, value, node);
|
|
139
|
-
evt.return = true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Creates an array of strategies for dealing with enabled listItem attributes.
|
|
148
|
-
*/
|
|
149
|
-
function createAttributeStrategies(enabledProperties) {
|
|
150
|
-
const strategies = [];
|
|
151
|
-
if (enabledProperties.styles) {
|
|
152
|
-
const useAttribute = typeof enabledProperties.styles == 'object' && enabledProperties.styles.useAttribute;
|
|
153
|
-
strategies.push({
|
|
154
|
-
attributeName: 'listStyle',
|
|
155
|
-
defaultValue: DEFAULT_LIST_TYPE,
|
|
156
|
-
viewConsumables: { styles: 'list-style-type' },
|
|
157
|
-
addCommand(editor) {
|
|
158
|
-
let supportedTypes = getAllSupportedStyleTypes();
|
|
159
|
-
if (useAttribute) {
|
|
160
|
-
supportedTypes = supportedTypes.filter(styleType => !!getTypeAttributeFromListStyleType(styleType));
|
|
161
|
-
}
|
|
162
|
-
editor.commands.add('listStyle', new DocumentListStyleCommand(editor, DEFAULT_LIST_TYPE, supportedTypes));
|
|
163
|
-
},
|
|
164
|
-
appliesToListItem(item) {
|
|
165
|
-
return item.getAttribute('listType') == 'numbered' || item.getAttribute('listType') == 'bulleted';
|
|
166
|
-
},
|
|
167
|
-
hasValidAttribute(item) {
|
|
168
|
-
if (!this.appliesToListItem(item)) {
|
|
169
|
-
return !item.hasAttribute('listStyle');
|
|
170
|
-
}
|
|
171
|
-
if (!item.hasAttribute('listStyle')) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
const value = item.getAttribute('listStyle');
|
|
175
|
-
if (value == DEFAULT_LIST_TYPE) {
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
return getListTypeFromListStyleType(value) == item.getAttribute('listType');
|
|
179
|
-
},
|
|
180
|
-
setAttributeOnDowncast(writer, listStyle, element) {
|
|
181
|
-
if (listStyle && listStyle !== DEFAULT_LIST_TYPE) {
|
|
182
|
-
if (useAttribute) {
|
|
183
|
-
const value = getTypeAttributeFromListStyleType(listStyle);
|
|
184
|
-
if (value) {
|
|
185
|
-
writer.setAttribute('type', value, element);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
writer.setStyle('list-style-type', listStyle, element);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
writer.removeStyle('list-style-type', element);
|
|
195
|
-
writer.removeAttribute('type', element);
|
|
196
|
-
},
|
|
197
|
-
getAttributeOnUpcast(listParent) {
|
|
198
|
-
const style = listParent.getStyle('list-style-type');
|
|
199
|
-
if (style) {
|
|
200
|
-
return style;
|
|
201
|
-
}
|
|
202
|
-
const attribute = listParent.getAttribute('type');
|
|
203
|
-
if (attribute) {
|
|
204
|
-
return getListStyleTypeFromTypeAttribute(attribute);
|
|
205
|
-
}
|
|
206
|
-
return DEFAULT_LIST_TYPE;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
if (enabledProperties.reversed) {
|
|
211
|
-
strategies.push({
|
|
212
|
-
attributeName: 'listReversed',
|
|
213
|
-
defaultValue: false,
|
|
214
|
-
viewConsumables: { attributes: 'reversed' },
|
|
215
|
-
addCommand(editor) {
|
|
216
|
-
editor.commands.add('listReversed', new DocumentListReversedCommand(editor));
|
|
217
|
-
},
|
|
218
|
-
appliesToListItem(item) {
|
|
219
|
-
return item.getAttribute('listType') == 'numbered';
|
|
220
|
-
},
|
|
221
|
-
hasValidAttribute(item) {
|
|
222
|
-
return this.appliesToListItem(item) == item.hasAttribute('listReversed');
|
|
223
|
-
},
|
|
224
|
-
setAttributeOnDowncast(writer, listReversed, element) {
|
|
225
|
-
if (listReversed) {
|
|
226
|
-
writer.setAttribute('reversed', 'reversed', element);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
writer.removeAttribute('reversed', element);
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
getAttributeOnUpcast(listParent) {
|
|
233
|
-
return listParent.hasAttribute('reversed');
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
if (enabledProperties.startIndex) {
|
|
238
|
-
strategies.push({
|
|
239
|
-
attributeName: 'listStart',
|
|
240
|
-
defaultValue: 1,
|
|
241
|
-
viewConsumables: { attributes: 'start' },
|
|
242
|
-
addCommand(editor) {
|
|
243
|
-
editor.commands.add('listStart', new DocumentListStartCommand(editor));
|
|
244
|
-
},
|
|
245
|
-
appliesToListItem(item) {
|
|
246
|
-
return item.getAttribute('listType') == 'numbered';
|
|
247
|
-
},
|
|
248
|
-
hasValidAttribute(item) {
|
|
249
|
-
return this.appliesToListItem(item) == item.hasAttribute('listStart');
|
|
250
|
-
},
|
|
251
|
-
setAttributeOnDowncast(writer, listStart, element) {
|
|
252
|
-
if (listStart == 0 || listStart > 1) {
|
|
253
|
-
writer.setAttribute('start', listStart, element);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
writer.removeAttribute('start', element);
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
getAttributeOnUpcast(listParent) {
|
|
260
|
-
const startAttributeValue = listParent.getAttribute('start');
|
|
261
|
-
return startAttributeValue >= 0 ? startAttributeValue : 1;
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
return strategies;
|
|
266
|
-
}
|
|
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/documentlistproperties/documentlistpropertiesediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import DocumentListEditing from '../documentlist/documentlistediting';
|
|
10
|
+
import DocumentListStartCommand from './documentliststartcommand';
|
|
11
|
+
import DocumentListStyleCommand from './documentliststylecommand';
|
|
12
|
+
import DocumentListReversedCommand from './documentlistreversedcommand';
|
|
13
|
+
import { listPropertiesUpcastConverter } from './converters';
|
|
14
|
+
import { getAllSupportedStyleTypes, getListTypeFromListStyleType, getListStyleTypeFromTypeAttribute, getTypeAttributeFromListStyleType } from './utils/style';
|
|
15
|
+
import DocumentListPropertiesUtils from './documentlistpropertiesutils';
|
|
16
|
+
const DEFAULT_LIST_TYPE = 'default';
|
|
17
|
+
/**
|
|
18
|
+
* The document list properties engine feature.
|
|
19
|
+
*
|
|
20
|
+
* It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
|
|
21
|
+
* Read more in {@link module:list/listconfig~ListPropertiesConfig}.
|
|
22
|
+
*/
|
|
23
|
+
export default class DocumentListPropertiesEditing extends Plugin {
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get requires() {
|
|
28
|
+
return [DocumentListEditing, DocumentListPropertiesUtils];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
static get pluginName() {
|
|
34
|
+
return 'DocumentListPropertiesEditing';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
constructor(editor) {
|
|
40
|
+
super(editor);
|
|
41
|
+
editor.config.define('list.properties', {
|
|
42
|
+
styles: true,
|
|
43
|
+
startIndex: false,
|
|
44
|
+
reversed: false
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @inheritDoc
|
|
49
|
+
*/
|
|
50
|
+
init() {
|
|
51
|
+
const editor = this.editor;
|
|
52
|
+
const model = editor.model;
|
|
53
|
+
const documentListEditing = editor.plugins.get(DocumentListEditing);
|
|
54
|
+
const enabledProperties = editor.config.get('list.properties');
|
|
55
|
+
const strategies = createAttributeStrategies(enabledProperties);
|
|
56
|
+
for (const strategy of strategies) {
|
|
57
|
+
strategy.addCommand(editor);
|
|
58
|
+
model.schema.extend('$listItem', { allowAttributes: strategy.attributeName });
|
|
59
|
+
// Register downcast strategy.
|
|
60
|
+
documentListEditing.registerDowncastStrategy({
|
|
61
|
+
scope: 'list',
|
|
62
|
+
attributeName: strategy.attributeName,
|
|
63
|
+
setAttributeOnDowncast(writer, attributeValue, viewElement) {
|
|
64
|
+
strategy.setAttributeOnDowncast(writer, attributeValue, viewElement);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Set up conversion.
|
|
69
|
+
editor.conversion.for('upcast').add(dispatcher => {
|
|
70
|
+
for (const strategy of strategies) {
|
|
71
|
+
dispatcher.on('element:ol', listPropertiesUpcastConverter(strategy));
|
|
72
|
+
dispatcher.on('element:ul', listPropertiesUpcastConverter(strategy));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// Verify if the list view element (ul or ol) requires refreshing.
|
|
76
|
+
documentListEditing.on('checkAttributes:list', (evt, { viewElement, modelAttributes }) => {
|
|
77
|
+
for (const strategy of strategies) {
|
|
78
|
+
if (strategy.getAttributeOnUpcast(viewElement) != modelAttributes[strategy.attributeName]) {
|
|
79
|
+
evt.return = true;
|
|
80
|
+
evt.stop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// Reset list properties after indenting list items.
|
|
85
|
+
this.listenTo(editor.commands.get('indentList'), 'afterExecute', (evt, changedBlocks) => {
|
|
86
|
+
model.change(writer => {
|
|
87
|
+
for (const node of changedBlocks) {
|
|
88
|
+
for (const strategy of strategies) {
|
|
89
|
+
if (strategy.appliesToListItem(node)) {
|
|
90
|
+
// Just reset the attribute.
|
|
91
|
+
// If there is a previous indented list that this node should be merged into,
|
|
92
|
+
// the postfixer will unify all the attributes of both sub-lists.
|
|
93
|
+
writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
// Add or remove list properties attributes depending on the list type.
|
|
100
|
+
documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
101
|
+
for (const { node } of listNodes) {
|
|
102
|
+
for (const strategy of strategies) {
|
|
103
|
+
// Check if attribute is valid.
|
|
104
|
+
if (strategy.hasValidAttribute(node)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// Add missing default property attributes...
|
|
108
|
+
if (strategy.appliesToListItem(node)) {
|
|
109
|
+
writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
|
|
110
|
+
}
|
|
111
|
+
// ...or remove invalid property attributes.
|
|
112
|
+
else {
|
|
113
|
+
writer.removeAttribute(strategy.attributeName, node);
|
|
114
|
+
}
|
|
115
|
+
evt.return = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Make sure that all items in a single list (items at the same level & listType) have the same properties.
|
|
120
|
+
documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
121
|
+
for (const { node, previousNodeInList } of listNodes) {
|
|
122
|
+
// This is a first item of a nested list.
|
|
123
|
+
if (!previousNodeInList) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
// This is a first block of a list of a different type.
|
|
127
|
+
if (previousNodeInList.getAttribute('listType') != node.getAttribute('listType')) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// Copy properties from the previous one.
|
|
131
|
+
for (const strategy of strategies) {
|
|
132
|
+
const { attributeName } = strategy;
|
|
133
|
+
if (!strategy.appliesToListItem(node)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const value = previousNodeInList.getAttribute(attributeName);
|
|
137
|
+
if (node.getAttribute(attributeName) != value) {
|
|
138
|
+
writer.setAttribute(attributeName, value, node);
|
|
139
|
+
evt.return = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates an array of strategies for dealing with enabled listItem attributes.
|
|
148
|
+
*/
|
|
149
|
+
function createAttributeStrategies(enabledProperties) {
|
|
150
|
+
const strategies = [];
|
|
151
|
+
if (enabledProperties.styles) {
|
|
152
|
+
const useAttribute = typeof enabledProperties.styles == 'object' && enabledProperties.styles.useAttribute;
|
|
153
|
+
strategies.push({
|
|
154
|
+
attributeName: 'listStyle',
|
|
155
|
+
defaultValue: DEFAULT_LIST_TYPE,
|
|
156
|
+
viewConsumables: { styles: 'list-style-type' },
|
|
157
|
+
addCommand(editor) {
|
|
158
|
+
let supportedTypes = getAllSupportedStyleTypes();
|
|
159
|
+
if (useAttribute) {
|
|
160
|
+
supportedTypes = supportedTypes.filter(styleType => !!getTypeAttributeFromListStyleType(styleType));
|
|
161
|
+
}
|
|
162
|
+
editor.commands.add('listStyle', new DocumentListStyleCommand(editor, DEFAULT_LIST_TYPE, supportedTypes));
|
|
163
|
+
},
|
|
164
|
+
appliesToListItem(item) {
|
|
165
|
+
return item.getAttribute('listType') == 'numbered' || item.getAttribute('listType') == 'bulleted';
|
|
166
|
+
},
|
|
167
|
+
hasValidAttribute(item) {
|
|
168
|
+
if (!this.appliesToListItem(item)) {
|
|
169
|
+
return !item.hasAttribute('listStyle');
|
|
170
|
+
}
|
|
171
|
+
if (!item.hasAttribute('listStyle')) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const value = item.getAttribute('listStyle');
|
|
175
|
+
if (value == DEFAULT_LIST_TYPE) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
return getListTypeFromListStyleType(value) == item.getAttribute('listType');
|
|
179
|
+
},
|
|
180
|
+
setAttributeOnDowncast(writer, listStyle, element) {
|
|
181
|
+
if (listStyle && listStyle !== DEFAULT_LIST_TYPE) {
|
|
182
|
+
if (useAttribute) {
|
|
183
|
+
const value = getTypeAttributeFromListStyleType(listStyle);
|
|
184
|
+
if (value) {
|
|
185
|
+
writer.setAttribute('type', value, element);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
writer.setStyle('list-style-type', listStyle, element);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
writer.removeStyle('list-style-type', element);
|
|
195
|
+
writer.removeAttribute('type', element);
|
|
196
|
+
},
|
|
197
|
+
getAttributeOnUpcast(listParent) {
|
|
198
|
+
const style = listParent.getStyle('list-style-type');
|
|
199
|
+
if (style) {
|
|
200
|
+
return style;
|
|
201
|
+
}
|
|
202
|
+
const attribute = listParent.getAttribute('type');
|
|
203
|
+
if (attribute) {
|
|
204
|
+
return getListStyleTypeFromTypeAttribute(attribute);
|
|
205
|
+
}
|
|
206
|
+
return DEFAULT_LIST_TYPE;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (enabledProperties.reversed) {
|
|
211
|
+
strategies.push({
|
|
212
|
+
attributeName: 'listReversed',
|
|
213
|
+
defaultValue: false,
|
|
214
|
+
viewConsumables: { attributes: 'reversed' },
|
|
215
|
+
addCommand(editor) {
|
|
216
|
+
editor.commands.add('listReversed', new DocumentListReversedCommand(editor));
|
|
217
|
+
},
|
|
218
|
+
appliesToListItem(item) {
|
|
219
|
+
return item.getAttribute('listType') == 'numbered';
|
|
220
|
+
},
|
|
221
|
+
hasValidAttribute(item) {
|
|
222
|
+
return this.appliesToListItem(item) == item.hasAttribute('listReversed');
|
|
223
|
+
},
|
|
224
|
+
setAttributeOnDowncast(writer, listReversed, element) {
|
|
225
|
+
if (listReversed) {
|
|
226
|
+
writer.setAttribute('reversed', 'reversed', element);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
writer.removeAttribute('reversed', element);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
getAttributeOnUpcast(listParent) {
|
|
233
|
+
return listParent.hasAttribute('reversed');
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
if (enabledProperties.startIndex) {
|
|
238
|
+
strategies.push({
|
|
239
|
+
attributeName: 'listStart',
|
|
240
|
+
defaultValue: 1,
|
|
241
|
+
viewConsumables: { attributes: 'start' },
|
|
242
|
+
addCommand(editor) {
|
|
243
|
+
editor.commands.add('listStart', new DocumentListStartCommand(editor));
|
|
244
|
+
},
|
|
245
|
+
appliesToListItem(item) {
|
|
246
|
+
return item.getAttribute('listType') == 'numbered';
|
|
247
|
+
},
|
|
248
|
+
hasValidAttribute(item) {
|
|
249
|
+
return this.appliesToListItem(item) == item.hasAttribute('listStart');
|
|
250
|
+
},
|
|
251
|
+
setAttributeOnDowncast(writer, listStart, element) {
|
|
252
|
+
if (listStart == 0 || listStart > 1) {
|
|
253
|
+
writer.setAttribute('start', listStart, element);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
writer.removeAttribute('start', element);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
getAttributeOnUpcast(listParent) {
|
|
260
|
+
const startAttributeValue = listParent.getAttribute('start');
|
|
261
|
+
return startAttributeValue >= 0 ? startAttributeValue : 1;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return strategies;
|
|
266
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
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/documentlistproperties/documentlistpropertiesutils
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
/**
|
|
10
|
-
* A set of helpers related to document lists.
|
|
11
|
-
*/
|
|
12
|
-
export default class DocumentListPropertiesUtils extends Plugin {
|
|
13
|
-
/**
|
|
14
|
-
* @inheritDoc
|
|
15
|
-
*/
|
|
16
|
-
static get pluginName(): "DocumentListPropertiesUtils";
|
|
17
|
-
/**
|
|
18
|
-
* Gets all the style types supported by given list type.
|
|
19
|
-
*/
|
|
20
|
-
getAllSupportedStyleTypes(): Array<string>;
|
|
21
|
-
/**
|
|
22
|
-
* Checks whether the given list-style-type is supported by numbered or bulleted list.
|
|
23
|
-
*/
|
|
24
|
-
getListTypeFromListStyleType(listStyleType: string): 'bulleted' | 'numbered' | null;
|
|
25
|
-
/**
|
|
26
|
-
* Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
|
|
27
|
-
*/
|
|
28
|
-
getListStyleTypeFromTypeAttribute(value: string): string | null;
|
|
29
|
-
/**
|
|
30
|
-
* Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
|
|
31
|
-
*/
|
|
32
|
-
getTypeAttributeFromListStyleType(value: string): string | null;
|
|
33
|
-
}
|
|
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/documentlistproperties/documentlistpropertiesutils
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* A set of helpers related to document lists.
|
|
11
|
+
*/
|
|
12
|
+
export default class DocumentListPropertiesUtils extends Plugin {
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
static get pluginName(): "DocumentListPropertiesUtils";
|
|
17
|
+
/**
|
|
18
|
+
* Gets all the style types supported by given list type.
|
|
19
|
+
*/
|
|
20
|
+
getAllSupportedStyleTypes(): Array<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether the given list-style-type is supported by numbered or bulleted list.
|
|
23
|
+
*/
|
|
24
|
+
getListTypeFromListStyleType(listStyleType: string): 'bulleted' | 'numbered' | null;
|
|
25
|
+
/**
|
|
26
|
+
* Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
|
|
27
|
+
*/
|
|
28
|
+
getListStyleTypeFromTypeAttribute(value: string): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
|
|
31
|
+
*/
|
|
32
|
+
getTypeAttributeFromListStyleType(value: string): string | null;
|
|
33
|
+
}
|