1.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console:false, document, window */
  6. import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
  7. import Enter from '/ckeditor5/enter/enter.js';
  8. import Typing from '/ckeditor5/typing/typing.js';
  9. import Paragraph from '/ckeditor5/paragraph/paragraph.js';
  10. import { getData as getModelData } from '/ckeditor5/engine/dev-utils/model.js';
  11. import { getData as getViewData } from '/ckeditor5/engine/dev-utils/view.js';
  12. ClassicEditor.create( document.querySelector( '#editor' ), {
  13. features: [ Enter, Typing, Paragraph ],
  14. toolbar: []
  15. } )
  16. .then( editor => {
  17. window.editor = editor;
  18. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  19. const editable = editor.ui.editableElement;
  20. document.querySelector( '#nbsp' ).addEventListener( 'click', () => {
  21. editor.document.enqueueChanges( () => {
  22. editor.document.selection.collapseToStart();
  23. editor.document.batch().weakInsert( editor.document.selection.getFirstPosition(), '\u00A0' );
  24. } );
  25. } );
  26. editor.document.on( 'changesDone', () => {
  27. console.clear();
  28. const modelData = getModelData( editor.document, { withoutSelection: true } );
  29. console.log( 'model:', modelData.replace( /\u00A0/g, ' ' ) );
  30. const viewData = getViewData( editor.editing.view, { withoutSelection: true } );
  31. console.log( 'view:', viewData.replace( /\u00A0/g, ' ' ) );
  32. console.log( 'dom:', editable.innerHTML );
  33. console.log( 'editor.getData', editor.getData() );
  34. }, { priority: 'lowest' } );
  35. } )
  36. .catch( err => {
  37. console.error( err.stack );
  38. } );