@ckeditor/ckeditor5-list 35.3.2 → 35.4.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.
@@ -16,6 +16,7 @@ import DocumentListIndentCommand from './documentlistindentcommand';
16
16
  import DocumentListCommand from './documentlistcommand';
17
17
  import DocumentListMergeCommand from './documentlistmergecommand';
18
18
  import DocumentListSplitCommand from './documentlistsplitcommand';
19
+ import DocumentListUtils from '../documentlist/documentlistutils';
19
20
  import {
20
21
  bogusParagraphCreator,
21
22
  listItemDowncastConverter,
@@ -41,11 +42,11 @@ import {
41
42
  getViewElementIdForListType,
42
43
  getViewElementNameForListType
43
44
  } from './utils/view';
45
+
44
46
  import ListWalker, {
45
47
  iterateSiblingListBlocks,
46
48
  ListBlocksIterable
47
49
  } from './utils/listwalker';
48
-
49
50
  import '../../theme/documentlist.css';
50
51
 
51
52
  /**
@@ -72,7 +73,7 @@ export default class DocumentListEditing extends Plugin {
72
73
  * @inheritDoc
73
74
  */
74
75
  static get requires() {
75
- return [ Enter, Delete ];
76
+ return [ Enter, Delete, DocumentListUtils ];
76
77
  }
77
78
 
78
79
  /**
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/documentlist/documentlistutils
8
+ */
9
+
10
+ import { Plugin } from 'ckeditor5/src/core';
11
+ import { expandListBlocksToCompleteList, isFirstBlockOfListItem, isListItemBlock } from './utils/model';
12
+
13
+ /**
14
+ * A set of helpers related to document lists.
15
+ *
16
+ * @extends module:core/plugin~Plugin
17
+ */
18
+ export default class DocumentListUtils extends Plugin {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get pluginName() {
23
+ return 'DocumentListUtils';
24
+ }
25
+
26
+ /**
27
+ * Expands the given list of selected blocks to include all the items of the lists they're in.
28
+ *
29
+ * @param {module:engine/model/element~Element|Array.<module:engine/model/element~Element>} blocks The list of selected blocks.
30
+ * @returns {Array.<module:engine/model/element~Element>}
31
+ */
32
+ expandListBlocksToCompleteList( blocks ) {
33
+ return expandListBlocksToCompleteList( blocks );
34
+ }
35
+
36
+ /**
37
+ * Check if the given block is the first in the list item.
38
+ *
39
+ * @param {module:engine/model/element~Element} listBlock The list block element.
40
+ * @returns {Boolean}
41
+ */
42
+ isFirstBlockOfListItem( listBlock ) {
43
+ return isFirstBlockOfListItem( listBlock );
44
+ }
45
+
46
+ /**
47
+ * Returns true if the given model node is a list item block.
48
+ *
49
+ * @param {module:engine/model/node~Node} node A model node.
50
+ * @returns {Boolean}
51
+ */
52
+ isListItemBlock( node ) {
53
+ return isListItemBlock( node );
54
+ }
55
+ }
@@ -30,7 +30,15 @@ export function findAndAddListHeadToMap( position, itemToListHead ) {
30
30
  } else {
31
31
  let listHead = previousNode;
32
32
 
33
- for ( { node: listHead } of iterateSiblingListBlocks( listHead, 'backward' ) ) {
33
+ // Previously, the loop below was defined like this:
34
+ //
35
+ // for ( { node: listHead } of iterateSiblingListBlocks( listHead, 'backward' ) )
36
+ //
37
+ // Unfortunately, such a destructuring is incorrectly transpiled by Babel and the loop never ends.
38
+ // See: https://github.com/ckeditor/ckeditor5-react/issues/345.
39
+ for ( const { node } of iterateSiblingListBlocks( listHead, 'backward' ) ) {
40
+ listHead = node;
41
+
34
42
  if ( itemToListHead.has( listHead ) ) {
35
43
  return;
36
44
  }
@@ -20,6 +20,7 @@ import {
20
20
  getListStyleTypeFromTypeAttribute,
21
21
  getTypeAttributeFromListStyleType
22
22
  } from './utils/style';
23
+ import DocumentListPropertiesUtils from './documentlistpropertiesutils';
23
24
 
24
25
  const DEFAULT_LIST_TYPE = 'default';
25
26
 
@@ -36,7 +37,7 @@ export default class DocumentListPropertiesEditing extends Plugin {
36
37
  * @inheritDoc
37
38
  */
38
39
  static get requires() {
39
- return [ DocumentListEditing ];
40
+ return [ DocumentListEditing, DocumentListPropertiesUtils ];
40
41
  }
41
42
 
42
43
  /**
@@ -360,7 +361,7 @@ function createAttributeStrategies( enabledProperties ) {
360
361
  },
361
362
 
362
363
  setAttributeOnDowncast( writer, listStart, element ) {
363
- if ( listStart && listStart > 1 ) {
364
+ if ( listStart == 0 || listStart > 1 ) {
364
365
  writer.setAttribute( 'start', listStart, element );
365
366
  } else {
366
367
  writer.removeAttribute( 'start', element );
@@ -368,7 +369,9 @@ function createAttributeStrategies( enabledProperties ) {
368
369
  },
369
370
 
370
371
  getAttributeOnUpcast( listParent ) {
371
- return listParent.getAttribute( 'start' ) || 1;
372
+ const startAttributeValue = listParent.getAttribute( 'start' );
373
+
374
+ return startAttributeValue >= 0 ? startAttributeValue : 1;
372
375
  }
373
376
  } );
374
377
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/documentlist/documentlistpropertiesutils
8
+ */
9
+
10
+ import { Plugin } from 'ckeditor5/src/core';
11
+ import {
12
+ getAllSupportedStyleTypes,
13
+ getListStyleTypeFromTypeAttribute,
14
+ getListTypeFromListStyleType,
15
+ getTypeAttributeFromListStyleType
16
+ } from './utils/style';
17
+
18
+ /**
19
+ * A set of helpers related to document lists.
20
+ *
21
+ * @extends module:core/plugin~Plugin
22
+ */
23
+ export default class DocumentListPropertiesUtils extends Plugin {
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'DocumentListPropertiesUtils';
29
+ }
30
+
31
+ /**
32
+ * Gets all the style types supported by given list type.
33
+ *
34
+ * @returns {Array.<String>}
35
+ */
36
+ getAllSupportedStyleTypes() {
37
+ return getAllSupportedStyleTypes();
38
+ }
39
+
40
+ /**
41
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
42
+ *
43
+ * @param {String} listStyleType
44
+ * @returns {'bulleted'|'numbered'|null}
45
+ */
46
+ getListTypeFromListStyleType( listStyleType ) {
47
+ return getListTypeFromListStyleType( listStyleType );
48
+ }
49
+
50
+ /**
51
+ * Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
52
+ *
53
+ * @param {String} value
54
+ * @returns {String|null}
55
+ */
56
+ getListStyleTypeFromTypeAttribute( value ) {
57
+ return getListStyleTypeFromTypeAttribute( value );
58
+ }
59
+
60
+ /**
61
+ * Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
62
+ *
63
+ * @param {String} value
64
+ * @returns {String|null}
65
+ */
66
+ getTypeAttributeFromListStyleType( value ) {
67
+ return getTypeAttributeFromListStyleType( value );
68
+ }
69
+ }
@@ -50,7 +50,7 @@ export default class DocumentListStartCommand extends Command {
50
50
 
51
51
  model.change( writer => {
52
52
  for ( const block of blocks ) {
53
- writer.setAttribute( 'listStart', options.startIndex || 1, block );
53
+ writer.setAttribute( 'listStart', options.startIndex >= 0 ? options.startIndex : 1, block );
54
54
  }
55
55
  } );
56
56
  }
package/src/index.js CHANGED
@@ -11,10 +11,13 @@ export { default as DocumentList } from './documentlist';
11
11
  export { default as DocumentListEditing } from './documentlist/documentlistediting';
12
12
  export { default as DocumentListProperties } from './documentlistproperties';
13
13
  export { default as DocumentListPropertiesEditing } from './documentlistproperties/documentlistpropertiesediting';
14
+ export { default as DocumentListUtils } from './documentlist/documentlistutils';
15
+ export { default as DocumentListPropertiesUtils } from './documentlistproperties/documentlistpropertiesutils';
14
16
  export { default as List } from './list';
15
17
  export { default as ListEditing } from './list/listediting';
16
18
  export { default as ListUI } from './list/listui';
17
19
  export { default as ListProperties } from './listproperties';
20
+ export { default as ListUtils } from './list/listutils';
18
21
  export { default as ListPropertiesEditing } from './listproperties/listpropertiesediting';
19
22
  export { default as ListPropertiesUI } from './listproperties/listpropertiesui';
20
23
  export { default as TodoList } from './todolist';
@@ -9,6 +9,7 @@
9
9
 
10
10
  import ListCommand from './listcommand';
11
11
  import IndentCommand from './indentcommand';
12
+ import ListUtils from './listutils';
12
13
 
13
14
  import { Plugin } from 'ckeditor5/src/core';
14
15
  import { Enter } from 'ckeditor5/src/enter';
@@ -50,7 +51,7 @@ export default class ListEditing extends Plugin {
50
51
  * @inheritDoc
51
52
  */
52
53
  static get requires() {
53
- return [ Enter, Delete ];
54
+ return [ Enter, Delete, ListUtils ];
54
55
  }
55
56
 
56
57
  /**
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/list/listutils
8
+ */
9
+
10
+ import { Plugin } from 'ckeditor5/src/core';
11
+ import {
12
+ getListTypeFromListStyleType,
13
+ getSelectedListItems,
14
+ getSiblingNodes
15
+ } from './utils';
16
+
17
+ /**
18
+ * A set of helpers related to document lists.
19
+ *
20
+ * @extends module:core/plugin~Plugin
21
+ */
22
+ export default class ListUtils extends Plugin {
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get pluginName() {
27
+ return 'ListUtils';
28
+ }
29
+
30
+ /**
31
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
32
+ *
33
+ * @param {String} listStyleType
34
+ * @returns {'bulleted'|'numbered'|null}
35
+ */
36
+ getListTypeFromListStyleType( listStyleType ) {
37
+ return getListTypeFromListStyleType( listStyleType );
38
+ }
39
+
40
+ /**
41
+ * Returns an array with all `listItem` elements in the model selection.
42
+ *
43
+ * It returns all the items even if only a part of the list is selected, including items that belong to nested lists.
44
+ * If no list is selected, it returns an empty array.
45
+ * The order of the elements is not specified.
46
+ *
47
+ * @param {module:engine/model/model~Model} model
48
+ * @returns {Array.<module:engine/model/element~Element>}
49
+ */
50
+ getSelectedListItems( model ) {
51
+ return getSelectedListItems( model );
52
+ }
53
+
54
+ /**
55
+ * Returns an array with all `listItem` elements that represent the same list.
56
+ *
57
+ * It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
58
+ *
59
+ * Additionally, if the `position` is inside a list item, that list item will be returned as well.
60
+ *
61
+ * @param {module:engine/model/position~Position} position Starting position.
62
+ * @param {'forward'|'backward'} direction Walking direction.
63
+ * @returns {Array.<module:engine/model/element~Element>}
64
+ */
65
+ getSiblingNodes( position, direction ) {
66
+ return getSiblingNodes( position, direction );
67
+ }
68
+ }
@@ -335,7 +335,7 @@ function createAttributeStrategies( enabledProperties ) {
335
335
  },
336
336
 
337
337
  setAttributeOnDowncast( writer, listStart, element ) {
338
- if ( listStart != 1 ) {
338
+ if ( listStart == 0 || listStart > 1 ) {
339
339
  writer.setAttribute( 'start', listStart, element );
340
340
  } else {
341
341
  writer.removeAttribute( 'start', element );
@@ -343,7 +343,9 @@ function createAttributeStrategies( enabledProperties ) {
343
343
  },
344
344
 
345
345
  getAttributeOnUpcast( listParent ) {
346
- return listParent.getAttribute( 'start' ) || 1;
346
+ const startAttributeValue = listParent.getAttribute( 'start' );
347
+
348
+ return startAttributeValue >= 0 ? startAttributeValue : 1;
347
349
  }
348
350
  } );
349
351
  }
@@ -40,7 +40,7 @@ export default class ListStartCommand extends Command {
40
40
 
41
41
  model.change( writer => {
42
42
  for ( const item of listItems ) {
43
- writer.setAttribute( 'listStart', options.startIndex || 1, item );
43
+ writer.setAttribute( 'listStart', options.startIndex >= 0 ? options.startIndex : 1, item );
44
44
  }
45
45
  } );
46
46
  }
@@ -203,7 +203,8 @@ export default class ListPropertiesView extends View {
203
203
  .getComputedStyle( this.stylesView.element )
204
204
  .getPropertyValue( 'grid-template-columns' )
205
205
  .split( ' ' )
206
- .length
206
+ .length,
207
+ uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
207
208
  } );
208
209
  }
209
210
 
@@ -368,7 +369,7 @@ export default class ListPropertiesView extends View {
368
369
  } );
369
370
 
370
371
  startIndexFieldView.fieldView.set( {
371
- min: 1,
372
+ min: 0,
372
373
  step: 1,
373
374
  value: 1,
374
375
  inputMode: 'numeric'