78e58da709ecf8190c94c577238cfdee5bf7244b7f1e9b9498c530cfe060ca148bc64e4e4a4bd932bd1fee8dce163a946c0abf771962fee047813d8496dda4 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import * as diff from 'fast-diff';
  2. import AttributeMap from './AttributeMap';
  3. import Op from './Op';
  4. import OpIterator from './OpIterator';
  5. interface EmbedHandler<T> {
  6. compose(a: T, b: T, keepNull: boolean): T;
  7. invert(a: T, b: T): T;
  8. transform(a: T, b: T, priority: boolean): T;
  9. }
  10. declare class Delta {
  11. static Op: typeof Op;
  12. static OpIterator: typeof OpIterator;
  13. static AttributeMap: typeof AttributeMap;
  14. private static handlers;
  15. static registerEmbed<T>(embedType: string, handler: EmbedHandler<T>): void;
  16. static unregisterEmbed(embedType: string): void;
  17. private static getHandler;
  18. ops: Op[];
  19. constructor(ops?: Op[] | {
  20. ops: Op[];
  21. });
  22. insert(arg: string | Record<string, unknown>, attributes?: AttributeMap | null): this;
  23. delete(length: number): this;
  24. retain(length: number | Record<string, unknown>, attributes?: AttributeMap | null): this;
  25. push(newOp: Op): this;
  26. chop(): this;
  27. filter(predicate: (op: Op, index: number) => boolean): Op[];
  28. forEach(predicate: (op: Op, index: number) => void): void;
  29. map<T>(predicate: (op: Op, index: number) => T): T[];
  30. partition(predicate: (op: Op) => boolean): [Op[], Op[]];
  31. reduce<T>(predicate: (accum: T, curr: Op, index: number) => T, initialValue: T): T;
  32. changeLength(): number;
  33. length(): number;
  34. slice(start?: number, end?: number): Delta;
  35. compose(other: Delta): Delta;
  36. concat(other: Delta): Delta;
  37. diff(other: Delta, cursor?: number | diff.CursorInfo): Delta;
  38. eachLine(predicate: (line: Delta, attributes: AttributeMap, index: number) => boolean | void, newline?: string): void;
  39. invert(base: Delta): Delta;
  40. transform(index: number, priority?: boolean): number;
  41. transform(other: Delta, priority?: boolean): Delta;
  42. transformPosition(index: number, priority?: boolean): number;
  43. }
  44. export default Delta;
  45. export { Op, OpIterator, AttributeMap };