8
0

integration.js 2.0 KB

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