8
0

operationfactory.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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. import WrapOperation from '../operation/wrapoperation';
  19. import UnwrapOperation from '../operation/unwrapoperation';
  20. const operations = {};
  21. operations[ AttributeOperation.className ] = AttributeOperation;
  22. operations[ InsertOperation.className ] = InsertOperation;
  23. operations[ MarkerOperation.className ] = MarkerOperation;
  24. operations[ MoveOperation.className ] = MoveOperation;
  25. operations[ NoOperation.className ] = NoOperation;
  26. operations[ Operation.className ] = Operation;
  27. operations[ RenameOperation.className ] = RenameOperation;
  28. operations[ RootAttributeOperation.className ] = RootAttributeOperation;
  29. operations[ SplitOperation.className ] = SplitOperation;
  30. operations[ MergeOperation.className ] = MergeOperation;
  31. operations[ WrapOperation.className ] = WrapOperation;
  32. operations[ UnwrapOperation.className ] = UnwrapOperation;
  33. /**
  34. * A factory class for creating operations.
  35. *
  36. * @abstract
  37. */
  38. export default class OperationFactory {
  39. /**
  40. * Creates concrete `Operation` object from deserialized object, i.e. from parsed JSON string.
  41. *
  42. * @param {Object} json Deserialized JSON object.
  43. * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
  44. * @returns {module:engine/model/operation/operation~Operation}
  45. */
  46. static fromJSON( json, document ) {
  47. return operations[ json.__className ].fromJSON( json, document );
  48. }
  49. }