8
0

uielement.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  8. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  9. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  12. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
  13. import Undo from '@ckeditor/ckeditor5-undo/src/undo';
  14. import UIElement from '../../../src/view/uielement';
  15. class MyUIElement extends UIElement {
  16. render( domDocument ) {
  17. const root = super.render( domDocument );
  18. root.classList.add( 'ui-element' );
  19. root.innerHTML = 'END OF PARAGRAPH';
  20. return root;
  21. }
  22. }
  23. class UIElementTestPlugin extends Plugin {
  24. init() {
  25. const editor = this.editor;
  26. const editing = editor.editing;
  27. // Add some UIElement to each paragraph.
  28. editing.modelToView.on( 'insert:paragraph', ( evt, data, consumable, conversionApi ) => {
  29. const viewP = conversionApi.mapper.toViewElement( data.item );
  30. viewP.appendChildren( new MyUIElement( 'span' ) );
  31. }, { priority: 'lowest' } );
  32. }
  33. }
  34. ClassicEditor
  35. .create( document.querySelector( '#editor' ), {
  36. plugins: [ Enter, Typing, Paragraph, Undo, Bold, Italic, UIElementTestPlugin ],
  37. toolbar: [ 'undo', 'redo', 'bold', 'italic' ]
  38. } )
  39. .then( editor => {
  40. window.editor = editor;
  41. } )
  42. .catch( err => {
  43. console.error( err.stack );
  44. } );