modeltesteditor.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Editor from '/ckeditor5/editor/editor.js';
  6. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  7. /**
  8. * A simple editor implementation with a functional model part of the engine (the document).
  9. * It contains a full data pipeline but no editing pipeline.
  10. *
  11. * Should work in Node.js. If not now, then in the future :).
  12. *
  13. * @memberOf tests.ckeditor5._utils
  14. */
  15. export default class ModelTestEditor extends Editor {
  16. constructor( config ) {
  17. super( config );
  18. this.document.createRoot();
  19. this.data.processor = new HtmlDataProcessor();
  20. }
  21. /**
  22. * Sets the data in the editor's main root.
  23. *
  24. * @param {*} data The data to load.
  25. */
  26. setData( data ) {
  27. this.data.set( data );
  28. }
  29. /**
  30. * Gets the data from the editor's main root.
  31. */
  32. getData() {
  33. return this.data.get();
  34. }
  35. /**
  36. * Creates a virtual, element-less editor instance.
  37. *
  38. * @param {Object} config See {@link ckeditor5.editor.StandardEditor}'s param.
  39. * @returns {Promise} Promise resolved once editor is ready.
  40. * @returns {ckeditor5.editor.VirtualTestEditor} return.editor The editor instance.
  41. */
  42. static create( config ) {
  43. return new Promise( ( resolve ) => {
  44. const editor = new this( config );
  45. resolve(
  46. editor.initPlugins()
  47. .then( () => editor )
  48. );
  49. } );
  50. }
  51. }