operationfactory.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module engine/model/operation/operationfactory
  7. */
  8. import AttributeOperation from '../operation/attributeoperation';
  9. import InsertOperation from '../operation/insertoperation';
  10. import MarkerOperation from '../operation/markeroperation';
  11. import MoveOperation from '../operation/moveoperation';
  12. import NoOperation from '../operation/nooperation';
  13. import Operation from '../operation/operation';
  14. import RenameOperation from '../operation/renameoperation';
  15. import RootAttributeOperation from '../operation/rootattributeoperation';
  16. import SplitOperation from '../operation/splitoperation';
  17. import MergeOperation from '../operation/mergeoperation';
  18. const operations = {};
  19. operations[ AttributeOperation.className ] = AttributeOperation;
  20. operations[ InsertOperation.className ] = InsertOperation;
  21. operations[ MarkerOperation.className ] = MarkerOperation;
  22. operations[ MoveOperation.className ] = MoveOperation;
  23. operations[ NoOperation.className ] = NoOperation;
  24. operations[ Operation.className ] = Operation;
  25. operations[ RenameOperation.className ] = RenameOperation;
  26. operations[ RootAttributeOperation.className ] = RootAttributeOperation;
  27. operations[ SplitOperation.className ] = SplitOperation;
  28. operations[ MergeOperation.className ] = MergeOperation;
  29. /**
  30. * A factory class for creating operations.
  31. *
  32. * @abstract
  33. */
  34. export default class OperationFactory {
  35. /**
  36. * Creates an operation instance from a JSON object (parsed JSON string).
  37. *
  38. * @param {Object} json Deserialized JSON object.
  39. * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
  40. * @returns {module:engine/model/operation/operation~Operation}
  41. */
  42. static fromJSON( json, document ) {
  43. return operations[ json.__className ].fromJSON( json, document );
  44. }
  45. }