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 | * Returns a converter that consumes the `style`, `reversed`, and `start` attributes.
|
7 | * In `style`, it searches for the `list-style-type` definition.
|
8 | * If not found, the `"default"` value will be used.
|
9 | *
|
10 | * @internal
|
11 | * @param strategy
|
12 | */
|
13 | export function listPropertiesUpcastConverter(strategy) {
|
14 | return (evt, data, conversionApi) => {
|
15 | const { writer, schema, consumable } = conversionApi;
|
16 | // If there is no view consumable to consume, set the default attribute value to be able to reconvert nested lists on parent change.
|
17 | // So abort converting if attribute was directly consumed.
|
18 | if (consumable.test(data.viewItem, strategy.viewConsumables) === false) {
|
19 | return;
|
20 | }
|
21 | if (!data.modelRange) {
|
22 | Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
23 | }
|
24 | let applied = false;
|
25 | for (const item of data.modelRange.getItems({ shallow: true })) {
|
26 | if (!schema.checkAttribute(item, strategy.attributeName)) {
|
27 | continue;
|
28 | }
|
29 | if (!strategy.appliesToListItem(item)) {
|
30 | continue;
|
31 | }
|
32 | // Set list attributes only on same level items, those nested deeper are already handled by the recursive conversion.
|
33 | if (item.hasAttribute(strategy.attributeName)) {
|
34 | continue;
|
35 | }
|
36 | writer.setAttribute(strategy.attributeName, strategy.getAttributeOnUpcast(data.viewItem), item);
|
37 | applied = true;
|
38 | }
|
39 | if (applied) {
|
40 | consumable.consume(data.viewItem, strategy.viewConsumables);
|
41 | }
|
42 | };
|
43 | }
|