operation.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * Abstract base operation class.
  9. *
  10. * @abstract
  11. * @class document.operation.Operation
  12. */
  13. class Operation {
  14. /**
  15. * Base operation constructor.
  16. *
  17. * @param {Number} baseVersion {@link document.Document#version} on which the operation can be applied.
  18. * @constructor
  19. */
  20. constructor( baseVersion ) {
  21. /**
  22. * {@link document.Document#version} on which operation can be applied. If you try to
  23. * {@link document.Document#applyOperation apply} operation with different base version than the
  24. * {@link document.Document#version document version} the {@link document-applyOperation-wrong-version}
  25. * error is thrown.
  26. *
  27. * @property {Number}
  28. */
  29. this.baseVersion = baseVersion;
  30. /**
  31. * {@link Document.Delta Delta} which the operation is a part of. This property is set by the
  32. * {@link Document.Delta delta} when the operations is added to it by the
  33. * {@link Document.Delta#addOperation} method.
  34. *
  35. * @property {Document.Delta} delta
  36. */
  37. /**
  38. * Executes the operation - modifications described by the operation attributes
  39. * will be applied to the tree model.
  40. *
  41. * @method _execute
  42. * @protected
  43. */
  44. /**
  45. * Creates and returns a reverse operation. Reverse operation when executed right after
  46. * the original operation will bring back tree model state to the point before the original
  47. * operation execution. In other words, it reverses changes done by the original operation.
  48. *
  49. * Keep in mind that tree model state may change since executing the original operation,
  50. * so reverse operation will be "outdated". In that case you will need to
  51. * {@link #getTransformedBy transform} it by all operations that were executed after the original operation.
  52. *
  53. * @method getReversed
  54. * @returns {document.operation.Operation} Reversed operation.
  55. */
  56. /**
  57. * Creates and returns a clone of this operation which is transformed by the given operation.
  58. * When operation is transformed its parameters may change accordingly to the operation which it is
  59. * transformed by. If the given operation applied to the tree model any modifications which are
  60. * affecting ranges/positions/nodes connected with this operation, those changes will be reflected
  61. * in the parameters of the returned operation.
  62. *
  63. * Whenever the {@link document.Document document} has different {@link document.Document#baseVersion}
  64. * than an operation you want to {@link document.Document#applyOperation apply}, you need to transform
  65. * all the operations that were executed on the {@link document.Document document} since it has
  66. * {@link document.Document#baseVersion} same as the operation (transform in the same order as those
  67. * operations were executed). This way all modifications done to the tree model will be reflected
  68. * in the operation parameters and the operation will "work" on "up-to-date" version of the tree model.
  69. *
  70. * **TODO**: So far we think that transforming one operation by another one may result in more than one
  71. * operation. This needs to be clarified in this documentation.
  72. *
  73. * @method getTransformedBy
  74. * @param {document.operation.Operation} operation Operation by which this operation will be transformed.
  75. * @returns {document.operation.Operation[]} A result of transformation of this operation by the given operation.
  76. */
  77. }
  78. }
  79. return Operation;
  80. } );