indent.js 763 B

12345678910111213141516171819202122232425262728293031
  1. import Parchment from 'parchment';
  2. class IdentAttributor extends Parchment.Attributor.Class {
  3. add(node, value) {
  4. if (value === '+1' || value === '-1') {
  5. let 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. } else {
  12. return super.add(node, value);
  13. }
  14. }
  15. canAdd(node, value) {
  16. return super.canAdd(node, value) || super.canAdd(node, parseInt(value));
  17. }
  18. value(node) {
  19. return parseInt(super.value(node)) || undefined; // Don't return NaN
  20. }
  21. }
  22. let IndentClass = new IdentAttributor('indent', 'ql-indent', {
  23. scope: Parchment.Scope.BLOCK,
  24. whitelist: [1, 2, 3, 4, 5, 6, 7, 8]
  25. });
  26. export { IndentClass };