8
0

delta.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. CKEDITOR.define( [], () => {
  7. /**
  8. * Base class for all deltas.
  9. *
  10. * Delta is a single, from the user action point of view, change in the editable document, like insert, split or
  11. * rename element. Delta is composed of operations, which are unit changes needed to be done to execute user action.
  12. *
  13. * Multiple deltas are grouped into a single {@link document.Transaction}.
  14. *
  15. * @class document.delta.Delta
  16. */
  17. class Delta {
  18. /**
  19. * Creates a delta instance.
  20. *
  21. * @constructor
  22. */
  23. constructor() {
  24. /**
  25. * {@link document.Transaction} which delta is a part of. This property is null by default and set by the
  26. * {@link Document.Transaction#addDelta} method.
  27. *
  28. * @readonly
  29. * @type {document.Transaction}
  30. */
  31. this.transaction = null;
  32. /**
  33. * Array of operations which compose delta.
  34. *
  35. * @readonly
  36. * @type {document.operation.Operation[]}
  37. */
  38. this.operations = [];
  39. }
  40. /**
  41. * Add operation to the delta.
  42. *
  43. * @param {document.operation.Operation} operation Operation instance.
  44. */
  45. addOperation( operation ) {
  46. operation.delta = this;
  47. this.operations.push( operation );
  48. return operation;
  49. }
  50. /**
  51. * Delta provides iterator interface which will iterate over operations in the delta.
  52. */
  53. [ Symbol.iterator ]() {
  54. return this.operations[ Symbol.iterator ]();
  55. }
  56. }
  57. return Delta;
  58. } );