@ckeditor/ckeditor5-list 42.0.2 → 43.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.
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/listproperties/utils/config
7
+ */
8
+ import { toArray } from 'ckeditor5/src/utils.js';
9
+ /**
10
+ * Normalizes {@link module:list/listconfig~ListPropertiesConfig} in the configuration of the list properties feature.
11
+ * The structure of normalized list properties options looks as follows:
12
+ *
13
+ * ```ts
14
+ * {
15
+ * styles: {
16
+ * listTypes: [ 'bulleted', 'numbered' ],
17
+ * useAttribute: false
18
+ * },
19
+ * startIndex: true,
20
+ * reversed: true
21
+ * }
22
+ * ```
23
+ *
24
+ * @param config The list properties {@link module:list/listconfig~ListPropertiesConfig config}.
25
+ * @returns An object with normalized list properties options.
26
+ */
27
+ export function getNormalizedConfig(config) {
28
+ const { startIndex, reversed, styles } = config;
29
+ return {
30
+ styles: getNormalizedStylesConfig(styles),
31
+ startIndex: startIndex || false,
32
+ reversed: reversed || false
33
+ };
34
+ }
35
+ /**
36
+ * Normalizes styles in the configuration of the list properties feature.
37
+ * The structure of normalized list properties options looks as follows:
38
+ *
39
+ * ```ts
40
+ * {
41
+ * listTypes: [ 'bulleted', 'numbered' ],
42
+ * useAttribute: false
43
+ * }
44
+ * ```
45
+ *
46
+ * @param styles The list properties styles.
47
+ * @returns An object with normalized list properties styles.
48
+ */
49
+ function getNormalizedStylesConfig(styles) {
50
+ const normalizedConfig = {
51
+ listTypes: ['bulleted', 'numbered'],
52
+ useAttribute: false
53
+ };
54
+ if (styles === true) {
55
+ return normalizedConfig;
56
+ }
57
+ if (!styles) {
58
+ normalizedConfig.listTypes = [];
59
+ }
60
+ else if (Array.isArray(styles) || typeof styles == 'string') {
61
+ normalizedConfig.listTypes = toArray(styles);
62
+ }
63
+ else {
64
+ normalizedConfig.listTypes = styles.listTypes ?
65
+ toArray(styles.listTypes) :
66
+ normalizedConfig.listTypes;
67
+ normalizedConfig.useAttribute = !!styles.useAttribute;
68
+ }
69
+ return normalizedConfig;
70
+ }
@@ -50,15 +50,13 @@ export default class TodoListEditing extends Plugin {
50
50
  editor.commands.add('checkTodoList', new CheckTodoListCommand(editor));
51
51
  editing.view.addObserver(TodoCheckboxChangeObserver);
52
52
  model.schema.extend('$listItem', { allowAttributes: 'todoListChecked' });
53
- model.schema.addAttributeCheck((context, attributeName) => {
53
+ model.schema.addAttributeCheck(context => {
54
54
  const item = context.last;
55
- if (attributeName != 'todoListChecked') {
56
- return;
57
- }
55
+ // Don't allow `todoListChecked` attribute on elements which are not todo list items.
58
56
  if (!item.getAttribute('listItemId') || item.getAttribute('listType') != 'todo') {
59
57
  return false;
60
58
  }
61
- });
59
+ }, 'todoListChecked');
62
60
  editor.conversion.for('upcast').add(dispatcher => {
63
61
  // Upcast of to-do list item is based on a checkbox at the beginning of a <li> to keep compatibility with markdown input.
64
62
  dispatcher.on('element:input', todoItemInputConverter());