integration.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 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 TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar';
  12. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  13. import PasteFromOffice from '../../src/pastefromoffice';
  14. import { stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  15. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  16. import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
  17. const htmlDiv = document.querySelector( '#html' );
  18. const textDiv = document.querySelector( '#text' );
  19. const dataDiv = document.querySelector( '#data' );
  20. ClassicEditor
  21. .create( document.querySelector( '#editor' ), {
  22. plugins: [ ArticlePluginSet, Strikethrough, Underline, Table, TableToolbar,
  23. TableProperties, TableProperties, EasyImage, PasteFromOffice ],
  24. toolbar: [ 'heading', '|', 'bold', 'italic', 'strikethrough', 'underline', 'link',
  25. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo' ],
  26. table: {
  27. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ]
  28. },
  29. cloudServices: CS_CONFIG
  30. } )
  31. .then( editor => {
  32. window.editor = editor;
  33. const clipboard = editor.plugins.get( 'Clipboard' );
  34. editor.editing.view.document.on( 'paste', ( evt, data ) => {
  35. console.clear();
  36. console.log( '----- paste -----' );
  37. console.log( data );
  38. console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
  39. console.log( 'text/plain\n', data.dataTransfer.getData( 'text/plain' ) );
  40. htmlDiv.innerText = data.dataTransfer.getData( 'text/html' );
  41. textDiv.innerText = data.dataTransfer.getData( 'text/plain' );
  42. } );
  43. clipboard.on( 'inputTransformation', ( evt, data ) => {
  44. console.log( '----- clipboardInput -----' );
  45. console.log( 'stringify( data.dataTransfer )\n', stringifyView( data.content ) );
  46. dataDiv.innerText = stringifyView( data.content );
  47. } );
  48. } )
  49. .catch( err => {
  50. console.error( err.stack );
  51. } );