@ckeditor/ckeditor5-indent 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.
@@ -1,56 +1,56 @@
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 indent/indentblockcommand
7
- */
8
- import { Command, type Editor } from 'ckeditor5/src/core';
9
- import type { IndentBehavior } from './indentcommandbehavior/indentbehavior';
10
- /**
11
- * The indent block command.
12
- *
13
- * The command is registered by the {@link module:indent/indentblock~IndentBlock} as `'indentBlock'` for indenting blocks and
14
- * `'outdentBlock'` for outdenting blocks.
15
- *
16
- * To increase block indentation at the current selection, execute the command:
17
- *
18
- * ```ts
19
- * editor.execute( 'indentBlock' );
20
- * ```
21
- *
22
- * To decrease block indentation at the current selection, execute the command:
23
- *
24
- * ```ts
25
- * editor.execute( 'outdentBlock' );
26
- * ```
27
- */
28
- export default class IndentBlockCommand extends Command {
29
- /**
30
- * The command's indentation behavior.
31
- */
32
- private readonly _indentBehavior;
33
- /**
34
- * Creates an instance of the command.
35
- */
36
- constructor(editor: Editor, indentBehavior: IndentBehavior);
37
- /**
38
- * @inheritDoc
39
- */
40
- refresh(): void;
41
- /**
42
- * @inheritDoc
43
- */
44
- execute(): void;
45
- /**
46
- * Returns blocks from selection that should have blockIndent selection set.
47
- */
48
- private _getBlocksToChange;
49
- /**
50
- * Returns false if indentation cannot be applied, i.e.:
51
- * - for blocks disallowed by schema declaration
52
- * - for blocks in Document Lists (disallowed forward indentation only). See https://github.com/ckeditor/ckeditor5/issues/14155.
53
- * Otherwise returns true.
54
- */
55
- private _isIndentationChangeAllowed;
56
- }
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 indent/indentblockcommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ import type { IndentBehavior } from './indentcommandbehavior/indentbehavior';
10
+ /**
11
+ * The indent block command.
12
+ *
13
+ * The command is registered by the {@link module:indent/indentblock~IndentBlock} as `'indentBlock'` for indenting blocks and
14
+ * `'outdentBlock'` for outdenting blocks.
15
+ *
16
+ * To increase block indentation at the current selection, execute the command:
17
+ *
18
+ * ```ts
19
+ * editor.execute( 'indentBlock' );
20
+ * ```
21
+ *
22
+ * To decrease block indentation at the current selection, execute the command:
23
+ *
24
+ * ```ts
25
+ * editor.execute( 'outdentBlock' );
26
+ * ```
27
+ */
28
+ export default class IndentBlockCommand extends Command {
29
+ /**
30
+ * The command's indentation behavior.
31
+ */
32
+ private readonly _indentBehavior;
33
+ /**
34
+ * Creates an instance of the command.
35
+ */
36
+ constructor(editor: Editor, indentBehavior: IndentBehavior);
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ refresh(): void;
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ execute(): void;
45
+ /**
46
+ * Returns blocks from selection that should have blockIndent selection set.
47
+ */
48
+ private _getBlocksToChange;
49
+ /**
50
+ * Returns false if indentation cannot be applied, i.e.:
51
+ * - for blocks disallowed by schema declaration
52
+ * - for blocks in Document Lists (disallowed forward indentation only). See https://github.com/ckeditor/ckeditor5/issues/14155.
53
+ * Otherwise returns true.
54
+ */
55
+ private _isIndentationChangeAllowed;
56
+ }
@@ -1,98 +1,98 @@
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 indent/indentblockcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- import { first } from 'ckeditor5/src/utils';
10
- /**
11
- * The indent block command.
12
- *
13
- * The command is registered by the {@link module:indent/indentblock~IndentBlock} as `'indentBlock'` for indenting blocks and
14
- * `'outdentBlock'` for outdenting blocks.
15
- *
16
- * To increase block indentation at the current selection, execute the command:
17
- *
18
- * ```ts
19
- * editor.execute( 'indentBlock' );
20
- * ```
21
- *
22
- * To decrease block indentation at the current selection, execute the command:
23
- *
24
- * ```ts
25
- * editor.execute( 'outdentBlock' );
26
- * ```
27
- */
28
- export default class IndentBlockCommand extends Command {
29
- /**
30
- * Creates an instance of the command.
31
- */
32
- constructor(editor, indentBehavior) {
33
- super(editor);
34
- this._indentBehavior = indentBehavior;
35
- }
36
- /**
37
- * @inheritDoc
38
- */
39
- refresh() {
40
- const editor = this.editor;
41
- const model = editor.model;
42
- const block = first(model.document.selection.getSelectedBlocks());
43
- if (!block || !this._isIndentationChangeAllowed(block)) {
44
- this.isEnabled = false;
45
- return;
46
- }
47
- this.isEnabled = this._indentBehavior.checkEnabled(block.getAttribute('blockIndent'));
48
- }
49
- /**
50
- * @inheritDoc
51
- */
52
- execute() {
53
- const model = this.editor.model;
54
- const blocksToChange = this._getBlocksToChange();
55
- model.change(writer => {
56
- for (const block of blocksToChange) {
57
- const currentIndent = block.getAttribute('blockIndent');
58
- const nextIndent = this._indentBehavior.getNextIndent(currentIndent);
59
- if (nextIndent) {
60
- writer.setAttribute('blockIndent', nextIndent, block);
61
- }
62
- else {
63
- writer.removeAttribute('blockIndent', block);
64
- }
65
- }
66
- });
67
- }
68
- /**
69
- * Returns blocks from selection that should have blockIndent selection set.
70
- */
71
- _getBlocksToChange() {
72
- const model = this.editor.model;
73
- const selection = model.document.selection;
74
- const blocksInSelection = Array.from(selection.getSelectedBlocks());
75
- return blocksInSelection.filter(block => this._isIndentationChangeAllowed(block));
76
- }
77
- /**
78
- * Returns false if indentation cannot be applied, i.e.:
79
- * - for blocks disallowed by schema declaration
80
- * - for blocks in Document Lists (disallowed forward indentation only). See https://github.com/ckeditor/ckeditor5/issues/14155.
81
- * Otherwise returns true.
82
- */
83
- _isIndentationChangeAllowed(element) {
84
- const editor = this.editor;
85
- if (!editor.model.schema.checkAttribute(element, 'blockIndent')) {
86
- return false;
87
- }
88
- if (!editor.plugins.has('DocumentListUtils')) {
89
- return true;
90
- }
91
- // Only forward indentation is disallowed in list items. This allows the user to outdent blocks that are already indented.
92
- if (!this._indentBehavior.isForward) {
93
- return true;
94
- }
95
- const documentListUtils = editor.plugins.get('DocumentListUtils');
96
- return !documentListUtils.isListItemBlock(element);
97
- }
98
- }
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 indent/indentblockcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ import { first } from 'ckeditor5/src/utils';
10
+ /**
11
+ * The indent block command.
12
+ *
13
+ * The command is registered by the {@link module:indent/indentblock~IndentBlock} as `'indentBlock'` for indenting blocks and
14
+ * `'outdentBlock'` for outdenting blocks.
15
+ *
16
+ * To increase block indentation at the current selection, execute the command:
17
+ *
18
+ * ```ts
19
+ * editor.execute( 'indentBlock' );
20
+ * ```
21
+ *
22
+ * To decrease block indentation at the current selection, execute the command:
23
+ *
24
+ * ```ts
25
+ * editor.execute( 'outdentBlock' );
26
+ * ```
27
+ */
28
+ export default class IndentBlockCommand extends Command {
29
+ /**
30
+ * Creates an instance of the command.
31
+ */
32
+ constructor(editor, indentBehavior) {
33
+ super(editor);
34
+ this._indentBehavior = indentBehavior;
35
+ }
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ refresh() {
40
+ const editor = this.editor;
41
+ const model = editor.model;
42
+ const block = first(model.document.selection.getSelectedBlocks());
43
+ if (!block || !this._isIndentationChangeAllowed(block)) {
44
+ this.isEnabled = false;
45
+ return;
46
+ }
47
+ this.isEnabled = this._indentBehavior.checkEnabled(block.getAttribute('blockIndent'));
48
+ }
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ execute() {
53
+ const model = this.editor.model;
54
+ const blocksToChange = this._getBlocksToChange();
55
+ model.change(writer => {
56
+ for (const block of blocksToChange) {
57
+ const currentIndent = block.getAttribute('blockIndent');
58
+ const nextIndent = this._indentBehavior.getNextIndent(currentIndent);
59
+ if (nextIndent) {
60
+ writer.setAttribute('blockIndent', nextIndent, block);
61
+ }
62
+ else {
63
+ writer.removeAttribute('blockIndent', block);
64
+ }
65
+ }
66
+ });
67
+ }
68
+ /**
69
+ * Returns blocks from selection that should have blockIndent selection set.
70
+ */
71
+ _getBlocksToChange() {
72
+ const model = this.editor.model;
73
+ const selection = model.document.selection;
74
+ const blocksInSelection = Array.from(selection.getSelectedBlocks());
75
+ return blocksInSelection.filter(block => this._isIndentationChangeAllowed(block));
76
+ }
77
+ /**
78
+ * Returns false if indentation cannot be applied, i.e.:
79
+ * - for blocks disallowed by schema declaration
80
+ * - for blocks in Document Lists (disallowed forward indentation only). See https://github.com/ckeditor/ckeditor5/issues/14155.
81
+ * Otherwise returns true.
82
+ */
83
+ _isIndentationChangeAllowed(element) {
84
+ const editor = this.editor;
85
+ if (!editor.model.schema.checkAttribute(element, 'blockIndent')) {
86
+ return false;
87
+ }
88
+ if (!editor.plugins.has('DocumentListUtils')) {
89
+ return true;
90
+ }
91
+ // Only forward indentation is disallowed in list items. This allows the user to outdent blocks that are already indented.
92
+ if (!this._indentBehavior.isForward) {
93
+ return true;
94
+ }
95
+ const documentListUtils = editor.plugins.get('DocumentListUtils');
96
+ return !documentListUtils.isListItemBlock(element);
97
+ }
98
+ }
@@ -1,25 +1,25 @@
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 indent/indentcommandbehavior/indentbehavior
7
- */
8
- /**
9
- * Provides indentation behavior to {@link module:indent/indentblockcommand~IndentBlockCommand}.
10
- */
11
- export interface IndentBehavior {
12
- /**
13
- * The direction of indentation.
14
- */
15
- isForward: boolean;
16
- /**
17
- * Checks if the command should be enabled.
18
- */
19
- checkEnabled: (indentAttributeValue: string) => boolean;
20
- /**
21
- * Returns a new indent attribute value based on the current indent.
22
- * This method returns `undefined` when the indentation should be removed.
23
- */
24
- getNextIndent: (indentAttributeValue: string) => string | undefined;
25
- }
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 indent/indentcommandbehavior/indentbehavior
7
+ */
8
+ /**
9
+ * Provides indentation behavior to {@link module:indent/indentblockcommand~IndentBlockCommand}.
10
+ */
11
+ export interface IndentBehavior {
12
+ /**
13
+ * The direction of indentation.
14
+ */
15
+ isForward: boolean;
16
+ /**
17
+ * Checks if the command should be enabled.
18
+ */
19
+ checkEnabled: (indentAttributeValue: string) => boolean;
20
+ /**
21
+ * Returns a new indent attribute value based on the current indent.
22
+ * This method returns `undefined` when the indentation should be removed.
23
+ */
24
+ getNextIndent: (indentAttributeValue: string) => string | undefined;
25
+ }
@@ -1,5 +1,5 @@
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
- export {};
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
+ export {};
@@ -1,39 +1,39 @@
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 indent/indentcommandbehavior/indentusingclasses
7
- */
8
- import type { IndentBehavior } from './indentbehavior';
9
- /**
10
- * The block indentation behavior that uses classes to set indentation.
11
- */
12
- export default class IndentUsingClasses implements IndentBehavior {
13
- /**
14
- * The direction of indentation.
15
- */
16
- isForward: boolean;
17
- /**
18
- * A list of classes used for indentation.
19
- */
20
- classes: Array<string>;
21
- /**
22
- * Creates an instance of the indentation behavior.
23
- *
24
- * @param config.direction The direction of indentation.
25
- * @param config.classes A list of classes used for indentation.
26
- */
27
- constructor(config: {
28
- direction: 'forward' | 'backward';
29
- classes: Array<string>;
30
- });
31
- /**
32
- * @inheritDoc
33
- */
34
- checkEnabled(indentAttributeValue: string): boolean;
35
- /**
36
- * @inheritDoc
37
- */
38
- getNextIndent(indentAttributeValue: string): string | undefined;
39
- }
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 indent/indentcommandbehavior/indentusingclasses
7
+ */
8
+ import type { IndentBehavior } from './indentbehavior';
9
+ /**
10
+ * The block indentation behavior that uses classes to set indentation.
11
+ */
12
+ export default class IndentUsingClasses implements IndentBehavior {
13
+ /**
14
+ * The direction of indentation.
15
+ */
16
+ isForward: boolean;
17
+ /**
18
+ * A list of classes used for indentation.
19
+ */
20
+ classes: Array<string>;
21
+ /**
22
+ * Creates an instance of the indentation behavior.
23
+ *
24
+ * @param config.direction The direction of indentation.
25
+ * @param config.classes A list of classes used for indentation.
26
+ */
27
+ constructor(config: {
28
+ direction: 'forward' | 'backward';
29
+ classes: Array<string>;
30
+ });
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ checkEnabled(indentAttributeValue: string): boolean;
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ getNextIndent(indentAttributeValue: string): string | undefined;
39
+ }
@@ -1,39 +1,39 @@
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
- * The block indentation behavior that uses classes to set indentation.
7
- */
8
- export default class IndentUsingClasses {
9
- /**
10
- * Creates an instance of the indentation behavior.
11
- *
12
- * @param config.direction The direction of indentation.
13
- * @param config.classes A list of classes used for indentation.
14
- */
15
- constructor(config) {
16
- this.isForward = config.direction === 'forward';
17
- this.classes = config.classes;
18
- }
19
- /**
20
- * @inheritDoc
21
- */
22
- checkEnabled(indentAttributeValue) {
23
- const currentIndex = this.classes.indexOf(indentAttributeValue);
24
- if (this.isForward) {
25
- return currentIndex < this.classes.length - 1;
26
- }
27
- else {
28
- return currentIndex >= 0;
29
- }
30
- }
31
- /**
32
- * @inheritDoc
33
- */
34
- getNextIndent(indentAttributeValue) {
35
- const currentIndex = this.classes.indexOf(indentAttributeValue);
36
- const indexStep = this.isForward ? 1 : -1;
37
- return this.classes[currentIndex + indexStep];
38
- }
39
- }
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
+ * The block indentation behavior that uses classes to set indentation.
7
+ */
8
+ export default class IndentUsingClasses {
9
+ /**
10
+ * Creates an instance of the indentation behavior.
11
+ *
12
+ * @param config.direction The direction of indentation.
13
+ * @param config.classes A list of classes used for indentation.
14
+ */
15
+ constructor(config) {
16
+ this.isForward = config.direction === 'forward';
17
+ this.classes = config.classes;
18
+ }
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ checkEnabled(indentAttributeValue) {
23
+ const currentIndex = this.classes.indexOf(indentAttributeValue);
24
+ if (this.isForward) {
25
+ return currentIndex < this.classes.length - 1;
26
+ }
27
+ else {
28
+ return currentIndex >= 0;
29
+ }
30
+ }
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ getNextIndent(indentAttributeValue) {
35
+ const currentIndex = this.classes.indexOf(indentAttributeValue);
36
+ const indexStep = this.isForward ? 1 : -1;
37
+ return this.classes[currentIndex + indexStep];
38
+ }
39
+ }
@@ -1,45 +1,45 @@
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 indent/indentcommandbehavior/indentusingoffset
7
- */
8
- import type { IndentBehavior } from './indentbehavior';
9
- /**
10
- * The block indentation behavior that uses offsets to set indentation.
11
- */
12
- export default class IndentUsingOffset implements IndentBehavior {
13
- /**
14
- * The direction of indentation.
15
- */
16
- isForward: boolean;
17
- /**
18
- * The offset of the next indentation step.
19
- */
20
- offset: number;
21
- /**
22
- * Indentation unit.
23
- */
24
- unit: string;
25
- /**
26
- * Creates an instance of the indentation behavior.
27
- *
28
- * @param config.direction The direction of indentation.
29
- * @param config.offset The offset of the next indentation step.
30
- * @param config.unit Indentation unit.
31
- */
32
- constructor(config: {
33
- direction: 'forward' | 'backward';
34
- offset: number;
35
- unit: string;
36
- });
37
- /**
38
- * @inheritDoc
39
- */
40
- checkEnabled(indentAttributeValue: string): boolean;
41
- /**
42
- * @inheritDoc
43
- */
44
- getNextIndent(indentAttributeValue: string): string | undefined;
45
- }
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 indent/indentcommandbehavior/indentusingoffset
7
+ */
8
+ import type { IndentBehavior } from './indentbehavior';
9
+ /**
10
+ * The block indentation behavior that uses offsets to set indentation.
11
+ */
12
+ export default class IndentUsingOffset implements IndentBehavior {
13
+ /**
14
+ * The direction of indentation.
15
+ */
16
+ isForward: boolean;
17
+ /**
18
+ * The offset of the next indentation step.
19
+ */
20
+ offset: number;
21
+ /**
22
+ * Indentation unit.
23
+ */
24
+ unit: string;
25
+ /**
26
+ * Creates an instance of the indentation behavior.
27
+ *
28
+ * @param config.direction The direction of indentation.
29
+ * @param config.offset The offset of the next indentation step.
30
+ * @param config.unit Indentation unit.
31
+ */
32
+ constructor(config: {
33
+ direction: 'forward' | 'backward';
34
+ offset: number;
35
+ unit: string;
36
+ });
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ checkEnabled(indentAttributeValue: string): boolean;
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ getNextIndent(indentAttributeValue: string): string | undefined;
45
+ }