@ckeditor/ckeditor5-indent 39.0.2 → 40.0.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/build/indent.js.map +1 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +24 -24
- package/src/augmentation.js +5 -5
- package/src/indent.d.ts +40 -40
- package/src/indent.js +44 -44
- package/src/indentblock.d.ts +42 -42
- package/src/indentblock.js +147 -147
- package/src/indentblockcommand.d.ts +56 -56
- package/src/indentblockcommand.js +98 -98
- package/src/indentcommandbehavior/indentbehavior.d.ts +25 -25
- package/src/indentcommandbehavior/indentbehavior.js +5 -5
- package/src/indentcommandbehavior/indentusingclasses.d.ts +39 -39
- package/src/indentcommandbehavior/indentusingclasses.js +39 -39
- package/src/indentcommandbehavior/indentusingoffset.d.ts +45 -45
- package/src/indentcommandbehavior/indentusingoffset.js +42 -42
- package/src/indentconfig.d.ts +72 -72
- package/src/indentconfig.js +5 -5
- package/src/indentediting.d.ts +26 -26
- package/src/indentediting.js +32 -32
- package/src/indentui.d.ts +27 -27
- package/src/indentui.js +60 -60
- package/src/index.d.ts +14 -14
- package/src/index.js +12 -12
package/src/indentblock.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
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/indentblock
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { addMarginRules } from 'ckeditor5/src/engine';
|
|
10
|
-
import IndentBlockCommand from './indentblockcommand';
|
|
11
|
-
import IndentUsingOffset from './indentcommandbehavior/indentusingoffset';
|
|
12
|
-
import IndentUsingClasses from './indentcommandbehavior/indentusingclasses';
|
|
13
|
-
const DEFAULT_ELEMENTS = ['paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6'];
|
|
14
|
-
/**
|
|
15
|
-
* The block indentation feature.
|
|
16
|
-
*
|
|
17
|
-
* It registers the `'indentBlock'` and `'outdentBlock'` commands.
|
|
18
|
-
*
|
|
19
|
-
* If the plugin {@link module:indent/indent~Indent} is defined, it also attaches the `'indentBlock'` and `'outdentBlock'` commands to
|
|
20
|
-
* the `'indent'` and `'outdent'` commands.
|
|
21
|
-
*/
|
|
22
|
-
export default class IndentBlock extends Plugin {
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
constructor(editor) {
|
|
27
|
-
super(editor);
|
|
28
|
-
editor.config.define('indentBlock', {
|
|
29
|
-
offset: 40,
|
|
30
|
-
unit: 'px'
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @inheritDoc
|
|
35
|
-
*/
|
|
36
|
-
static get pluginName() {
|
|
37
|
-
return 'IndentBlock';
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @inheritDoc
|
|
41
|
-
*/
|
|
42
|
-
init() {
|
|
43
|
-
const editor = this.editor;
|
|
44
|
-
const configuration = editor.config.get('indentBlock');
|
|
45
|
-
if (configuration.classes && configuration.classes.length) {
|
|
46
|
-
this._setupConversionUsingClasses(configuration.classes);
|
|
47
|
-
editor.commands.add('indentBlock', new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
48
|
-
direction: 'forward',
|
|
49
|
-
classes: configuration.classes
|
|
50
|
-
})));
|
|
51
|
-
editor.commands.add('outdentBlock', new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
52
|
-
direction: 'backward',
|
|
53
|
-
classes: configuration.classes
|
|
54
|
-
})));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
editor.data.addStyleProcessorRules(addMarginRules);
|
|
58
|
-
this._setupConversionUsingOffset();
|
|
59
|
-
editor.commands.add('indentBlock', new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
60
|
-
direction: 'forward',
|
|
61
|
-
offset: configuration.offset,
|
|
62
|
-
unit: configuration.unit
|
|
63
|
-
})));
|
|
64
|
-
editor.commands.add('outdentBlock', new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
65
|
-
direction: 'backward',
|
|
66
|
-
offset: configuration.offset,
|
|
67
|
-
unit: configuration.unit
|
|
68
|
-
})));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* @inheritDoc
|
|
73
|
-
*/
|
|
74
|
-
afterInit() {
|
|
75
|
-
const editor = this.editor;
|
|
76
|
-
const schema = editor.model.schema;
|
|
77
|
-
const indentCommand = editor.commands.get('indent');
|
|
78
|
-
const outdentCommand = editor.commands.get('outdent');
|
|
79
|
-
// Enable block indentation to heading configuration options. If it is not defined enable in paragraph and default headings.
|
|
80
|
-
const options = editor.config.get('heading.options');
|
|
81
|
-
const configuredElements = options && options.map(option => option.model);
|
|
82
|
-
const knownElements = configuredElements || DEFAULT_ELEMENTS;
|
|
83
|
-
knownElements.forEach(elementName => {
|
|
84
|
-
if (schema.isRegistered(elementName)) {
|
|
85
|
-
schema.extend(elementName, { allowAttributes: 'blockIndent' });
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
schema.setAttributeProperties('blockIndent', { isFormatting: true });
|
|
89
|
-
indentCommand.registerChildCommand(editor.commands.get('indentBlock'));
|
|
90
|
-
outdentCommand.registerChildCommand(editor.commands.get('outdentBlock'));
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Setups conversion for using offset indents.
|
|
94
|
-
*/
|
|
95
|
-
_setupConversionUsingOffset() {
|
|
96
|
-
const conversion = this.editor.conversion;
|
|
97
|
-
const locale = this.editor.locale;
|
|
98
|
-
const marginProperty = locale.contentLanguageDirection === 'rtl' ? 'margin-right' : 'margin-left';
|
|
99
|
-
conversion.for('upcast').attributeToAttribute({
|
|
100
|
-
view: {
|
|
101
|
-
styles: {
|
|
102
|
-
[marginProperty]: /[\s\S]+/
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
model: {
|
|
106
|
-
key: 'blockIndent',
|
|
107
|
-
value: (viewElement) => {
|
|
108
|
-
// Do not indent block elements in Document Lists. See https://github.com/ckeditor/ckeditor5/issues/12466.
|
|
109
|
-
if (!viewElement.is('element', 'li')) {
|
|
110
|
-
return viewElement.getStyle(marginProperty);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
conversion.for('downcast').attributeToAttribute({
|
|
116
|
-
model: 'blockIndent',
|
|
117
|
-
view: modelAttributeValue => {
|
|
118
|
-
return {
|
|
119
|
-
key: 'style',
|
|
120
|
-
value: {
|
|
121
|
-
[marginProperty]: modelAttributeValue
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Setups conversion for using classes.
|
|
129
|
-
*/
|
|
130
|
-
_setupConversionUsingClasses(classes) {
|
|
131
|
-
const definition = {
|
|
132
|
-
model: {
|
|
133
|
-
key: 'blockIndent',
|
|
134
|
-
values: []
|
|
135
|
-
},
|
|
136
|
-
view: {}
|
|
137
|
-
};
|
|
138
|
-
for (const className of classes) {
|
|
139
|
-
definition.model.values.push(className);
|
|
140
|
-
definition.view[className] = {
|
|
141
|
-
key: 'class',
|
|
142
|
-
value: [className]
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
this.editor.conversion.attributeToAttribute(definition);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
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/indentblock
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { addMarginRules } from 'ckeditor5/src/engine';
|
|
10
|
+
import IndentBlockCommand from './indentblockcommand';
|
|
11
|
+
import IndentUsingOffset from './indentcommandbehavior/indentusingoffset';
|
|
12
|
+
import IndentUsingClasses from './indentcommandbehavior/indentusingclasses';
|
|
13
|
+
const DEFAULT_ELEMENTS = ['paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6'];
|
|
14
|
+
/**
|
|
15
|
+
* The block indentation feature.
|
|
16
|
+
*
|
|
17
|
+
* It registers the `'indentBlock'` and `'outdentBlock'` commands.
|
|
18
|
+
*
|
|
19
|
+
* If the plugin {@link module:indent/indent~Indent} is defined, it also attaches the `'indentBlock'` and `'outdentBlock'` commands to
|
|
20
|
+
* the `'indent'` and `'outdent'` commands.
|
|
21
|
+
*/
|
|
22
|
+
export default class IndentBlock extends Plugin {
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
constructor(editor) {
|
|
27
|
+
super(editor);
|
|
28
|
+
editor.config.define('indentBlock', {
|
|
29
|
+
offset: 40,
|
|
30
|
+
unit: 'px'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
static get pluginName() {
|
|
37
|
+
return 'IndentBlock';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
42
|
+
init() {
|
|
43
|
+
const editor = this.editor;
|
|
44
|
+
const configuration = editor.config.get('indentBlock');
|
|
45
|
+
if (configuration.classes && configuration.classes.length) {
|
|
46
|
+
this._setupConversionUsingClasses(configuration.classes);
|
|
47
|
+
editor.commands.add('indentBlock', new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
48
|
+
direction: 'forward',
|
|
49
|
+
classes: configuration.classes
|
|
50
|
+
})));
|
|
51
|
+
editor.commands.add('outdentBlock', new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
52
|
+
direction: 'backward',
|
|
53
|
+
classes: configuration.classes
|
|
54
|
+
})));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
editor.data.addStyleProcessorRules(addMarginRules);
|
|
58
|
+
this._setupConversionUsingOffset();
|
|
59
|
+
editor.commands.add('indentBlock', new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
60
|
+
direction: 'forward',
|
|
61
|
+
offset: configuration.offset,
|
|
62
|
+
unit: configuration.unit
|
|
63
|
+
})));
|
|
64
|
+
editor.commands.add('outdentBlock', new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
65
|
+
direction: 'backward',
|
|
66
|
+
offset: configuration.offset,
|
|
67
|
+
unit: configuration.unit
|
|
68
|
+
})));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
afterInit() {
|
|
75
|
+
const editor = this.editor;
|
|
76
|
+
const schema = editor.model.schema;
|
|
77
|
+
const indentCommand = editor.commands.get('indent');
|
|
78
|
+
const outdentCommand = editor.commands.get('outdent');
|
|
79
|
+
// Enable block indentation to heading configuration options. If it is not defined enable in paragraph and default headings.
|
|
80
|
+
const options = editor.config.get('heading.options');
|
|
81
|
+
const configuredElements = options && options.map(option => option.model);
|
|
82
|
+
const knownElements = configuredElements || DEFAULT_ELEMENTS;
|
|
83
|
+
knownElements.forEach(elementName => {
|
|
84
|
+
if (schema.isRegistered(elementName)) {
|
|
85
|
+
schema.extend(elementName, { allowAttributes: 'blockIndent' });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
schema.setAttributeProperties('blockIndent', { isFormatting: true });
|
|
89
|
+
indentCommand.registerChildCommand(editor.commands.get('indentBlock'));
|
|
90
|
+
outdentCommand.registerChildCommand(editor.commands.get('outdentBlock'));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Setups conversion for using offset indents.
|
|
94
|
+
*/
|
|
95
|
+
_setupConversionUsingOffset() {
|
|
96
|
+
const conversion = this.editor.conversion;
|
|
97
|
+
const locale = this.editor.locale;
|
|
98
|
+
const marginProperty = locale.contentLanguageDirection === 'rtl' ? 'margin-right' : 'margin-left';
|
|
99
|
+
conversion.for('upcast').attributeToAttribute({
|
|
100
|
+
view: {
|
|
101
|
+
styles: {
|
|
102
|
+
[marginProperty]: /[\s\S]+/
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
model: {
|
|
106
|
+
key: 'blockIndent',
|
|
107
|
+
value: (viewElement) => {
|
|
108
|
+
// Do not indent block elements in Document Lists. See https://github.com/ckeditor/ckeditor5/issues/12466.
|
|
109
|
+
if (!viewElement.is('element', 'li')) {
|
|
110
|
+
return viewElement.getStyle(marginProperty);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
conversion.for('downcast').attributeToAttribute({
|
|
116
|
+
model: 'blockIndent',
|
|
117
|
+
view: modelAttributeValue => {
|
|
118
|
+
return {
|
|
119
|
+
key: 'style',
|
|
120
|
+
value: {
|
|
121
|
+
[marginProperty]: modelAttributeValue
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Setups conversion for using classes.
|
|
129
|
+
*/
|
|
130
|
+
_setupConversionUsingClasses(classes) {
|
|
131
|
+
const definition = {
|
|
132
|
+
model: {
|
|
133
|
+
key: 'blockIndent',
|
|
134
|
+
values: []
|
|
135
|
+
},
|
|
136
|
+
view: {}
|
|
137
|
+
};
|
|
138
|
+
for (const className of classes) {
|
|
139
|
+
definition.model.values.push(className);
|
|
140
|
+
definition.view[className] = {
|
|
141
|
+
key: 'class',
|
|
142
|
+
value: [className]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
this.editor.conversion.attributeToAttribute(definition);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -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
|
+
}
|