pasting.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 ArticlePreset from '@ckeditor/ckeditor5-presets/src/article';
  8. import { stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  9. ClassicEditor.create( document.querySelector( '#editor' ), {
  10. plugins: [ ArticlePreset ],
  11. toolbar: [ 'headings', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'undo', 'redo' ]
  12. } )
  13. .then( editor => {
  14. window.editor = editor;
  15. const clipboard = editor.plugins.get( 'Clipboard' );
  16. editor.editing.view.on( 'paste', ( evt, data ) => {
  17. console.clear();
  18. console.log( '----- paste -----' );
  19. console.log( data );
  20. console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
  21. console.log( 'text/plain\n', data.dataTransfer.getData( 'text/plain' ) );
  22. } );
  23. clipboard.on( 'inputTransformation', ( evt, data ) => {
  24. console.log( '----- clipboardInput -----' );
  25. console.log( 'stringify( data.dataTransfer )\n', stringifyView( data.content ) );
  26. } );
  27. } )
  28. .catch( err => {
  29. console.error( err.stack );
  30. } );