7bf920b4cd497fedf7bd4c6474bdaa0cdb4e30f9fcf95009f5fbec807494f53ca40f737b01718329b9cc8093bfd7e0c7eb9693c749abf5e1d50dcd6fd856a7 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import Scope from '../../scope.js';
  2. import BlockBlot from '../block.js';
  3. import ParentBlot from './parent.js';
  4. class ContainerBlot extends ParentBlot {
  5. public static blotName = 'container';
  6. public static scope = Scope.BLOCK_BLOT;
  7. public static tagName: string | string[];
  8. public prev!: BlockBlot | ContainerBlot | null;
  9. public next!: BlockBlot | ContainerBlot | null;
  10. public checkMerge(): boolean {
  11. return (
  12. this.next !== null && this.next.statics.blotName === this.statics.blotName
  13. );
  14. }
  15. public deleteAt(index: number, length: number): void {
  16. super.deleteAt(index, length);
  17. this.enforceAllowedChildren();
  18. }
  19. public formatAt(
  20. index: number,
  21. length: number,
  22. name: string,
  23. value: any,
  24. ): void {
  25. super.formatAt(index, length, name, value);
  26. this.enforceAllowedChildren();
  27. }
  28. public insertAt(index: number, value: string, def?: any): void {
  29. super.insertAt(index, value, def);
  30. this.enforceAllowedChildren();
  31. }
  32. public optimize(context: { [key: string]: any }): void {
  33. super.optimize(context);
  34. if (this.children.length > 0 && this.next != null && this.checkMerge()) {
  35. this.next.moveChildren(this);
  36. this.next.remove();
  37. }
  38. }
  39. }
  40. export default ContainerBlot;