8
0

integration.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  9. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  10. import Table from '@ckeditor/ckeditor5-table/src/table';
  11. import { stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  12. const htmlDiv = document.querySelector( '#html' );
  13. const textDiv = document.querySelector( '#text' );
  14. const dataDiv = document.querySelector( '#data' );
  15. ClassicEditor
  16. .create( document.querySelector( '#editor' ), {
  17. plugins: [ ArticlePluginSet, Strikethrough, Underline, Table ],
  18. toolbar: [ 'heading', '|', 'bold', 'italic', 'strikethrough', 'underline', 'link',
  19. 'bulletedList', 'numberedList', 'blockQuote', 'table', 'undo', 'redo' ]
  20. } )
  21. .then( editor => {
  22. window.editor = editor;
  23. const clipboard = editor.plugins.get( 'Clipboard' );
  24. editor.editing.view.document.on( 'paste', ( evt, data ) => {
  25. console.clear();
  26. console.log( '----- paste -----' );
  27. console.log( data );
  28. console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
  29. console.log( 'text/plain\n', data.dataTransfer.getData( 'text/plain' ) );
  30. htmlDiv.innerText = data.dataTransfer.getData( 'text/html' );
  31. textDiv.innerText = data.dataTransfer.getData( 'text/plain' );
  32. } );
  33. clipboard.on( 'inputTransformation', ( evt, data ) => {
  34. console.log( '----- clipboardInput -----' );
  35. console.log( 'stringify( data.dataTransfer )\n', stringifyView( data.content ) );
  36. dataDiv.innerText = stringifyView( data.content );
  37. } );
  38. } )
  39. .catch( err => {
  40. console.error( err.stack );
  41. } );