8
0

integration.js 2.8 KB

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