dropping.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @license Copyright (c) 2003-2018, 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 ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import Text from '@ckeditor/ckeditor5-engine/src/model/text';
  9. import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
  10. // import { stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  11. ClassicEditor
  12. .create( document.querySelector( '#editor' ), {
  13. plugins: [ ArticlePluginSet ],
  14. toolbar: [ 'headings', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'undo', 'redo' ]
  15. } )
  16. .then( editor => {
  17. window.editor = editor;
  18. // const clipboard = editor.plugins.get( 'Clipboard' );
  19. editor.editing.view.on( 'drop', ( evt, data ) => {
  20. console.clear();
  21. console.log( '----- drop -----' );
  22. console.log( data );
  23. console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
  24. console.log( 'text/plain\n', data.dataTransfer.getData( 'text/plain' ) );
  25. data.preventDefault();
  26. evt.stop();
  27. editor.model.change( () => {
  28. const insertAtSelection = new Selection( [ editor.editing.mapper.toModelRange( data.dropRange ) ] );
  29. editor.model.insertContent( new Text( '@' ), insertAtSelection );
  30. editor.model.document.selection.setTo( insertAtSelection );
  31. } );
  32. } );
  33. // Waiting until a real dropping support...
  34. // clipboard.on( 'inputTransformation', ( evt, data ) => {
  35. // console.log( '----- clipboardInput -----' );
  36. // console.log( 'stringify( data.dataTransfer )\n', stringifyView( data.content ) );
  37. // } );
  38. } )
  39. .catch( err => {
  40. console.error( err.stack );
  41. } );