pasting.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals console, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import { stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  9. ClassicEditor
  10. .create( document.querySelector( '#editor' ), {
  11. plugins: [ ArticlePluginSet ],
  12. toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'undo', 'redo' ]
  13. } )
  14. .then( editor => {
  15. window.editor = editor;
  16. const clipboard = editor.plugins.get( 'Clipboard' );
  17. editor.editing.view.document.on( 'paste', ( evt, data ) => {
  18. console.clear();
  19. console.log( '----- paste -----' );
  20. console.log( data );
  21. console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
  22. console.log( 'text/plain\n', data.dataTransfer.getData( 'text/plain' ) );
  23. } );
  24. clipboard.on( 'inputTransformation', ( evt, data ) => {
  25. console.log( '----- clipboardInput -----' );
  26. console.log( 'stringify( data.dataTransfer )\n', stringifyView( data.content ) );
  27. } );
  28. } )
  29. .catch( err => {
  30. console.error( err.stack );
  31. } );