indent.js 756 B

123456789101112131415161718192021222324252627282930
  1. import { ClassAttributor, Scope } from 'parchment';
  2. class IndentAttributor extends ClassAttributor {
  3. add(node, value) {
  4. if (value === '+1' || value === '-1') {
  5. const indent = this.value(node) || 0;
  6. value = value === '+1' ? indent + 1 : indent - 1;
  7. }
  8. if (value === 0) {
  9. this.remove(node);
  10. return true;
  11. }
  12. return super.add(node, value);
  13. }
  14. canAdd(node, value) {
  15. return super.canAdd(node, value) || super.canAdd(node, parseInt(value, 10));
  16. }
  17. value(node) {
  18. return parseInt(super.value(node), 10) || undefined; // Don't return NaN
  19. }
  20. }
  21. const IndentClass = new IndentAttributor('indent', 'ql-indent', {
  22. scope: Scope.BLOCK,
  23. whitelist: [1, 2, 3, 4, 5, 6, 7, 8],
  24. });
  25. export default IndentClass;