@ckeditor/ckeditor5-indent 47.6.1 → 48.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.
- package/ckeditor5-metadata.json +9 -21
- package/{src → dist}/indent.d.ts +1 -1
- package/{src → dist}/indentblock.d.ts +1 -1
- package/{src → dist}/indentblockcommand.d.ts +1 -1
- package/dist/indentcommandbehavior/resetindentusingclasses.d.ts +24 -0
- package/dist/indentcommandbehavior/resetindentusingoffset.d.ts +24 -0
- package/{src → dist}/indentediting.d.ts +1 -1
- package/{src → dist}/indentui.d.ts +1 -1
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +82 -114
- package/dist/index.js.map +1 -1
- package/{src → dist}/integrations/indentblocklistcommand.d.ts +1 -1
- package/{src → dist}/integrations/indentblocklistintegration.d.ts +4 -12
- package/{src → dist}/integrations/indentblocklistitemcommand.d.ts +1 -8
- package/package.json +25 -48
- package/build/indent.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/lang/contexts.json +0 -4
- package/lang/translations/af.po +0 -20
- package/lang/translations/ar.po +0 -20
- package/lang/translations/ast.po +0 -20
- package/lang/translations/az.po +0 -20
- package/lang/translations/be.po +0 -20
- package/lang/translations/bg.po +0 -20
- package/lang/translations/bn.po +0 -20
- package/lang/translations/bs.po +0 -20
- package/lang/translations/ca.po +0 -20
- package/lang/translations/cs.po +0 -20
- package/lang/translations/da.po +0 -20
- package/lang/translations/de-ch.po +0 -20
- package/lang/translations/de.po +0 -20
- package/lang/translations/el.po +0 -20
- package/lang/translations/en-au.po +0 -20
- package/lang/translations/en-gb.po +0 -20
- package/lang/translations/en.po +0 -20
- package/lang/translations/eo.po +0 -20
- package/lang/translations/es-co.po +0 -20
- package/lang/translations/es.po +0 -20
- package/lang/translations/et.po +0 -20
- package/lang/translations/eu.po +0 -20
- package/lang/translations/fa.po +0 -20
- package/lang/translations/fi.po +0 -20
- package/lang/translations/fr.po +0 -20
- package/lang/translations/gl.po +0 -20
- package/lang/translations/gu.po +0 -20
- package/lang/translations/he.po +0 -20
- package/lang/translations/hi.po +0 -20
- package/lang/translations/hr.po +0 -20
- package/lang/translations/hu.po +0 -20
- package/lang/translations/hy.po +0 -20
- package/lang/translations/id.po +0 -20
- package/lang/translations/it.po +0 -20
- package/lang/translations/ja.po +0 -20
- package/lang/translations/jv.po +0 -20
- package/lang/translations/kk.po +0 -20
- package/lang/translations/km.po +0 -20
- package/lang/translations/kn.po +0 -20
- package/lang/translations/ko.po +0 -20
- package/lang/translations/ku.po +0 -20
- package/lang/translations/lt.po +0 -20
- package/lang/translations/lv.po +0 -20
- package/lang/translations/ms.po +0 -20
- package/lang/translations/nb.po +0 -20
- package/lang/translations/ne.po +0 -20
- package/lang/translations/nl.po +0 -20
- package/lang/translations/no.po +0 -20
- package/lang/translations/oc.po +0 -20
- package/lang/translations/pl.po +0 -20
- package/lang/translations/pt-br.po +0 -20
- package/lang/translations/pt.po +0 -20
- package/lang/translations/ro.po +0 -20
- package/lang/translations/ru.po +0 -20
- package/lang/translations/si.po +0 -20
- package/lang/translations/sk.po +0 -20
- package/lang/translations/sl.po +0 -20
- package/lang/translations/sq.po +0 -20
- package/lang/translations/sr-latn.po +0 -20
- package/lang/translations/sr.po +0 -20
- package/lang/translations/sv.po +0 -20
- package/lang/translations/th.po +0 -20
- package/lang/translations/ti.po +0 -20
- package/lang/translations/tk.po +0 -20
- package/lang/translations/tr.po +0 -20
- package/lang/translations/tt.po +0 -20
- package/lang/translations/ug.po +0 -20
- package/lang/translations/uk.po +0 -20
- package/lang/translations/ur.po +0 -20
- package/lang/translations/uz.po +0 -20
- package/lang/translations/vi.po +0 -20
- package/lang/translations/zh-cn.po +0 -20
- package/lang/translations/zh.po +0 -20
- package/src/augmentation.js +0 -5
- package/src/indent.js +0 -50
- package/src/indentblock.js +0 -160
- package/src/indentblockcommand.js +0 -102
- package/src/indentcommandbehavior/indentbehavior.js +0 -5
- package/src/indentcommandbehavior/indentusingclasses.js +0 -51
- package/src/indentcommandbehavior/indentusingoffset.js +0 -59
- package/src/indentconfig.js +0 -5
- package/src/indentediting.js +0 -38
- package/src/indentui.js +0 -79
- package/src/index.js +0 -18
- package/src/integrations/indentblocklistcommand.js +0 -108
- package/src/integrations/indentblocklistintegration.js +0 -328
- package/src/integrations/indentblocklistitemcommand.js +0 -96
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/indentcommandbehavior/indentbehavior.d.ts +0 -0
- /package/{src → dist}/indentcommandbehavior/indentusingclasses.d.ts +0 -0
- /package/{src → dist}/indentcommandbehavior/indentusingoffset.d.ts +0 -0
- /package/{src → dist}/indentconfig.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
package/src/indentui.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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/indentui
|
|
7
|
-
*/
|
|
8
|
-
import { ButtonView, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
|
|
9
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
10
|
-
import { IconIndent, IconOutdent } from 'ckeditor5/src/icons.js';
|
|
11
|
-
/**
|
|
12
|
-
* The indent UI feature.
|
|
13
|
-
*
|
|
14
|
-
* This plugin registers the `'indent'` and `'outdent'` buttons.
|
|
15
|
-
*
|
|
16
|
-
* **Note**: In order for the commands to work, at least one of the compatible features is required. Read more in
|
|
17
|
-
* the {@link module:indent/indent~Indent indent feature} API documentation.
|
|
18
|
-
*/
|
|
19
|
-
export class IndentUI extends Plugin {
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
static get pluginName() {
|
|
24
|
-
return 'IndentUI';
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get isOfficialPlugin() {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
init() {
|
|
36
|
-
const editor = this.editor;
|
|
37
|
-
const locale = editor.locale;
|
|
38
|
-
const t = editor.t;
|
|
39
|
-
const localizedIndentIcon = locale.uiLanguageDirection == 'ltr' ? IconIndent : IconOutdent;
|
|
40
|
-
const localizedOutdentIcon = locale.uiLanguageDirection == 'ltr' ? IconOutdent : IconIndent;
|
|
41
|
-
this._defineButton('indent', t('Increase indent'), localizedIndentIcon);
|
|
42
|
-
this._defineButton('outdent', t('Decrease indent'), localizedOutdentIcon);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Defines UI buttons for both toolbar and menu bar.
|
|
46
|
-
*/
|
|
47
|
-
_defineButton(commandName, label, icon) {
|
|
48
|
-
const editor = this.editor;
|
|
49
|
-
editor.ui.componentFactory.add(commandName, () => {
|
|
50
|
-
const buttonView = this._createButton(ButtonView, commandName, label, icon);
|
|
51
|
-
buttonView.set({
|
|
52
|
-
tooltip: true
|
|
53
|
-
});
|
|
54
|
-
return buttonView;
|
|
55
|
-
});
|
|
56
|
-
editor.ui.componentFactory.add('menuBar:' + commandName, () => {
|
|
57
|
-
return this._createButton(MenuBarMenuListItemButtonView, commandName, label, icon);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Creates a button to use either in toolbar or in menu bar.
|
|
62
|
-
*/
|
|
63
|
-
_createButton(ButtonClass, commandName, label, icon) {
|
|
64
|
-
const editor = this.editor;
|
|
65
|
-
const command = editor.commands.get(commandName);
|
|
66
|
-
const view = new ButtonClass(editor.locale);
|
|
67
|
-
view.set({
|
|
68
|
-
label,
|
|
69
|
-
icon
|
|
70
|
-
});
|
|
71
|
-
view.bind('isEnabled').to(command, 'isEnabled');
|
|
72
|
-
// Execute the command.
|
|
73
|
-
this.listenTo(view, 'execute', () => {
|
|
74
|
-
editor.execute(commandName);
|
|
75
|
-
editor.editing.view.focus();
|
|
76
|
-
});
|
|
77
|
-
return view;
|
|
78
|
-
}
|
|
79
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
7
|
-
*/
|
|
8
|
-
export { Indent } from './indent.js';
|
|
9
|
-
export { IndentEditing } from './indentediting.js';
|
|
10
|
-
export { IndentUI } from './indentui.js';
|
|
11
|
-
export { IndentBlock } from './indentblock.js';
|
|
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';
|
|
16
|
-
export { IndentUsingClasses as _IndentUsingClasses } from './indentcommandbehavior/indentusingclasses.js';
|
|
17
|
-
export { IndentUsingOffset as _IndentUsingOffset } from './indentcommandbehavior/indentusingoffset.js';
|
|
18
|
-
import './augmentation.js';
|
|
@@ -1,108 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,328 +0,0 @@
|
|
|
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
|
-
import { addMarginStylesRules } from 'ckeditor5/src/engine.js';
|
|
7
|
-
import { IndentBlockListCommand } from './indentblocklistcommand.js';
|
|
8
|
-
import { IndentBlockListItemCommand } from './indentblocklistitemcommand.js';
|
|
9
|
-
import { IndentUsingOffset } from '../indentcommandbehavior/indentusingoffset.js';
|
|
10
|
-
import { IndentUsingClasses } from '../indentcommandbehavior/indentusingclasses.js';
|
|
11
|
-
/**
|
|
12
|
-
* This integration enables using block indentation feature with lists.
|
|
13
|
-
*/
|
|
14
|
-
export class IndentBlockListIntegration extends Plugin {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get pluginName() {
|
|
19
|
-
return 'IndentBlockListIntegration';
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
static get isOfficialPlugin() {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @inheritDoc
|
|
29
|
-
*/
|
|
30
|
-
init() {
|
|
31
|
-
const editor = this.editor;
|
|
32
|
-
if (!this.editor.plugins.has('ListEditing')) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const config = editor.config.get('indentBlock');
|
|
36
|
-
if (config.classes && config.classes.length) {
|
|
37
|
-
this._setupConversionUsingClassesForListBlock(config.classes);
|
|
38
|
-
this._setupConversionUsingClassesForListItemBlock(config.classes);
|
|
39
|
-
editor.commands.add('indentBlockList', new IndentBlockListCommand(editor, new IndentUsingClasses({
|
|
40
|
-
direction: 'forward',
|
|
41
|
-
classes: config.classes
|
|
42
|
-
})));
|
|
43
|
-
editor.commands.add('outdentBlockList', new IndentBlockListCommand(editor, new IndentUsingClasses({
|
|
44
|
-
direction: 'backward',
|
|
45
|
-
classes: config.classes
|
|
46
|
-
})));
|
|
47
|
-
editor.commands.add('indentBlockListItem', new IndentBlockListItemCommand(editor, new IndentUsingClasses({
|
|
48
|
-
direction: 'forward',
|
|
49
|
-
classes: config.classes
|
|
50
|
-
})));
|
|
51
|
-
editor.commands.add('outdentBlockListItem', new IndentBlockListItemCommand(editor, new IndentUsingClasses({
|
|
52
|
-
direction: 'backward',
|
|
53
|
-
classes: config.classes
|
|
54
|
-
})));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
editor.data.addStyleProcessorRules(addMarginStylesRules);
|
|
58
|
-
this._setupConversionUsingOffsetForListBlock();
|
|
59
|
-
this._setupConversionUsingOffsetForListItemBlock();
|
|
60
|
-
editor.commands.add('indentBlockList', new IndentBlockListCommand(editor, new IndentUsingOffset({
|
|
61
|
-
direction: 'forward',
|
|
62
|
-
offset: config.offset,
|
|
63
|
-
unit: config.unit
|
|
64
|
-
})));
|
|
65
|
-
editor.commands.add('outdentBlockList', new IndentBlockListCommand(editor, new IndentUsingOffset({
|
|
66
|
-
direction: 'backward',
|
|
67
|
-
offset: config.offset,
|
|
68
|
-
unit: config.unit
|
|
69
|
-
})));
|
|
70
|
-
editor.commands.add('indentBlockListItem', new IndentBlockListItemCommand(editor, new IndentUsingOffset({
|
|
71
|
-
direction: 'forward',
|
|
72
|
-
offset: config.offset,
|
|
73
|
-
unit: config.unit
|
|
74
|
-
})));
|
|
75
|
-
editor.commands.add('outdentBlockListItem', new IndentBlockListItemCommand(editor, new IndentUsingOffset({
|
|
76
|
-
direction: 'backward',
|
|
77
|
-
offset: config.offset,
|
|
78
|
-
unit: config.unit
|
|
79
|
-
})));
|
|
80
|
-
}
|
|
81
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
82
|
-
// Make sure that all items in a single list (items at the same level & listType) have the same blockIndentList attribute value.
|
|
83
|
-
listEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
84
|
-
for (const { node, previousNodeInList } of listNodes) {
|
|
85
|
-
// This is a first item of a nested list.
|
|
86
|
-
if (!previousNodeInList) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (previousNodeInList.getAttribute('listType') != node.getAttribute('listType')) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (ensureIndentValuesConsistency('blockIndentList', node, previousNodeInList, writer)) {
|
|
93
|
-
evt.return = true;
|
|
94
|
-
}
|
|
95
|
-
if (previousNodeInList.getAttribute('listItemId') != node.getAttribute('listItemId')) {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (ensureIndentValuesConsistency('blockIndentListItem', node, previousNodeInList, writer)) {
|
|
99
|
-
evt.return = true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
this.listenTo(editor.editing.view.document, 'tab', (evt, data) => {
|
|
104
|
-
const commandName = data.shiftKey ? 'outdentBlockList' : 'indentBlockList';
|
|
105
|
-
const command = this.editor.commands.get(commandName);
|
|
106
|
-
if (command.isEnabled) {
|
|
107
|
-
editor.execute(commandName, { firstListOnly: true });
|
|
108
|
-
data.stopPropagation();
|
|
109
|
-
data.preventDefault();
|
|
110
|
-
evt.stop();
|
|
111
|
-
}
|
|
112
|
-
}, { context: 'li', priority: 'high' });
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @inheritDoc
|
|
116
|
-
*/
|
|
117
|
-
afterInit() {
|
|
118
|
-
const editor = this.editor;
|
|
119
|
-
const model = editor.model;
|
|
120
|
-
const schema = model.schema;
|
|
121
|
-
if (!editor.plugins.has('ListEditing')) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
// Schema registration.
|
|
125
|
-
schema.extend('$listItem', { allowAttributes: ['blockIndentList', 'blockIndentListItem'] });
|
|
126
|
-
schema.setAttributeProperties('blockIndentList', { isFormatting: true });
|
|
127
|
-
schema.setAttributeProperties('blockIndentListItem', { isFormatting: true });
|
|
128
|
-
model.schema.addAttributeCheck(context => {
|
|
129
|
-
const item = context.last;
|
|
130
|
-
if (!item.getAttribute('listItemId')) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}, 'blockIndentList');
|
|
134
|
-
model.schema.addAttributeCheck(context => {
|
|
135
|
-
const item = context.last;
|
|
136
|
-
if (!item.getAttribute('listItemId')) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
}, 'blockIndentListItem');
|
|
140
|
-
// Clear blockIndentList and blockIndentListItem when list indent changes.
|
|
141
|
-
const clearBlockIndentAttributesOnListIndentChange = (_evt, changedBlocks) => {
|
|
142
|
-
editor.model.change(writer => {
|
|
143
|
-
for (const node of changedBlocks) {
|
|
144
|
-
if (node.hasAttribute('listItemId')) {
|
|
145
|
-
if (node.hasAttribute('blockIndentList')) {
|
|
146
|
-
writer.removeAttribute('blockIndentList', node);
|
|
147
|
-
}
|
|
148
|
-
if (node.hasAttribute('blockIndentListItem')) {
|
|
149
|
-
writer.removeAttribute('blockIndentListItem', node);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
const indentListCommand = editor.commands.get('indentList');
|
|
156
|
-
const outdentListCommand = editor.commands.get('outdentList');
|
|
157
|
-
if (indentListCommand) {
|
|
158
|
-
this.listenTo(indentListCommand, 'afterExecute', clearBlockIndentAttributesOnListIndentChange);
|
|
159
|
-
}
|
|
160
|
-
if (outdentListCommand) {
|
|
161
|
-
this.listenTo(outdentListCommand, 'afterExecute', clearBlockIndentAttributesOnListIndentChange);
|
|
162
|
-
}
|
|
163
|
-
// Register list block indent commands in multi command.
|
|
164
|
-
const indentCommand = editor.commands.get('indent');
|
|
165
|
-
const outdentCommand = editor.commands.get('outdent');
|
|
166
|
-
indentCommand.registerChildCommand(editor.commands.get('indentBlockList'));
|
|
167
|
-
outdentCommand.registerChildCommand(editor.commands.get('outdentBlockList'));
|
|
168
|
-
indentCommand.registerChildCommand(editor.commands.get('indentBlockListItem'));
|
|
169
|
-
outdentCommand.registerChildCommand(editor.commands.get('outdentBlockListItem'));
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Setups conversion for list block indent using offset indents.
|
|
173
|
-
*/
|
|
174
|
-
_setupConversionUsingOffsetForListBlock() {
|
|
175
|
-
const editor = this.editor;
|
|
176
|
-
const conversion = editor.conversion;
|
|
177
|
-
const locale = editor.locale;
|
|
178
|
-
const marginProperty = locale.contentLanguageDirection === 'rtl' ? 'margin-right' : 'margin-left';
|
|
179
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
180
|
-
conversion.for('upcast').add(dispatcher => {
|
|
181
|
-
dispatcher.on('element:ol', listBlockIndentUpcastConverter('blockIndentList', marginProperty));
|
|
182
|
-
dispatcher.on('element:ul', listBlockIndentUpcastConverter('blockIndentList', marginProperty));
|
|
183
|
-
});
|
|
184
|
-
listEditing.registerDowncastStrategy({
|
|
185
|
-
scope: 'list',
|
|
186
|
-
attributeName: 'blockIndentList',
|
|
187
|
-
setAttributeOnDowncast(writer, value, element) {
|
|
188
|
-
if (value) {
|
|
189
|
-
writer.setStyle(marginProperty, value, element);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Setups conversion for list item block indent using offset indents.
|
|
196
|
-
*/
|
|
197
|
-
_setupConversionUsingOffsetForListItemBlock() {
|
|
198
|
-
const editor = this.editor;
|
|
199
|
-
const locale = editor.locale;
|
|
200
|
-
const conversion = editor.conversion;
|
|
201
|
-
const marginProperty = locale.contentLanguageDirection === 'rtl' ? 'margin-right' : 'margin-left';
|
|
202
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
203
|
-
conversion.for('upcast').add(dispatcher => {
|
|
204
|
-
dispatcher.on('element:li', listBlockIndentUpcastConverter('blockIndentListItem', marginProperty), { priority: 'low' });
|
|
205
|
-
});
|
|
206
|
-
listEditing.registerDowncastStrategy({
|
|
207
|
-
scope: 'item',
|
|
208
|
-
attributeName: 'blockIndentListItem',
|
|
209
|
-
setAttributeOnDowncast(writer, value, element) {
|
|
210
|
-
if (value) {
|
|
211
|
-
writer.setStyle(marginProperty, value, element);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Setups conversion for list block indent using classes.
|
|
218
|
-
*/
|
|
219
|
-
_setupConversionUsingClassesForListBlock(classes) {
|
|
220
|
-
const editor = this.editor;
|
|
221
|
-
const conversion = editor.conversion;
|
|
222
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
223
|
-
conversion.for('upcast').add(dispatcher => {
|
|
224
|
-
dispatcher.on('element:ol', listBlockIndentUpcastConverterUsingClasses('blockIndentList', classes));
|
|
225
|
-
dispatcher.on('element:ul', listBlockIndentUpcastConverterUsingClasses('blockIndentList', classes));
|
|
226
|
-
});
|
|
227
|
-
listEditing.registerDowncastStrategy({
|
|
228
|
-
scope: 'list',
|
|
229
|
-
attributeName: 'blockIndentList',
|
|
230
|
-
setAttributeOnDowncast(writer, value, element) {
|
|
231
|
-
if (value) {
|
|
232
|
-
writer.addClass(value, element);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Setups conversion for list item block indent using classes.
|
|
239
|
-
*/
|
|
240
|
-
_setupConversionUsingClassesForListItemBlock(classes) {
|
|
241
|
-
const editor = this.editor;
|
|
242
|
-
const conversion = editor.conversion;
|
|
243
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
244
|
-
conversion.for('upcast').add(dispatcher => {
|
|
245
|
-
dispatcher.on('element:li', listBlockIndentUpcastConverterUsingClasses('blockIndentListItem', classes), { priority: 'low' });
|
|
246
|
-
});
|
|
247
|
-
listEditing.registerDowncastStrategy({
|
|
248
|
-
scope: 'item',
|
|
249
|
-
attributeName: 'blockIndentListItem',
|
|
250
|
-
setAttributeOnDowncast(writer, value, element) {
|
|
251
|
-
if (value) {
|
|
252
|
-
writer.addClass(value, element);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function listBlockIndentUpcastConverterUsingClasses(attributeName, classes) {
|
|
259
|
-
return (evt, data, conversionApi) => {
|
|
260
|
-
const { writer, consumable } = conversionApi;
|
|
261
|
-
if (!data.modelRange) {
|
|
262
|
-
Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
|
263
|
-
}
|
|
264
|
-
const viewClasses = Array.from(data.viewItem.getClassNames());
|
|
265
|
-
const matchedClass = classes.find(cls => viewClasses.includes(cls));
|
|
266
|
-
if (matchedClass === undefined) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
let applied = false;
|
|
270
|
-
let indentLevel;
|
|
271
|
-
for (const item of data.modelRange.getItems({ shallow: true })) {
|
|
272
|
-
if (indentLevel === undefined) {
|
|
273
|
-
indentLevel = item.getAttribute('listIndent');
|
|
274
|
-
}
|
|
275
|
-
if (item.hasAttribute(attributeName)) {
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
if (item.getAttribute('listIndent') !== indentLevel) {
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
writer.setAttribute(attributeName, matchedClass, item);
|
|
282
|
-
applied = true;
|
|
283
|
-
}
|
|
284
|
-
if (applied) {
|
|
285
|
-
consumable.consume(data.viewItem, { classes: matchedClass });
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function listBlockIndentUpcastConverter(attributeName, marginProperty) {
|
|
290
|
-
return (evt, data, conversionApi) => {
|
|
291
|
-
const { writer, consumable } = conversionApi;
|
|
292
|
-
if (!data.modelRange) {
|
|
293
|
-
Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
|
294
|
-
}
|
|
295
|
-
const marginValue = data.viewItem.getStyle(marginProperty);
|
|
296
|
-
let applied = false;
|
|
297
|
-
let indentLevel;
|
|
298
|
-
for (const item of data.modelRange.getItems({ shallow: true })) {
|
|
299
|
-
if (indentLevel === undefined) {
|
|
300
|
-
indentLevel = item.getAttribute('listIndent');
|
|
301
|
-
}
|
|
302
|
-
if (item.hasAttribute(attributeName)) {
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
if (item.getAttribute('listIndent') !== indentLevel) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
writer.setAttribute(attributeName, marginValue, item);
|
|
309
|
-
applied = true;
|
|
310
|
-
}
|
|
311
|
-
if (applied) {
|
|
312
|
-
consumable.consume(data.viewItem, { styles: marginProperty });
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function ensureIndentValuesConsistency(attributeName, node, previousNodeInList, writer) {
|
|
317
|
-
const prevNodeIndentListValue = previousNodeInList.getAttribute(attributeName);
|
|
318
|
-
if (node.getAttribute(attributeName) === prevNodeIndentListValue) {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
if (prevNodeIndentListValue) {
|
|
322
|
-
writer.setAttribute(attributeName, prevNodeIndentListValue, node);
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
writer.removeAttribute(attributeName, node);
|
|
326
|
-
}
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
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/indentblocklistitemcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from 'ckeditor5/src/core.js';
|
|
9
|
-
/**
|
|
10
|
-
* The indent block list item command.
|
|
11
|
-
*
|
|
12
|
-
* The command is registered by the {@link module:indent/integrations/indentblocklistintegration~IndentBlockListIntegration} as
|
|
13
|
-
* `'indentBlockListItem'` for indenting list items and `'outdentBlockListItem'` for outdenting list items.
|
|
14
|
-
*
|
|
15
|
-
* It's only possible to reset the block indentation of a list item to `0`.
|
|
16
|
-
* This means that if a list item has negative block indentation, the command will only allow forward indentation
|
|
17
|
-
* to make it possible to reset it to `0` and if a list item has positive block indentation, the command
|
|
18
|
-
* will only allow backward indentation to make it possible to reset it to `0`.
|
|
19
|
-
*
|
|
20
|
-
* To increase block indentation of the list item, execute the command:
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* editor.execute( 'indentBlockListItem' );
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* To decrease block indentation of the list item, execute the command:
|
|
27
|
-
*
|
|
28
|
-
* ```ts
|
|
29
|
-
* editor.execute( 'outdentBlockListItem' );
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export class IndentBlockListItemCommand extends Command {
|
|
33
|
-
/**
|
|
34
|
-
* The command's indentation behavior.
|
|
35
|
-
*/
|
|
36
|
-
_indentBehavior;
|
|
37
|
-
/**
|
|
38
|
-
* Creates an instance of the command.
|
|
39
|
-
*/
|
|
40
|
-
constructor(editor, indentBehavior) {
|
|
41
|
-
super(editor);
|
|
42
|
-
this._indentBehavior = indentBehavior;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @inheritDoc
|
|
46
|
-
*/
|
|
47
|
-
refresh() {
|
|
48
|
-
this.isEnabled = this._getAffectedListItems().length > 0;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @inheritDoc
|
|
52
|
-
*/
|
|
53
|
-
execute() {
|
|
54
|
-
const editor = this.editor;
|
|
55
|
-
const model = editor.model;
|
|
56
|
-
model.change(writer => {
|
|
57
|
-
for (const block of this._getAffectedListItems()) {
|
|
58
|
-
writer.removeAttribute('blockIndentListItem', block);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns an array of list items which block indentation should be changed.
|
|
64
|
-
*/
|
|
65
|
-
_getAffectedListItems() {
|
|
66
|
-
const model = this.editor.model;
|
|
67
|
-
const selection = model.document.selection;
|
|
68
|
-
const listUtils = this.editor.plugins.get('ListUtils');
|
|
69
|
-
const blocksInSelection = Array.from(selection.getSelectedBlocks());
|
|
70
|
-
const expandedBlocks = listUtils.expandListBlocksToCompleteItems(blocksInSelection);
|
|
71
|
-
return expandedBlocks.filter(block => this._isIndentationChangeAllowed(block));
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Returns `true` if changing the block indentation is allowed for the given list item.
|
|
75
|
-
*
|
|
76
|
-
* Indentation of a list item is only allowed if it moves toward zero. This means that:
|
|
77
|
-
* - when currentIndent = 0, the command should be disabled
|
|
78
|
-
* - when currentIndent < 0, only forward indentation should be allowed
|
|
79
|
-
* - when currentIndent > 0, only backward indentation should be allowed
|
|
80
|
-
*
|
|
81
|
-
* For classes-based indentation, the command should be enabled if there is a class to be removed.
|
|
82
|
-
*/
|
|
83
|
-
_isIndentationChangeAllowed(element) {
|
|
84
|
-
if (!element.hasAttribute('blockIndentListItem')) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const currentIndent = parseFloat(element.getAttribute('blockIndentListItem'));
|
|
88
|
-
// Class based indent, allow only outdent.
|
|
89
|
-
// TODO find a better way, probably use behavior to find out.
|
|
90
|
-
if (isNaN(currentIndent)) {
|
|
91
|
-
return !this._indentBehavior.isForward;
|
|
92
|
-
}
|
|
93
|
-
return this._indentBehavior.isForward && currentIndent < 0 ||
|
|
94
|
-
!this._indentBehavior.isForward && currentIndent > 0;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → dist}/index.d.ts
RENAMED
|
File without changes
|