8
0

modeltesteditor.js 1.4 KB

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