@ckeditor/ckeditor5-indent 47.5.0 → 47.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-indent",
3
- "version": "47.5.0",
3
+ "version": "47.6.0-alpha.0",
4
4
  "description": "Block indentation feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,14 +13,14 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "@ckeditor/ckeditor5-core": "47.5.0",
17
- "@ckeditor/ckeditor5-engine": "47.5.0",
18
- "@ckeditor/ckeditor5-icons": "47.5.0",
19
- "@ckeditor/ckeditor5-heading": "47.5.0",
20
- "@ckeditor/ckeditor5-list": "47.5.0",
21
- "@ckeditor/ckeditor5-ui": "47.5.0",
22
- "@ckeditor/ckeditor5-utils": "47.5.0",
23
- "ckeditor5": "47.5.0"
16
+ "@ckeditor/ckeditor5-core": "47.6.0-alpha.0",
17
+ "@ckeditor/ckeditor5-engine": "47.6.0-alpha.0",
18
+ "@ckeditor/ckeditor5-icons": "47.6.0-alpha.0",
19
+ "@ckeditor/ckeditor5-heading": "47.6.0-alpha.0",
20
+ "@ckeditor/ckeditor5-list": "47.6.0-alpha.0",
21
+ "@ckeditor/ckeditor5-ui": "47.6.0-alpha.0",
22
+ "@ckeditor/ckeditor5-utils": "47.6.0-alpha.0",
23
+ "ckeditor5": "47.6.0-alpha.0"
24
24
  },
25
25
  "author": "CKSource (http://cksource.com/)",
