1 | import Parchment from 'parchment';
|
2 |
|
3 | class IdentAttributor extends Parchment.Attributor.Class {
|
4 | add(node, value) {
|
5 | if (value === '+1' || value === '-1') {
|
6 | let indent = this.value(node) || 0;
|
7 | value = (value === '+1' ? (indent + 1) : (indent - 1));
|
8 | }
|
9 | if (value === 0) {
|
10 | this.remove(node);
|
11 | return true;
|
12 | } else {
|
13 | return super.add(node, value);
|
14 | }
|
15 | }
|
16 |
|
17 | canAdd(node, value) {
|
18 | return super.canAdd(node, value) || super.canAdd(node, parseInt(value));
|
19 | }
|
20 |
|
21 | value(node) {
|
22 | return parseInt(super.value(node)) || undefined;
|
23 | }
|
24 | }
|
25 |
|
26 | let IndentClass = new IdentAttributor('indent', 'ql-indent', {
|
27 | scope: Parchment.Scope.BLOCK,
|
28 | whitelist: [1, 2, 3, 4, 5, 6, 7, 8]
|
29 | });
|
30 |
|
31 | export { IndentClass };
|