@ckeditor/ckeditor5-indent 48.2.0 → 48.3.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/dist/augmentation.d.ts +27 -27
- package/dist/indent.d.ts +39 -39
- package/dist/indentblock.d.ts +46 -46
- package/dist/indentblockcommand.d.ts +51 -51
- package/dist/indentcommandbehavior/indentbehavior.d.ts +20 -20
- package/dist/indentcommandbehavior/indentusingclasses.d.ts +36 -36
- package/dist/indentcommandbehavior/indentusingoffset.d.ts +42 -42
- package/dist/indentcommandbehavior/resetindentusingclasses.d.ts +19 -19
- package/dist/indentcommandbehavior/resetindentusingoffset.d.ts +19 -19
- package/dist/indentconfig.d.ts +67 -67
- package/dist/indentediting.d.ts +25 -25
- package/dist/indentui.d.ts +31 -31
- package/dist/index-content.css +1 -0
- package/dist/index-editor.css +1 -0
- package/dist/index.css +0 -2
- package/dist/index.d.ts +18 -18
- package/dist/index.js +901 -923
- package/dist/index.js.map +1 -1
- package/dist/integrations/indentblocklistcommand.d.ts +55 -55
- package/dist/integrations/indentblocklistintegration.d.ts +30 -30
- package/dist/integrations/indentblocklistitemcommand.d.ts +53 -53
- package/package.json +8 -8
- package/dist/index.css.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2,958 +2,936 @@
|
|
|
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 {
|
|
6
|
-
import { ButtonView, MenuBarMenuListItemButtonView } from
|
|
7
|
-
import { IconIndent, IconOutdent } from
|
|
8
|
-
import { addMarginStylesRules } from
|
|
9
|
-
import { first } from
|
|
10
|
-
import { _isListItemBlock } from
|
|
5
|
+
import { Command, MultiCommand, Plugin } from "@ckeditor/ckeditor5-core";
|
|
6
|
+
import { ButtonView, MenuBarMenuListItemButtonView } from "@ckeditor/ckeditor5-ui";
|
|
7
|
+
import { IconIndent, IconOutdent } from "@ckeditor/ckeditor5-icons";
|
|
8
|
+
import { addMarginStylesRules } from "@ckeditor/ckeditor5-engine";
|
|
9
|
+
import { first } from "@ckeditor/ckeditor5-utils";
|
|
10
|
+
import { _isListItemBlock } from "@ckeditor/ckeditor5-list";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
13
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
14
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @module indent/indentediting
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The indent editing feature.
|
|
21
|
+
*
|
|
22
|
+
* This plugin registers the `'indent'` and `'outdent'` commands.
|
|
23
|
+
*
|
|
24
|
+
* **Note**: In order for the commands to work, at least one of the compatible features is required. Read more in the
|
|
25
|
+
* {@link module:indent/indent~Indent indent feature} API documentation.
|
|
26
|
+
*/
|
|
27
|
+
var IndentEditing = class extends Plugin {
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get pluginName() {
|
|
32
|
+
return "IndentEditing";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
static get isOfficialPlugin() {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
init() {
|
|
44
|
+
const editor = this.editor;
|
|
45
|
+
editor.commands.add("indent", new MultiCommand(editor));
|
|
46
|
+
editor.commands.add("outdent", new MultiCommand(editor));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
38
49
|
|
|
39
50
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
51
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
52
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* @module indent/indentui
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* The indent UI feature.
|
|
59
|
+
*
|
|
60
|
+
* This plugin registers the `'indent'` and `'outdent'` buttons.
|
|
61
|
+
*
|
|
62
|
+
* **Note**: In order for the commands to work, at least one of the compatible features is required. Read more in
|
|
63
|
+
* the {@link module:indent/indent~Indent indent feature} API documentation.
|
|
64
|
+
*/
|
|
65
|
+
var IndentUI = class extends Plugin {
|
|
66
|
+
/**
|
|
67
|
+
* @inheritDoc
|
|
68
|
+
*/
|
|
69
|
+
static get pluginName() {
|
|
70
|
+
return "IndentUI";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @inheritDoc
|
|
74
|
+
*/
|
|
75
|
+
static get isOfficialPlugin() {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @inheritDoc
|
|
80
|
+
*/
|
|
81
|
+
init() {
|
|
82
|
+
const editor = this.editor;
|
|
83
|
+
const locale = editor.locale;
|
|
84
|
+
const t = editor.t;
|
|
85
|
+
const localizedIndentIcon = locale.uiLanguageDirection == "ltr" ? IconIndent : IconOutdent;
|
|
86
|
+
const localizedOutdentIcon = locale.uiLanguageDirection == "ltr" ? IconOutdent : IconIndent;
|
|
87
|
+
this._defineButton("indent", t("Increase indent"), localizedIndentIcon);
|
|
88
|
+
this._defineButton("outdent", t("Decrease indent"), localizedOutdentIcon);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Defines UI buttons for both toolbar and menu bar.
|
|
92
|
+
*/
|
|
93
|
+
_defineButton(commandName, label, icon) {
|
|
94
|
+
const editor = this.editor;
|
|
95
|
+
editor.ui.componentFactory.add(commandName, () => {
|
|
96
|
+
const buttonView = this._createButton(ButtonView, commandName, label, icon);
|
|
97
|
+
buttonView.set({ tooltip: true });
|
|
98
|
+
return buttonView;
|
|
99
|
+
});
|
|
100
|
+
editor.ui.componentFactory.add("menuBar:" + commandName, () => {
|
|
101
|
+
return this._createButton(MenuBarMenuListItemButtonView, commandName, label, icon);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a button to use either in toolbar or in menu bar.
|
|
106
|
+
*/
|
|
107
|
+
_createButton(ButtonClass, commandName, label, icon) {
|
|
108
|
+
const editor = this.editor;
|
|
109
|
+
const command = editor.commands.get(commandName);
|
|
110
|
+
const view = new ButtonClass(editor.locale);
|
|
111
|
+
view.set({
|
|
112
|
+
label,
|
|
113
|
+
icon
|
|
114
|
+
});
|
|
115
|
+
view.bind("isEnabled").to(command, "isEnabled");
|
|
116
|
+
this.listenTo(view, "execute", () => {
|
|
117
|
+
editor.execute(commandName);
|
|
118
|
+
editor.editing.view.focus();
|
|
119
|
+
});
|
|
120
|
+
return view;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
102
123
|
|
|
103
124
|
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*
|
|
118
|
-
* The
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
125
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
126
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* @module indent/indent
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* The indent feature.
|
|
133
|
+
*
|
|
134
|
+
* This plugin acts as a single entry point plugin for other features that implement indentation of elements like lists or paragraphs.
|
|
135
|
+
*
|
|
136
|
+
* The compatible features are:
|
|
137
|
+
*
|
|
138
|
+
* * The {@link module:list/list~List} or {@link module:list/list/listediting~ListEditing} feature for list indentation.
|
|
139
|
+
* * The {@link module:indent/indentblock~IndentBlock} feature for block indentation.
|
|
140
|
+
*
|
|
141
|
+
* This is a "glue" plugin that loads the following plugins:
|
|
142
|
+
*
|
|
143
|
+
* * The {@link module:indent/indentediting~IndentEditing indent editing feature}.
|
|
144
|
+
* * The {@link module:indent/indentui~IndentUI indent UI feature}.
|
|
145
|
+
*
|
|
146
|
+
* The dependent plugins register the `'indent'` and `'outdent'` commands and introduce the `'indent'` and `'outdent'` buttons
|
|
147
|
+
* that allow to increase or decrease text indentation of supported elements.
|
|
148
|
+
*
|
|
149
|
+
* **Note**: In order for the commands and buttons to work, at least one of compatible features is required.
|
|
150
|
+
*/
|
|
151
|
+
var Indent = class extends Plugin {
|
|
152
|
+
/**
|
|
153
|
+
* @inheritDoc
|
|
154
|
+
*/
|
|
155
|
+
static get pluginName() {
|
|
156
|
+
return "Indent";
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @inheritDoc
|
|
160
|
+
*/
|
|
161
|
+
static get isOfficialPlugin() {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @inheritDoc
|
|
166
|
+
*/
|
|
167
|
+
static get requires() {
|
|
168
|
+
return [IndentEditing, IndentUI];
|
|
169
|
+
}
|
|
170
|
+
};
|
|
142
171
|
|
|
143
172
|
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
173
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
174
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* @module indent/indentblockcommand
|
|
178
|
+
*/
|
|
179
|
+
/**
|
|
180
|
+
* The indent block command.
|
|
181
|
+
*
|
|
182
|
+
* The command is registered by the {@link module:indent/indentblock~IndentBlock} as `'indentBlock'` for indenting blocks and
|
|
183
|
+
* `'outdentBlock'` for outdenting blocks.
|
|
184
|
+
*
|
|
185
|
+
* To increase block indentation at the current selection, execute the command:
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* editor.execute( 'indentBlock' );
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* To decrease block indentation at the current selection, execute the command:
|
|
192
|
+
*
|
|
193
|
+
* ```ts
|
|
194
|
+
* editor.execute( 'outdentBlock' );
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
var IndentBlockCommand = class extends Command {
|
|
198
|
+
/**
|
|
199
|
+
* The command's indentation behavior.
|
|
200
|
+
*/
|
|
201
|
+
_indentBehavior;
|
|
202
|
+
/**
|
|
203
|
+
* Creates an instance of the command.
|
|
204
|
+
*/
|
|
205
|
+
constructor(editor, indentBehavior) {
|
|
206
|
+
super(editor);
|
|
207
|
+
this._indentBehavior = indentBehavior;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @inheritDoc
|
|
211
|
+
*/
|
|
212
|
+
refresh() {
|
|
213
|
+
const model = this.editor.model;
|
|
214
|
+
const block = first(model.document.selection.getSelectedBlocks());
|
|
215
|
+
if (!block || !this._isIndentationChangeAllowed(block)) {
|
|
216
|
+
this.isEnabled = false;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
this.isEnabled = this._indentBehavior.checkEnabled(block.getAttribute("blockIndent"));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @inheritDoc
|
|
223
|
+
*/
|
|
224
|
+
execute() {
|
|
225
|
+
const model = this.editor.model;
|
|
226
|
+
const blocksToChange = this._getBlocksToChange();
|
|
227
|
+
model.change((writer) => {
|
|
228
|
+
for (const block of blocksToChange) {
|
|
229
|
+
const currentIndent = block.getAttribute("blockIndent");
|
|
230
|
+
const nextIndent = this._indentBehavior.getNextIndent(currentIndent);
|
|
231
|
+
if (nextIndent) writer.setAttribute("blockIndent", nextIndent, block);
|
|
232
|
+
else writer.removeAttribute("blockIndent", block);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns blocks from selection that should have blockIndent selection set.
|
|
238
|
+
*/
|
|
239
|
+
_getBlocksToChange() {
|
|
240
|
+
const selection = this.editor.model.document.selection;
|
|
241
|
+
return Array.from(selection.getSelectedBlocks()).filter((block) => this._isIndentationChangeAllowed(block));
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Returns false if indentation cannot be applied, i.e.:
|
|
245
|
+
* - for blocks disallowed by schema declaration
|
|
246
|
+
* - for blocks in Document Lists (disallowed forward indentation only). See https://github.com/ckeditor/ckeditor5/issues/14155.
|
|
247
|
+
* Otherwise returns true.
|
|
248
|
+
*/
|
|
249
|
+
_isIndentationChangeAllowed(element) {
|
|
250
|
+
const editor = this.editor;
|
|
251
|
+
if (!editor.model.schema.checkAttribute(element, "blockIndent")) return false;
|
|
252
|
+
if (!editor.plugins.has("ListUtils")) return true;
|
|
253
|
+
if (!this._indentBehavior.isForward) return true;
|
|
254
|
+
return !editor.plugins.get("ListUtils").isListItemBlock(element);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
228
257
|
|
|
229
258
|
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
259
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
260
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
261
|
+
*/
|
|
262
|
+
/**
|
|
263
|
+
* The block indentation behavior that uses offsets to set indentation.
|
|
264
|
+
*
|
|
265
|
+
* @internal
|
|
266
|
+
*/
|
|
267
|
+
var IndentUsingOffset = class {
|
|
268
|
+
/**
|
|
269
|
+
* The direction of indentation.
|
|
270
|
+
*/
|
|
271
|
+
isForward;
|
|
272
|
+
/**
|
|
273
|
+
* The offset of the next indentation step.
|
|
274
|
+
*/
|
|
275
|
+
offset;
|
|
276
|
+
/**
|
|
277
|
+
* Indentation unit.
|
|
278
|
+
*/
|
|
279
|
+
unit;
|
|
280
|
+
/**
|
|
281
|
+
* Creates an instance of the indentation behavior.
|
|
282
|
+
*
|
|
283
|
+
* @param config.direction The direction of indentation.
|
|
284
|
+
* @param config.offset The offset of the next indentation step.
|
|
285
|
+
* @param config.unit Indentation unit.
|
|
286
|
+
*/
|
|
287
|
+
constructor(config) {
|
|
288
|
+
this.isForward = config.direction === "forward";
|
|
289
|
+
this.offset = config.offset;
|
|
290
|
+
this.unit = config.unit;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* @inheritDoc
|
|
294
|
+
*/
|
|
295
|
+
checkEnabled(indentAttributeValue) {
|
|
296
|
+
const currentOffset = parseFloat(indentAttributeValue || "0");
|
|
297
|
+
return this.isForward || currentOffset > 0;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @inheritDoc
|
|
301
|
+
*/
|
|
302
|
+
getNextIndent(indentAttributeValue) {
|
|
303
|
+
const currentOffset = parseFloat(indentAttributeValue || "0");
|
|
304
|
+
const isSameUnit = !indentAttributeValue || indentAttributeValue.endsWith(this.unit);
|
|
305
|
+
if (currentOffset < 0) return;
|
|
306
|
+
if (!isSameUnit) return this.isForward ? this.offset + this.unit : void 0;
|
|
307
|
+
const offsetToSet = currentOffset + (this.isForward ? this.offset : -this.offset);
|
|
308
|
+
return offsetToSet > 0 ? offsetToSet + this.unit : void 0;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
282
311
|
|
|
283
312
|
/**
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
313
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
314
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
315
|
+
*/
|
|
316
|
+
/**
|
|
317
|
+
* The block indentation behavior that uses classes to set indentation.
|
|
318
|
+
*
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
321
|
+
var IndentUsingClasses = class {
|
|
322
|
+
/**
|
|
323
|
+
* The direction of indentation.
|
|
324
|
+
*/
|
|
325
|
+
isForward;
|
|
326
|
+
/**
|
|
327
|
+
* A list of classes used for indentation.
|
|
328
|
+
*/
|
|
329
|
+
classes;
|
|
330
|
+
/**
|
|
331
|
+
* Creates an instance of the indentation behavior.
|
|
332
|
+
*
|
|
333
|
+
* @param config.direction The direction of indentation.
|
|
334
|
+
* @param config.classes A list of classes used for indentation.
|
|
335
|
+
*/
|
|
336
|
+
constructor(config) {
|
|
337
|
+
this.isForward = config.direction === "forward";
|
|
338
|
+
this.classes = config.classes;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* @inheritDoc
|
|
342
|
+
*/
|
|
343
|
+
checkEnabled(indentAttributeValue) {
|
|
344
|
+
const currentIndex = this.classes.indexOf(indentAttributeValue);
|
|
345
|
+
if (this.isForward) return currentIndex < this.classes.length - 1;
|
|
346
|
+
else return currentIndex >= 0;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @inheritDoc
|
|
350
|
+
*/
|
|
351
|
+
getNextIndent(indentAttributeValue) {
|
|
352
|
+
const nextIndex = this.classes.indexOf(indentAttributeValue) + (this.isForward ? 1 : -1);
|
|
353
|
+
const nextIndexClamped = Math.min(nextIndex, this.classes.length - 1);
|
|
354
|
+
return this.classes[nextIndexClamped];
|
|
355
|
+
}
|
|
356
|
+
};
|
|
328
357
|
|
|
329
358
|
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
359
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
360
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
361
|
+
*/
|
|
362
|
+
/**
|
|
363
|
+
* @module indent/integrations/indentblocklistcommand
|
|
364
|
+
*/
|
|
365
|
+
/**
|
|
366
|
+
* The indent block list command.
|
|
367
|
+
*
|
|
368
|
+
* The command is registered by the {@link module:indent/integrations/indentblocklistintegration~IndentBlockListIntegration} as
|
|
369
|
+
* `'indentBlockList'` for indenting lists and `'outdentBlockList'` for outdenting lists.
|
|
370
|
+
*
|
|
371
|
+
* To increase/decrease block indentation of the list the selection must be at the start of the first top–level list item
|
|
372
|
+
* in the list.
|
|
373
|
+
*
|
|
374
|
+
* To increase block indentation of the list, execute the command:
|
|
375
|
+
*
|
|
376
|
+
* ```ts
|
|
377
|
+
* editor.execute( 'indentBlockList' );
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* To decrease block indentation of the list, execute the command:
|
|
381
|
+
*
|
|
382
|
+
* ```ts
|
|
383
|
+
* editor.execute( 'outdentBlockList' );
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
var IndentBlockListCommand = class extends Command {
|
|
387
|
+
/**
|
|
388
|
+
* The command's indentation behavior.
|
|
389
|
+
*/
|
|
390
|
+
_indentBehavior;
|
|
391
|
+
/**
|
|
392
|
+
* Creates an instance of the command.
|
|
393
|
+
*/
|
|
394
|
+
constructor(editor, indentBehavior) {
|
|
395
|
+
super(editor);
|
|
396
|
+
this._indentBehavior = indentBehavior;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* @inheritDoc
|
|
400
|
+
*/
|
|
401
|
+
refresh() {
|
|
402
|
+
const listItem = this._getFirstListItemIfSelectionIsAtListStart(this.editor.model.document.selection);
|
|
403
|
+
this.isEnabled = !!listItem && this._indentBehavior.checkEnabled(listItem.getAttribute("blockIndentList"));
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Executes the command.
|
|
407
|
+
*
|
|
408
|
+
* @fires execute
|
|
409
|
+
* @param options Command options.
|
|
410
|
+
* @param options.firstListOnly When `true`, indentation is applied only to the first list at the beginning of the selection.
|
|
411
|
+
* When `false` or omitted, indentation is applied to all lists of the selection.
|
|
412
|
+
*/
|
|
413
|
+
execute(options = {}) {
|
|
414
|
+
const editor = this.editor;
|
|
415
|
+
const model = editor.model;
|
|
416
|
+
const selection = model.document.selection;
|
|
417
|
+
const listUtils = editor.plugins.get("ListUtils");
|
|
418
|
+
model.change((writer) => {
|
|
419
|
+
const listItem = this._getFirstListItemIfSelectionIsAtListStart(selection);
|
|
420
|
+
const listItems = [];
|
|
421
|
+
if (!options.firstListOnly) {
|
|
422
|
+
const blocks = Array.from(selection.getSelectedBlocks());
|
|
423
|
+
for (const block of blocks) if (_isListItemBlock(block) && block.getAttribute("listIndent") === 0 && model.schema.checkAttribute(block, "blockIndentList")) listItems.push(block);
|
|
424
|
+
} else listItems.push(listItem);
|
|
425
|
+
const expandedListItems = listUtils.expandListBlocksToCompleteList(listItems);
|
|
426
|
+
for (const item of expandedListItems) {
|
|
427
|
+
const currentIndent = item.getAttribute("blockIndentList");
|
|
428
|
+
const nextIndent = this._indentBehavior.getNextIndent(currentIndent);
|
|
429
|
+
if (nextIndent) writer.setAttribute("blockIndentList", nextIndent, item);
|
|
430
|
+
else writer.removeAttribute("blockIndentList", item);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Returns the list item at the beginning of the current selection if it is the first top–level list item in the list.
|
|
436
|
+
* Otherwise, returns `null`.
|
|
437
|
+
*/
|
|
438
|
+
_getFirstListItemIfSelectionIsAtListStart(selection) {
|
|
439
|
+
const position = selection.getFirstPosition();
|
|
440
|
+
const listUtils = this.editor.plugins.get("ListUtils");
|
|
441
|
+
const parent = position.parent;
|
|
442
|
+
const schema = this.editor.model.schema;
|
|
443
|
+
if (position.isAtStart && _isListItemBlock(parent) && parent.getAttribute("listIndent") == 0 && schema.checkAttribute(parent, "blockIndentList") && listUtils.isFirstListItemInList(parent)) return parent;
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
417
447
|
|
|
418
448
|
/**
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
449
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
450
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
451
|
+
*/
|
|
452
|
+
/**
|
|
453
|
+
* @module indent/integrations/indentblocklistitemcommand
|
|
454
|
+
*/
|
|
455
|
+
/**
|
|
456
|
+
* The indent block list item command.
|
|
457
|
+
*
|
|
458
|
+
* The command is registered by the {@link module:indent/integrations/indentblocklistintegration~IndentBlockListIntegration} as
|
|
459
|
+
* `'indentBlockListItem'` for indenting list items and `'outdentBlockListItem'` for outdenting list items.
|
|
460
|
+
*
|
|
461
|
+
* It's only possible to reset the block indentation of a list item to `0`.
|
|
462
|
+
* This means that if a list item has negative block indentation, the command will only allow forward indentation
|
|
463
|
+
* to make it possible to reset it to `0` and if a list item has positive block indentation, the command
|
|
464
|
+
* will only allow backward indentation to make it possible to reset it to `0`.
|
|
465
|
+
*
|
|
466
|
+
* To increase block indentation of the list item, execute the command:
|
|
467
|
+
*
|
|
468
|
+
* ```ts
|
|
469
|
+
* editor.execute( 'indentBlockListItem' );
|
|
470
|
+
* ```
|
|
471
|
+
*
|
|
472
|
+
* To decrease block indentation of the list item, execute the command:
|
|
473
|
+
*
|
|
474
|
+
* ```ts
|
|
475
|
+
* editor.execute( 'outdentBlockListItem' );
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
var IndentBlockListItemCommand = class extends Command {
|
|
479
|
+
/**
|
|
480
|
+
* The command's indentation behavior.
|
|
481
|
+
*/
|
|
482
|
+
_indentBehavior;
|
|
483
|
+
/**
|
|
484
|
+
* Creates an instance of the command.
|
|
485
|
+
*/
|
|
486
|
+
constructor(editor, indentBehavior) {
|
|
487
|
+
super(editor);
|
|
488
|
+
this._indentBehavior = indentBehavior;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* @inheritDoc
|
|
492
|
+
*/
|
|
493
|
+
refresh() {
|
|
494
|
+
this.isEnabled = this._getAffectedListItems().length > 0;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* @inheritDoc
|
|
498
|
+
*/
|
|
499
|
+
execute() {
|
|
500
|
+
this.editor.model.change((writer) => {
|
|
501
|
+
for (const block of this._getAffectedListItems()) writer.removeAttribute("blockIndentListItem", block);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Returns an array of list items which block indentation should be changed.
|
|
506
|
+
*/
|
|
507
|
+
_getAffectedListItems() {
|
|
508
|
+
const selection = this.editor.model.document.selection;
|
|
509
|
+
const listUtils = this.editor.plugins.get("ListUtils");
|
|
510
|
+
const blocksInSelection = Array.from(selection.getSelectedBlocks());
|
|
511
|
+
return listUtils.expandListBlocksToCompleteItems(blocksInSelection).filter((block) => this._isIndentationChangeAllowed(block));
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Returns `true` if changing the block indentation is allowed for the given list item.
|
|
515
|
+
*/
|
|
516
|
+
_isIndentationChangeAllowed(element) {
|
|
517
|
+
if (!element.hasAttribute("blockIndentListItem")) return false;
|
|
518
|
+
return this._indentBehavior.checkEnabled(element.getAttribute("blockIndentListItem"));
|
|
519
|
+
}
|
|
520
|
+
};
|
|
485
521
|
|
|
486
522
|
/**
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
523
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
524
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
525
|
+
*/
|
|
526
|
+
/**
|
|
527
|
+
* @module indent/indentcommandbehavior/resetindentusingoffset
|
|
528
|
+
*/
|
|
529
|
+
/**
|
|
530
|
+
* The list item block indentation behavior that resets offset-based indentation toward zero.
|
|
531
|
+
*
|
|
532
|
+
* Unlike {@link module:indent/indentcommandbehavior/indentusingoffset~IndentUsingOffset}, this behavior
|
|
533
|
+
* is enabled only when the current indentation value can be moved toward zero:
|
|
534
|
+
* - for forward direction only when the current offset is negative,
|
|
535
|
+
* - for backward direction only when the current offset is positive.
|
|
536
|
+
*
|
|
537
|
+
* @internal
|
|
538
|
+
*/
|
|
539
|
+
var ResetIndentUsingOffset = class extends IndentUsingOffset {
|
|
540
|
+
/**
|
|
541
|
+
* @inheritDoc
|
|
542
|
+
*/
|
|
543
|
+
checkEnabled(indentAttributeValue) {
|
|
544
|
+
const currentOffset = parseFloat(indentAttributeValue);
|
|
545
|
+
return this.isForward && currentOffset < 0 || !this.isForward && currentOffset > 0;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
503
548
|
|
|
504
549
|
/**
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
550
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
551
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
552
|
+
*/
|
|
553
|
+
/**
|
|
554
|
+
* @module indent/indentcommandbehavior/resetindentusingclasses
|
|
555
|
+
*/
|
|
556
|
+
/**
|
|
557
|
+
* The list item block indentation behavior that resets class-based indentation toward zero.
|
|
558
|
+
*
|
|
559
|
+
* Unlike {@link module:indent/indentcommandbehavior/indentusingclasses~IndentUsingClasses}, this behavior
|
|
560
|
+
* is enabled only in the backward (outdent) direction when a class-based indentation is set.
|
|
561
|
+
* This is because class-based indentation values cannot be negative, so the only way to reset
|
|
562
|
+
* them to zero is to remove the class by outdenting.
|
|
563
|
+
*
|
|
564
|
+
* @internal
|
|
565
|
+
*/
|
|
566
|
+
var ResetIndentUsingClasses = class extends IndentUsingClasses {
|
|
567
|
+
/**
|
|
568
|
+
* @inheritDoc
|
|
569
|
+
*/
|
|
570
|
+
checkEnabled(indentAttributeValue) {
|
|
571
|
+
return !this.isForward && !!indentAttributeValue;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
520
574
|
|
|
521
575
|
/**
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
* @inheritDoc
|
|
526
|
-
*/ static get pluginName() {
|
|
527
|
-
return 'IndentBlockListIntegration';
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* @inheritDoc
|
|
531
|
-
*/ static get isOfficialPlugin() {
|
|
532
|
-
return true;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* @inheritDoc
|
|
536
|
-
*/ init() {
|
|
537
|
-
const editor = this.editor;
|
|
538
|
-
if (!this.editor.plugins.has('ListEditing')) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const config = editor.config.get('indentBlock');
|
|
542
|
-
if (config.classes && config.classes.length) {
|
|
543
|
-
this._setupConversionUsingClasses(config.classes, 'ol', 'blockIndentList', 'list');
|
|
544
|
-
this._setupConversionUsingClasses(config.classes, 'ul', 'blockIndentList', 'list');
|
|
545
|
-
this._setupConversionUsingClasses(config.classes, 'li', 'blockIndentListItem', 'item');
|
|
546
|
-
editor.commands.add('indentBlockList', new IndentBlockListCommand(editor, new IndentUsingClasses({
|
|
547
|
-
direction: 'forward',
|
|
548
|
-
classes: config.classes
|
|
549
|
-
})));
|
|
550
|
-
editor.commands.add('outdentBlockList', new IndentBlockListCommand(editor, new IndentUsingClasses({
|
|
551
|
-
direction: 'backward',
|
|
552
|
-
classes: config.classes
|
|
553
|
-
})));
|
|
554
|
-
editor.commands.add('indentBlockListItem', new IndentBlockListItemCommand(editor, new ResetIndentUsingClasses({
|
|
555
|
-
direction: 'forward',
|
|
556
|
-
classes: config.classes
|
|
557
|
-
})));
|
|
558
|
-
editor.commands.add('outdentBlockListItem', new IndentBlockListItemCommand(editor, new ResetIndentUsingClasses({
|
|
559
|
-
direction: 'backward',
|
|
560
|
-
classes: config.classes
|
|
561
|
-
})));
|
|
562
|
-
} else {
|
|
563
|
-
editor.data.addStyleProcessorRules(addMarginStylesRules);
|
|
564
|
-
this._setupConversionUsingOffset('ol', 'blockIndentList', 'list');
|
|
565
|
-
this._setupConversionUsingOffset('ul', 'blockIndentList', 'list');
|
|
566
|
-
this._setupConversionUsingOffset('li', 'blockIndentListItem', 'item');
|
|
567
|
-
editor.commands.add('indentBlockList', new IndentBlockListCommand(editor, new IndentUsingOffset({
|
|
568
|
-
direction: 'forward',
|
|
569
|
-
offset: config.offset,
|
|
570
|
-
unit: config.unit
|
|
571
|
-
})));
|
|
572
|
-
editor.commands.add('outdentBlockList', new IndentBlockListCommand(editor, new IndentUsingOffset({
|
|
573
|
-
direction: 'backward',
|
|
574
|
-
offset: config.offset,
|
|
575
|
-
unit: config.unit
|
|
576
|
-
})));
|
|
577
|
-
editor.commands.add('indentBlockListItem', new IndentBlockListItemCommand(editor, new ResetIndentUsingOffset({
|
|
578
|
-
direction: 'forward',
|
|
579
|
-
offset: config.offset,
|
|
580
|
-
unit: config.unit
|
|
581
|
-
})));
|
|
582
|
-
editor.commands.add('outdentBlockListItem', new IndentBlockListItemCommand(editor, new ResetIndentUsingOffset({
|
|
583
|
-
direction: 'backward',
|
|
584
|
-
offset: config.offset,
|
|
585
|
-
unit: config.unit
|
|
586
|
-
})));
|
|
587
|
-
}
|
|
588
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
589
|
-
// Make sure that all items in a single list (items at the same level & listType) have the same blockIndentList attribute value.
|
|
590
|
-
// Also make sure that all block in a single list item (blocks with the same listItemId) have the same
|
|
591
|
-
// blockIndentListItem attribute value.
|
|
592
|
-
listEditing.on('postFixer', (evt, { listNodes, writer })=>{
|
|
593
|
-
for (const { node, previousNodeInList } of listNodes){
|
|
594
|
-
// This is a first item of a nested list.
|
|
595
|
-
if (!previousNodeInList) {
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
if (previousNodeInList.getAttribute('listType') != node.getAttribute('listType')) {
|
|
599
|
-
continue;
|
|
600
|
-
}
|
|
601
|
-
if (ensureIndentValuesConsistency('blockIndentList', node, previousNodeInList, writer)) {
|
|
602
|
-
evt.return = true;
|
|
603
|
-
}
|
|
604
|
-
if (previousNodeInList.getAttribute('listItemId') != node.getAttribute('listItemId')) {
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
if (ensureIndentValuesConsistency('blockIndentListItem', node, previousNodeInList, writer)) {
|
|
608
|
-
evt.return = true;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
this.listenTo(editor.editing.view.document, 'tab', (evt, data)=>{
|
|
613
|
-
const commandName = data.shiftKey ? 'outdentBlockList' : 'indentBlockList';
|
|
614
|
-
const command = this.editor.commands.get(commandName);
|
|
615
|
-
if (command.isEnabled) {
|
|
616
|
-
editor.execute(commandName, {
|
|
617
|
-
firstListOnly: true
|
|
618
|
-
});
|
|
619
|
-
data.stopPropagation();
|
|
620
|
-
data.preventDefault();
|
|
621
|
-
evt.stop();
|
|
622
|
-
}
|
|
623
|
-
}, {
|
|
624
|
-
context: 'li',
|
|
625
|
-
priority: 'high'
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* @inheritDoc
|
|
630
|
-
*/ afterInit() {
|
|
631
|
-
const editor = this.editor;
|
|
632
|
-
const model = editor.model;
|
|
633
|
-
const schema = model.schema;
|
|
634
|
-
if (!editor.plugins.has('ListEditing')) {
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
// Schema registration.
|
|
638
|
-
schema.extend('$listItem', {
|
|
639
|
-
allowAttributes: [
|
|
640
|
-
'blockIndentList',
|
|
641
|
-
'blockIndentListItem'
|
|
642
|
-
]
|
|
643
|
-
});
|
|
644
|
-
schema.setAttributeProperties('blockIndentList', {
|
|
645
|
-
isFormatting: true
|
|
646
|
-
});
|
|
647
|
-
schema.setAttributeProperties('blockIndentListItem', {
|
|
648
|
-
isFormatting: true
|
|
649
|
-
});
|
|
650
|
-
model.schema.addAttributeCheck((context)=>{
|
|
651
|
-
const item = context.last;
|
|
652
|
-
if (!item.getAttribute('listItemId')) {
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
}, 'blockIndentList');
|
|
656
|
-
model.schema.addAttributeCheck((context)=>{
|
|
657
|
-
const item = context.last;
|
|
658
|
-
if (!item.getAttribute('listItemId')) {
|
|
659
|
-
return false;
|
|
660
|
-
}
|
|
661
|
-
}, 'blockIndentListItem');
|
|
662
|
-
// Clear blockIndentList and blockIndentListItem when list indent changes.
|
|
663
|
-
const clearBlockIndentAttributesOnListIndentChange = (_evt, changedBlocks)=>{
|
|
664
|
-
editor.model.change((writer)=>{
|
|
665
|
-
for (const node of changedBlocks){
|
|
666
|
-
if (node.hasAttribute('listItemId')) {
|
|
667
|
-
if (node.hasAttribute('blockIndentList')) {
|
|
668
|
-
writer.removeAttribute('blockIndentList', node);
|
|
669
|
-
}
|
|
670
|
-
if (node.hasAttribute('blockIndentListItem')) {
|
|
671
|
-
writer.removeAttribute('blockIndentListItem', node);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
};
|
|
677
|
-
const indentListCommand = editor.commands.get('indentList');
|
|
678
|
-
const outdentListCommand = editor.commands.get('outdentList');
|
|
679
|
-
if (indentListCommand) {
|
|
680
|
-
this.listenTo(indentListCommand, 'afterExecute', clearBlockIndentAttributesOnListIndentChange);
|
|
681
|
-
}
|
|
682
|
-
if (outdentListCommand) {
|
|
683
|
-
this.listenTo(outdentListCommand, 'afterExecute', clearBlockIndentAttributesOnListIndentChange);
|
|
684
|
-
}
|
|
685
|
-
// Register list block indent commands in multi command.
|
|
686
|
-
const indentCommand = editor.commands.get('indent');
|
|
687
|
-
const outdentCommand = editor.commands.get('outdent');
|
|
688
|
-
// Priority is highest so that block indent takes precedence over list indent (`indentList` is registered
|
|
689
|
-
// at `high`). When the selection is at the start of the first list item at indent 0, the block indent
|
|
690
|
-
// command adds margin instead of increasing the list indent level. For items at higher indent levels,
|
|
691
|
-
// this command is disabled and falls through to `indentList`.
|
|
692
|
-
indentCommand.registerChildCommand(editor.commands.get('indentBlockList'), {
|
|
693
|
-
priority: 'highest'
|
|
694
|
-
});
|
|
695
|
-
outdentCommand.registerChildCommand(editor.commands.get('outdentBlockList'));
|
|
696
|
-
indentCommand.registerChildCommand(editor.commands.get('indentBlockListItem'));
|
|
697
|
-
outdentCommand.registerChildCommand(editor.commands.get('outdentBlockListItem'));
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Setups conversion for list block indent using offset.
|
|
701
|
-
*/ _setupConversionUsingOffset(element, attributeName, scope) {
|
|
702
|
-
const editor = this.editor;
|
|
703
|
-
const locale = editor.locale;
|
|
704
|
-
const conversion = editor.conversion;
|
|
705
|
-
const marginProperty = locale.contentLanguageDirection === 'rtl' ? 'margin-right' : 'margin-left';
|
|
706
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
707
|
-
conversion.for('upcast').add((dispatcher)=>{
|
|
708
|
-
dispatcher.on(`element:${element}`, listBlockIndentUpcastConverter(attributeName, (item)=>item.getStyle(marginProperty), (consumable, item)=>consumable.consume(item, {
|
|
709
|
-
styles: marginProperty
|
|
710
|
-
})), {
|
|
711
|
-
priority: 'low'
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
listEditing.registerDowncastStrategy({
|
|
715
|
-
scope,
|
|
716
|
-
attributeName,
|
|
717
|
-
setAttributeOnDowncast (writer, value, element) {
|
|
718
|
-
if (value) {
|
|
719
|
-
writer.setStyle(marginProperty, value, element);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* Setups conversion for list block indent using classes.
|
|
726
|
-
*/ _setupConversionUsingClasses(classes, element, attributeName, scope) {
|
|
727
|
-
const editor = this.editor;
|
|
728
|
-
const conversion = editor.conversion;
|
|
729
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
730
|
-
conversion.for('upcast').add((dispatcher)=>{
|
|
731
|
-
dispatcher.on(`element:${element}`, listBlockIndentUpcastConverter(attributeName, (item)=>classes.find((cls)=>item.hasClass(cls)), (consumable, item, value)=>consumable.consume(item, {
|
|
732
|
-
classes: value
|
|
733
|
-
})), {
|
|
734
|
-
priority: 'low'
|
|
735
|
-
});
|
|
736
|
-
});
|
|
737
|
-
listEditing.registerDowncastStrategy({
|
|
738
|
-
scope,
|
|
739
|
-
attributeName,
|
|
740
|
-
setAttributeOnDowncast (writer, value, element) {
|
|
741
|
-
if (value) {
|
|
742
|
-
writer.addClass(value, element);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
}
|
|
576
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
577
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
578
|
+
*/
|
|
748
579
|
/**
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
580
|
+
* This integration enables using block indentation feature with lists.
|
|
581
|
+
*/
|
|
582
|
+
var IndentBlockListIntegration = class extends Plugin {
|
|
583
|
+
/**
|
|
584
|
+
* @inheritDoc
|
|
585
|
+
*/
|
|
586
|
+
static get pluginName() {
|
|
587
|
+
return "IndentBlockListIntegration";
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* @inheritDoc
|
|
591
|
+
*/
|
|
592
|
+
static get isOfficialPlugin() {
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* @inheritDoc
|
|
597
|
+
*/
|
|
598
|
+
init() {
|
|
599
|
+
const editor = this.editor;
|
|
600
|
+
if (!this.editor.plugins.has("ListEditing")) return;
|
|
601
|
+
const config = editor.config.get("indentBlock");
|
|
602
|
+
if (config.classes && config.classes.length) {
|
|
603
|
+
this._setupConversionUsingClasses(config.classes, "ol", "blockIndentList", "list");
|
|
604
|
+
this._setupConversionUsingClasses(config.classes, "ul", "blockIndentList", "list");
|
|
605
|
+
this._setupConversionUsingClasses(config.classes, "li", "blockIndentListItem", "item");
|
|
606
|
+
editor.commands.add("indentBlockList", new IndentBlockListCommand(editor, new IndentUsingClasses({
|
|
607
|
+
direction: "forward",
|
|
608
|
+
classes: config.classes
|
|
609
|
+
})));
|
|
610
|
+
editor.commands.add("outdentBlockList", new IndentBlockListCommand(editor, new IndentUsingClasses({
|
|
611
|
+
direction: "backward",
|
|
612
|
+
classes: config.classes
|
|
613
|
+
})));
|
|
614
|
+
editor.commands.add("indentBlockListItem", new IndentBlockListItemCommand(editor, new ResetIndentUsingClasses({
|
|
615
|
+
direction: "forward",
|
|
616
|
+
classes: config.classes
|
|
617
|
+
})));
|
|
618
|
+
editor.commands.add("outdentBlockListItem", new IndentBlockListItemCommand(editor, new ResetIndentUsingClasses({
|
|
619
|
+
direction: "backward",
|
|
620
|
+
classes: config.classes
|
|
621
|
+
})));
|
|
622
|
+
} else {
|
|
623
|
+
editor.data.addStyleProcessorRules(addMarginStylesRules);
|
|
624
|
+
this._setupConversionUsingOffset("ol", "blockIndentList", "list");
|
|
625
|
+
this._setupConversionUsingOffset("ul", "blockIndentList", "list");
|
|
626
|
+
this._setupConversionUsingOffset("li", "blockIndentListItem", "item");
|
|
627
|
+
editor.commands.add("indentBlockList", new IndentBlockListCommand(editor, new IndentUsingOffset({
|
|
628
|
+
direction: "forward",
|
|
629
|
+
offset: config.offset,
|
|
630
|
+
unit: config.unit
|
|
631
|
+
})));
|
|
632
|
+
editor.commands.add("outdentBlockList", new IndentBlockListCommand(editor, new IndentUsingOffset({
|
|
633
|
+
direction: "backward",
|
|
634
|
+
offset: config.offset,
|
|
635
|
+
unit: config.unit
|
|
636
|
+
})));
|
|
637
|
+
editor.commands.add("indentBlockListItem", new IndentBlockListItemCommand(editor, new ResetIndentUsingOffset({
|
|
638
|
+
direction: "forward",
|
|
639
|
+
offset: config.offset,
|
|
640
|
+
unit: config.unit
|
|
641
|
+
})));
|
|
642
|
+
editor.commands.add("outdentBlockListItem", new IndentBlockListItemCommand(editor, new ResetIndentUsingOffset({
|
|
643
|
+
direction: "backward",
|
|
644
|
+
offset: config.offset,
|
|
645
|
+
unit: config.unit
|
|
646
|
+
})));
|
|
647
|
+
}
|
|
648
|
+
editor.plugins.get("ListEditing").on("postFixer", (evt, { listNodes, writer }) => {
|
|
649
|
+
for (const { node, previousNodeInList } of listNodes) {
|
|
650
|
+
if (!previousNodeInList) continue;
|
|
651
|
+
if (previousNodeInList.getAttribute("listType") != node.getAttribute("listType")) continue;
|
|
652
|
+
if (ensureIndentValuesConsistency("blockIndentList", node, previousNodeInList, writer)) evt.return = true;
|
|
653
|
+
if (previousNodeInList.getAttribute("listItemId") != node.getAttribute("listItemId")) continue;
|
|
654
|
+
if (ensureIndentValuesConsistency("blockIndentListItem", node, previousNodeInList, writer)) evt.return = true;
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
this.listenTo(editor.editing.view.document, "tab", (evt, data) => {
|
|
658
|
+
const commandName = data.shiftKey ? "outdentBlockList" : "indentBlockList";
|
|
659
|
+
if (this.editor.commands.get(commandName).isEnabled) {
|
|
660
|
+
editor.execute(commandName, { firstListOnly: true });
|
|
661
|
+
data.stopPropagation();
|
|
662
|
+
data.preventDefault();
|
|
663
|
+
evt.stop();
|
|
664
|
+
}
|
|
665
|
+
}, {
|
|
666
|
+
context: "li",
|
|
667
|
+
priority: "high"
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* @inheritDoc
|
|
672
|
+
*/
|
|
673
|
+
afterInit() {
|
|
674
|
+
const editor = this.editor;
|
|
675
|
+
const model = editor.model;
|
|
676
|
+
const schema = model.schema;
|
|
677
|
+
if (!editor.plugins.has("ListEditing")) return;
|
|
678
|
+
schema.extend("$listItem", { allowAttributes: ["blockIndentList", "blockIndentListItem"] });
|
|
679
|
+
schema.setAttributeProperties("blockIndentList", { isFormatting: true });
|
|
680
|
+
schema.setAttributeProperties("blockIndentListItem", { isFormatting: true });
|
|
681
|
+
model.schema.addAttributeCheck((context) => {
|
|
682
|
+
if (!context.last.getAttribute("listItemId")) return false;
|
|
683
|
+
}, "blockIndentList");
|
|
684
|
+
model.schema.addAttributeCheck((context) => {
|
|
685
|
+
if (!context.last.getAttribute("listItemId")) return false;
|
|
686
|
+
}, "blockIndentListItem");
|
|
687
|
+
const clearBlockIndentAttributesOnListIndentChange = (_evt, changedBlocks) => {
|
|
688
|
+
editor.model.change((writer) => {
|
|
689
|
+
for (const node of changedBlocks) if (node.hasAttribute("listItemId")) {
|
|
690
|
+
if (node.hasAttribute("blockIndentList")) writer.removeAttribute("blockIndentList", node);
|
|
691
|
+
if (node.hasAttribute("blockIndentListItem")) writer.removeAttribute("blockIndentListItem", node);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
const indentListCommand = editor.commands.get("indentList");
|
|
696
|
+
const outdentListCommand = editor.commands.get("outdentList");
|
|
697
|
+
if (indentListCommand) this.listenTo(indentListCommand, "afterExecute", clearBlockIndentAttributesOnListIndentChange);
|
|
698
|
+
if (outdentListCommand) this.listenTo(outdentListCommand, "afterExecute", clearBlockIndentAttributesOnListIndentChange);
|
|
699
|
+
const indentCommand = editor.commands.get("indent");
|
|
700
|
+
const outdentCommand = editor.commands.get("outdent");
|
|
701
|
+
indentCommand.registerChildCommand(editor.commands.get("indentBlockList"), { priority: "highest" });
|
|
702
|
+
outdentCommand.registerChildCommand(editor.commands.get("outdentBlockList"));
|
|
703
|
+
indentCommand.registerChildCommand(editor.commands.get("indentBlockListItem"));
|
|
704
|
+
outdentCommand.registerChildCommand(editor.commands.get("outdentBlockListItem"));
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Setups conversion for list block indent using offset.
|
|
708
|
+
*/
|
|
709
|
+
_setupConversionUsingOffset(element, attributeName, scope) {
|
|
710
|
+
const editor = this.editor;
|
|
711
|
+
const locale = editor.locale;
|
|
712
|
+
const conversion = editor.conversion;
|
|
713
|
+
const marginProperty = locale.contentLanguageDirection === "rtl" ? "margin-right" : "margin-left";
|
|
714
|
+
const listEditing = editor.plugins.get("ListEditing");
|
|
715
|
+
conversion.for("upcast").add((dispatcher) => {
|
|
716
|
+
dispatcher.on(`element:${element}`, listBlockIndentUpcastConverter(attributeName, (item) => item.getStyle(marginProperty), (consumable, item) => consumable.consume(item, { styles: marginProperty })), { priority: "low" });
|
|
717
|
+
});
|
|
718
|
+
listEditing.registerDowncastStrategy({
|
|
719
|
+
scope,
|
|
720
|
+
attributeName,
|
|
721
|
+
setAttributeOnDowncast(writer, value, element) {
|
|
722
|
+
if (value) writer.setStyle(marginProperty, value, element);
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Setups conversion for list block indent using classes.
|
|
728
|
+
*/
|
|
729
|
+
_setupConversionUsingClasses(classes, element, attributeName, scope) {
|
|
730
|
+
const editor = this.editor;
|
|
731
|
+
const conversion = editor.conversion;
|
|
732
|
+
const listEditing = editor.plugins.get("ListEditing");
|
|
733
|
+
conversion.for("upcast").add((dispatcher) => {
|
|
734
|
+
dispatcher.on(`element:${element}`, listBlockIndentUpcastConverter(attributeName, (item) => classes.find((cls) => item.hasClass(cls)), (consumable, item, value) => consumable.consume(item, { classes: value })), { priority: "low" });
|
|
735
|
+
});
|
|
736
|
+
listEditing.registerDowncastStrategy({
|
|
737
|
+
scope,
|
|
738
|
+
attributeName,
|
|
739
|
+
setAttributeOnDowncast(writer, value, element) {
|
|
740
|
+
if (value) writer.addClass(value, element);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* Returns an upcast converter for block list indentation.
|
|
747
|
+
*
|
|
748
|
+
* @param attributeName The name of the model attribute.
|
|
749
|
+
* @param getValue A function to get the value from the view element.
|
|
750
|
+
* @param consume A function to consume the view element.
|
|
751
|
+
* @returns A callback for the upcast conversion.
|
|
752
|
+
*/
|
|
753
|
+
function listBlockIndentUpcastConverter(attributeName, getValue, consume) {
|
|
754
|
+
return (evt, data, conversionApi) => {
|
|
755
|
+
const { writer, consumable } = conversionApi;
|
|
756
|
+
if (!data.modelRange) Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
|
757
|
+
const value = getValue(data.viewItem);
|
|
758
|
+
if (value === void 0) return;
|
|
759
|
+
let applied = false;
|
|
760
|
+
let indentLevel;
|
|
761
|
+
for (const item of data.modelRange.getItems({ shallow: true })) {
|
|
762
|
+
if (indentLevel === void 0) indentLevel = item.getAttribute("listIndent");
|
|
763
|
+
if (item.hasAttribute(attributeName)) continue;
|
|
764
|
+
if (item.getAttribute("listIndent") !== indentLevel) continue;
|
|
765
|
+
writer.setAttribute(attributeName, value, item);
|
|
766
|
+
applied = true;
|
|
767
|
+
}
|
|
768
|
+
if (applied) consume(consumable, data.viewItem, value);
|
|
769
|
+
};
|
|
786
770
|
}
|
|
787
771
|
/**
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
} else {
|
|
799
|
-
writer.removeAttribute(attributeName, node);
|
|
800
|
-
}
|
|
801
|
-
return true;
|
|
772
|
+
* Ensures that two nodes have the same value of the given attribute.
|
|
773
|
+
* If the values are different, the attribute value from the previous node is applied to the given node.
|
|
774
|
+
* Returns true if the attribute value was changed, false otherwise.
|
|
775
|
+
*/
|
|
776
|
+
function ensureIndentValuesConsistency(attributeName, node, previousNodeInList, writer) {
|
|
777
|
+
const prevNodeIndentListValue = previousNodeInList.getAttribute(attributeName);
|
|
778
|
+
if (node.getAttribute(attributeName) === prevNodeIndentListValue) return false;
|
|
779
|
+
if (prevNodeIndentListValue) writer.setAttribute(attributeName, prevNodeIndentListValue, node);
|
|
780
|
+
else writer.removeAttribute(attributeName, node);
|
|
781
|
+
return true;
|
|
802
782
|
}
|
|
803
783
|
|
|
784
|
+
/**
|
|
785
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
786
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
787
|
+
*/
|
|
788
|
+
/**
|
|
789
|
+
* @module indent/indentblock
|
|
790
|
+
*/
|
|
804
791
|
const DEFAULT_ELEMENTS = [
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
792
|
+
"paragraph",
|
|
793
|
+
"heading1",
|
|
794
|
+
"heading2",
|
|
795
|
+
"heading3",
|
|
796
|
+
"heading4",
|
|
797
|
+
"heading5",
|
|
798
|
+
"heading6"
|
|
812
799
|
];
|
|
813
800
|
/**
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
key: 'class',
|
|
949
|
-
value: [
|
|
950
|
-
className
|
|
951
|
-
]
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
this.editor.conversion.attributeToAttribute(definition);
|
|
955
|
-
}
|
|
956
|
-
}
|
|
801
|
+
* The block indentation feature.
|
|
802
|
+
*
|
|
803
|
+
* It registers the `'indentBlock'` and `'outdentBlock'` commands.
|
|
804
|
+
*
|
|
805
|
+
* If the plugin {@link module:indent/indent~Indent} is defined, it also attaches the `'indentBlock'` and `'outdentBlock'` commands to
|
|
806
|
+
* the `'indent'` and `'outdent'` commands.
|
|
807
|
+
*/
|
|
808
|
+
var IndentBlock = class extends Plugin {
|
|
809
|
+
/**
|
|
810
|
+
* @inheritDoc
|
|
811
|
+
*/
|
|
812
|
+
constructor(editor) {
|
|
813
|
+
super(editor);
|
|
814
|
+
editor.config.define("indentBlock", {
|
|
815
|
+
offset: 40,
|
|
816
|
+
unit: "px"
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* @inheritDoc
|
|
821
|
+
*/
|
|
822
|
+
static get pluginName() {
|
|
823
|
+
return "IndentBlock";
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* @inheritDoc
|
|
827
|
+
*/
|
|
828
|
+
static get isOfficialPlugin() {
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* @inheritDoc
|
|
833
|
+
*/
|
|
834
|
+
static get requires() {
|
|
835
|
+
return [IndentBlockListIntegration];
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* @inheritDoc
|
|
839
|
+
*/
|
|
840
|
+
init() {
|
|
841
|
+
const editor = this.editor;
|
|
842
|
+
const configuration = editor.config.get("indentBlock");
|
|
843
|
+
if (configuration.classes && configuration.classes.length) {
|
|
844
|
+
this._setupConversionUsingClasses(configuration.classes);
|
|
845
|
+
editor.commands.add("indentBlock", new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
846
|
+
direction: "forward",
|
|
847
|
+
classes: configuration.classes
|
|
848
|
+
})));
|
|
849
|
+
editor.commands.add("outdentBlock", new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
850
|
+
direction: "backward",
|
|
851
|
+
classes: configuration.classes
|
|
852
|
+
})));
|
|
853
|
+
} else {
|
|
854
|
+
editor.data.addStyleProcessorRules(addMarginStylesRules);
|
|
855
|
+
this._setupConversionUsingOffset();
|
|
856
|
+
editor.commands.add("indentBlock", new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
857
|
+
direction: "forward",
|
|
858
|
+
offset: configuration.offset,
|
|
859
|
+
unit: configuration.unit
|
|
860
|
+
})));
|
|
861
|
+
editor.commands.add("outdentBlock", new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
862
|
+
direction: "backward",
|
|
863
|
+
offset: configuration.offset,
|
|
864
|
+
unit: configuration.unit
|
|
865
|
+
})));
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* @inheritDoc
|
|
870
|
+
*/
|
|
871
|
+
afterInit() {
|
|
872
|
+
const editor = this.editor;
|
|
873
|
+
const schema = editor.model.schema;
|
|
874
|
+
const indentCommand = editor.commands.get("indent");
|
|
875
|
+
const outdentCommand = editor.commands.get("outdent");
|
|
876
|
+
const options = editor.config.get("heading.options");
|
|
877
|
+
(options && options.map((option) => option.model) || DEFAULT_ELEMENTS).forEach((elementName) => {
|
|
878
|
+
if (schema.isRegistered(elementName)) schema.extend(elementName, { allowAttributes: "blockIndent" });
|
|
879
|
+
});
|
|
880
|
+
schema.setAttributeProperties("blockIndent", { isFormatting: true });
|
|
881
|
+
indentCommand.registerChildCommand(editor.commands.get("indentBlock"));
|
|
882
|
+
outdentCommand.registerChildCommand(editor.commands.get("outdentBlock"));
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Setups conversion for using offset indents.
|
|
886
|
+
*/
|
|
887
|
+
_setupConversionUsingOffset() {
|
|
888
|
+
const conversion = this.editor.conversion;
|
|
889
|
+
const marginProperty = this.editor.locale.contentLanguageDirection === "rtl" ? "margin-right" : "margin-left";
|
|
890
|
+
conversion.for("upcast").attributeToAttribute({
|
|
891
|
+
view: { styles: { [marginProperty]: /[\s\S]+/ } },
|
|
892
|
+
model: {
|
|
893
|
+
key: "blockIndent",
|
|
894
|
+
value: (viewElement) => {
|
|
895
|
+
if (!viewElement.is("element", "li")) return viewElement.getStyle(marginProperty);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
conversion.for("downcast").attributeToAttribute({
|
|
900
|
+
model: "blockIndent",
|
|
901
|
+
view: (modelAttributeValue) => {
|
|
902
|
+
return {
|
|
903
|
+
key: "style",
|
|
904
|
+
value: { [marginProperty]: modelAttributeValue }
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Setups conversion for using classes.
|
|
911
|
+
*/
|
|
912
|
+
_setupConversionUsingClasses(classes) {
|
|
913
|
+
const definition = {
|
|
914
|
+
model: {
|
|
915
|
+
key: "blockIndent",
|
|
916
|
+
values: []
|
|
917
|
+
},
|
|
918
|
+
view: {}
|
|
919
|
+
};
|
|
920
|
+
for (const className of classes) {
|
|
921
|
+
definition.model.values.push(className);
|
|
922
|
+
definition.view[className] = {
|
|
923
|
+
key: "class",
|
|
924
|
+
value: [className]
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
this.editor.conversion.attributeToAttribute(definition);
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
933
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
934
|
+
*/
|
|
957
935
|
|
|
958
936
|
export { Indent, IndentBlock, IndentBlockCommand, IndentBlockListCommand, IndentBlockListIntegration, IndentBlockListItemCommand, IndentEditing, IndentUI, IndentUsingClasses as _IndentUsingClasses, IndentUsingOffset as _IndentUsingOffset };
|
|
959
|
-
//# sourceMappingURL=index.js.map
|
|
937
|
+
//# sourceMappingURL=index.js.map
|