26
26
  "license": "SEE LICENSE IN LICENSE.md",
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- import type { IndentBlockConfig, Indent, IndentBlock, IndentUI, IndentBlockCommand } from './index.js';
5
+ import type { IndentBlockConfig, Indent, IndentBlock, IndentUI, IndentBlockCommand, IndentBlockListIntegration, IndentBlockListCommand, IndentBlockListItemCommand } from './index.js';
6
6
  declare module '@ckeditor/ckeditor5-core' {
7
7
  interface EditorConfig {
8
8
  /**
@@ -16,9 +16,14 @@ declare module '@ckeditor/ckeditor5-core' {
16
16
  [Indent.pluginName]: Indent;
17
17
  [IndentBlock.pluginName]: IndentBlock;
18
18
  [IndentUI.pluginName]: IndentUI;
19
+ [IndentBlockListIntegration.pluginName]: IndentBlockListIntegration;
19
20
  }
20
21
  interface CommandsMap {
21
22
  indentBlock: IndentBlockCommand;
22
23
  outdentBlock: IndentBlockCommand;
24
+ indentBlockList: IndentBlockListCommand;
25
+ outdentBlockList: IndentBlockListCommand;
26
+ indentBlockListItem: IndentBlockListItemCommand;
27
+ outdentBlockListItem: IndentBlockListItemCommand;
23
28
  }
24
29
  }
@@ -6,6 +6,7 @@
6
6
  * @module indent/indentblock
7
7
  */
8
8
  import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ import { IndentBlockListIntegration } from './integrations/indentblocklistintegration.js';
9
10
  /**
10
11
  * The block indentation feature.
11
12
  *
@@ -27,6 +28,10 @@ export declare class IndentBlock extends Plugin {
27
28
  * @inheritDoc
28
29
  */
29
30
  static get isOfficialPlugin(): true;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ static get requires(): readonly [typeof IndentBlockListIntegration];
30
35
  /**
31
36
  * @inheritDoc
32
37
  */
@@ -10,6 +10,7 @@ import { addMarginStylesRules } from 'ckeditor5/src/engine.js';
10
10
  import { IndentBlockCommand } from './indentblockcommand.js';
11
11
  import { IndentUsingOffset } from './indentcommandbehavior/indentusingoffset.js';
12
12
  import { IndentUsingClasses } from './indentcommandbehavior/indentusingclasses.js';
13
+ import { IndentBlockListIntegration } from './integrations/indentblocklistintegration.js';
13
14
  const DEFAULT_ELEMENTS = ['paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6'];
14
15
  /**
15
16
  * The block indentation feature.
@@ -42,6 +43,12 @@ export class IndentBlock extends Plugin {
42
43
  static get isOfficialPlugin() {
43
44
  return true;
44
45
  }
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ static get requires() {
50
+ return [IndentBlockListIntegration];
51
+ }
45
52
  /**
46
53
  * @inheritDoc
47
54
  */
@@ -44,6 +44,8 @@ export class IndentUsingClasses {
44
44
  getNextIndent(indentAttributeValue) {
45
45
  const currentIndex = this.classes.indexOf(indentAttributeValue);
46
46
  const indexStep = this.isForward ? 1 : -1;
47
- return this.classes[currentIndex + indexStep];
47
+ const nextIndex = currentIndex + indexStep;
48
+ const nextIndexClamped = Math.min(nextIndex, this.classes.length - 1);
49
+ return this.classes[nextIndexClamped];
48
50
  }
49
51
  }
@@ -46,6 +46,9 @@ export class IndentUsingOffset {
46
46
  getNextIndent(indentAttributeValue) {
47
47
  const currentOffset = parseFloat(indentAttributeValue || '0');
48
48
  const isSameUnit = !indentAttributeValue || indentAttributeValue.endsWith(this.unit);
49
+ if (currentOffset < 0) {
50
+ return;
51
+ }
49
52
  if (!isSameUnit) {
50
53
  return this.isForward ? this.offset + this.unit : undefined;
51
54
  }
package/src/index.d.ts CHANGED
@@ -10,6 +10,9 @@ export { IndentEditing } from './indentediting.js';
10
10
  export { IndentUI } from './indentui.js';
11
11
  export { IndentBlock } from './indentblock.js';
12
12
  export { IndentBlockCommand } from './indentblockcommand.js';
13
+ export { IndentBlockListIntegration } from './integrations/indentblocklistintegration.js';
14
+ export { IndentBlockListCommand } from './integrations/indentblocklistcommand.js';
15
+ export { IndentBlockListItemCommand } from './integrations/indentblocklistitemcommand.js';
13
16
  export type { IndentBlockConfig } from './indentconfig.js';
14
17
  export type { IndentBehavior } from './indentcommandbehavior/indentbehavior.js';
15
18
  export { IndentUsingClasses as _IndentUsingClasses } from './indentcommandbehavior/indentusingclasses.js';
package/src/index.js CHANGED
@@ -10,6 +10,9 @@ export { IndentEditing } from './indentediting.js';
10
10
  export { IndentUI } from './indentui.js';
11
11
  export { IndentBlock } from './indentblock.js';
12
12
  export { IndentBlockCommand } from './indentblockcommand.js';
13
+ export { IndentBlockListIntegration } from './integrations/indentblocklistintegration.js';
14
+ export { IndentBlockListCommand } from './integrations/indentblocklistcommand.js';
15
+ export { IndentBlockListItemCommand } from './integrations/indentblocklistitemcommand.js';
13
16
  export { IndentUsingClasses as _IndentUsingClasses } from './indentcommandbehavior/indentusingclasses.js';
14
17
  export { IndentUsingOffset as _IndentUsingOffset } from './indentcommandbehavior/indentusingoffset.js';
15
18
  import './augmentation.js';
@@ -0,0 +1,60 @@
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
+ /**
6
+ * @module indent/integrations/indentblocklistcommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core.js';
9
+ import type { IndentBehavior } from '../indentcommandbehavior/indentbehavior.js';
10
+ /**
11
+ * The indent block list command.
12
+ *
13
+ * The command is registered by the {@link module:indent/integrations/indentblocklistintegration~IndentBlockListIntegration} as
14
+ * `'indentBlockList'` for indenting lists and `'outdentBlockList'` for outdenting lists.
15
+ *
16
+ * To increase/decrease block indentation of the list the selection must be at the start of the first top–level list item
17
+ * in the list.
18
+ *
19
+ * To increase block indentation of the list, execute the command:
20
+ *
21
+ * ```ts
22
+ * editor.execute( 'indentBlockList' );
23
+ * ```
24
+ *
25
+ * To decrease block indentation of the list, execute the command:
26
+ *
27
+ * ```ts
28
+ * editor.execute( 'outdentBlockList' );
29
+ * ```
30
+ */
31
+ export declare class IndentBlockListCommand extends Command {
32
+ /**
33
+ * The command's indentation behavior.
34
+ */
35
+ private readonly _indentBehavior;
36
+ /**
37
+ * Creates an instance of the command.
38
+ */
39
+ constructor(editor: Editor, indentBehavior: IndentBehavior);
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ refresh(): void;
44
+ /**
45
+ * Executes the command.
46
+ *
47
+ * @fires execute
48
+ * @param options Command options.
49
+ * @param options.firstListOnly When `true`, indentation is applied only to the first list at the beginning of the selection.
50
+ * When `false` or omitted, indentation is applied to all lists of the selection.
51
+ */
52
+ execute(options?: {
53
+ firstListOnly?: boolean;
54
+ }): void;
55
+ /**
56
+ * Returns the list item at the beginning of the current selection if it is the first top–level list item in the list.
57
+ * Otherwise, returns `null`.
58
+ */
59
+ private _getFirstListItemIfSelectionIsAtListStart;
60
+ }
@@ -0,0 +1,108 @@
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
+ /**
6
+ * @module indent/integrations/indentblocklistcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core.js';
9
+ import { _isListItemBlock } from '@ckeditor/ckeditor5-list';
10
+ /**
11
+ * The indent block list command.
12
+ *
13
+ * The command is registered by the {@link module:indent/integrations/indentblocklistintegration~IndentBlockListIntegration} as
14
+ * `'indentBlockList'` for indenting lists and `'outdentBlockList'` for outdenting lists.
15
+ *
16
+ * To increase/decrease block indentation of the list the selection must be at the start of the first top–level list item
17
+ * in the list.
18
+ *
19
+ * To increase block indentation of the list, execute the command:
20
+ *
21
+ * ```ts
22
+ * editor.execute( 'indentBlockList' );
23
+ * ```
24
+ *
25
+ * To decrease block indentation of the list, execute the command:
26
+ *
27
+ * ```ts
28
+ * editor.execute( 'outdentBlockList' );
29
+ * ```
30
+ */
31
+ export class IndentBlockListCommand extends Command {
32
+ /**
33
+ * The command's indentation behavior.
34
+ */
35
+ _indentBehavior;
36
+ /**
37
+ * Creates an instance of the command.
38
+ */
39
+ constructor(editor, indentBehavior) {
40
+ super(editor);
41
+ this._indentBehavior = indentBehavior;
42
+ }
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ refresh() {
47
+ const listItem = this._getFirstListItemIfSelectionIsAtListStart(this.editor.model.document.selection);
48
+ this.isEnabled = !!listItem && this._indentBehavior.checkEnabled(listItem.getAttribute('blockIndentList'));
49
+ }
50
+ /**
51
+ * Executes the command.
52
+ *
53
+ * @fires execute
54
+ * @param options Command options.
55
+ * @param options.firstListOnly When `true`, indentation is applied only to the first list at the beginning of the selection.
56
+ * When `false` or omitted, indentation is applied to all lists of the selection.
57
+ */
58
+ execute(options = {}) {
59
+ const editor = this.editor;
60
+ const model = editor.model;
61
+ const selection = model.document.selection;
62
+ model.change(writer => {
63
+ const listItem = this._getFirstListItemIfSelectionIsAtListStart(selection);
64
+ const listItems = [];
65
+ if (!options.firstListOnly) {
66
+ const blocks = Array.from(selection.getSelectedBlocks());
67
+ for (const block of blocks) {
68
+ if (_isListItemBlock(block) &&
69
+ block.getAttribute('listIndent') === 0 &&
70
+ model.schema.checkAttribute(block, 'blockIndentList')) {
71
+ listItems.push(block);
72
+ }
73
+ }
74
+ }
75
+ else {
76
+ listItems.push(listItem);
77
+ }
78
+ for (const item of listItems) {
79
+ const currentIndent = item.getAttribute('blockIndentList');
80
+ const nextIndent = this._indentBehavior.getNextIndent(currentIndent);
81
+ if (nextIndent) {
82
+ writer.setAttribute('blockIndentList', nextIndent, item);
83
+ }
84
+ else {
85
+ writer.removeAttribute('blockIndentList', item);
86
+ }
87
+ }
88
+ });
89
+ }
90
+ /**
91
+ * Returns the list item at the beginning of the current selection if it is the first top–level list item in the list.
92
+ * Otherwise, returns `null`.
93
+ */
94
+ _getFirstListItemIfSelectionIsAtListStart(selection) {
95
+ const position = selection.getFirstPosition();
96
+ const listUtils = this.editor.plugins.get('ListUtils');
97
+ const parent = position.parent;
98
+ const schema = this.editor.model.schema;
99
+ if (position.isAtStart &&
100
+ _isListItemBlock(parent) &&
101
+ parent.getAttribute('listIndent') == 0 &&
102
+ schema.checkAttribute(parent, 'blockIndentList') &&
103
+ listUtils.isFirstListItemInList(parent)) {
104
+ return parent;
105
+ }
106
+ return null;
107
+ }
108
+ }
@@ -0,0 +1,42 @@
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 { Plugin } from 'ckeditor5/src/core.js';
6
+ /**
7
+ * This integration enables using block indentation feature with lists.
8
+ */
9
+ export declare class IndentBlockListIntegration extends Plugin {
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ static get pluginName(): "IndentBlockListIntegration";
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get isOfficialPlugin(): true;
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ init(): void;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ afterInit(): void;
26
+ /**
27
+ * Setups conversion for list block indent using offset indents.
28
+ */
29
+ private _setupConversionUsingOffsetForListBlock;
30
+ /**
31
+ * Setups conversion for list item block indent using offset indents.
32
+ */
33
+ private _setupConversionUsingOffsetForListItemBlock;
34
+ /**
35
+ * Setups conversion for list block indent using classes.
36
+ */
37
+ private _setupConversionUsingClassesForListBlock;
38
+ /**
39
+ * Setups conversion for list item block indent using classes.
40
+ */
41
+ private _setupConversionUsingClassesForListItemBlock;
42
+ }