9bac0c21a821b645cac84f1b67f99a29dd33a04398fb0bef01e125416b517cb64f624ff55a9923a68d7c18989ea5856c57a5ef108d6b397d1212b2779f24f0 951 B

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