richeditor.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
  9. import AutoFormat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
  10. import AutoSave from '@ckeditor/ckeditor5-autosave/src/autosave';
  11. import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  12. import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript';
  13. import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
  14. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  15. import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
  16. import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  17. import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
  18. import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
  19. import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
  20. import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
  21. import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
  22. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  23. import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
  24. import Mention from '@ckeditor/ckeditor5-mention/src/mention';
  25. import PageBreak from '@ckeditor/ckeditor5-page-break/src/pagebreak';
  26. import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice';
  27. import RemoveFormat from '@ckeditor/ckeditor5-remove-format/src/removeformat';
  28. import StandardEditingMode from '@ckeditor/ckeditor5-restricted-editing/src/standardeditingmode';
  29. import SpecialCharacters from '@ckeditor/ckeditor5-special-characters/src/specialcharacters';
  30. import SpecialCharactersEssentials from '@ckeditor/ckeditor5-special-characters/src/specialcharactersessentials';
  31. import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
  32. import TableCellProperties from '@ckeditor/ckeditor5-table/src/tablecellproperties';
  33. import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
  34. import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
  35. import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
  36. import { UploadAdapterMock } from '@ckeditor/ckeditor5-upload/tests/_utils/mocks';
  37. import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount';
  38. import { getPerformanceData, renderPerformanceDataButtons } from '../../_utils/utils';
  39. import smallTablesInlineCssFixture from '../../_data/small-tables-inline-css.html';
  40. renderPerformanceDataButtons( document.querySelector( '#fixture-buttons' ), {
  41. 'smallTablesInlineCss': 'text and tables (styled)'
  42. } );
  43. let editor;
  44. ClassicEditor
  45. .create( document.querySelector( '#editor' ), {
  46. plugins: [
  47. ArticlePluginSet,
  48. Alignment,
  49. AutoFormat,
  50. AutoSave,
  51. Strikethrough,
  52. Subscript,
  53. Superscript,
  54. Underline,
  55. Code,
  56. CodeBlock,
  57. FontBackgroundColor,
  58. FontColor,
  59. FontFamily,
  60. FontSize,
  61. Highlight,
  62. HorizontalLine,
  63. TodoList,
  64. Mention,
  65. PageBreak,
  66. PasteFromOffice,
  67. RemoveFormat,
  68. StandardEditingMode,
  69. SpecialCharacters,
  70. SpecialCharactersEssentials,
  71. TableProperties,
  72. TableCellProperties,
  73. ImageUpload,
  74. ImageResize,
  75. WordCount,
  76. IndentBlock
  77. ],
  78. toolbar: {
  79. items: [
  80. 'heading',
  81. '|',
  82. 'bold',
  83. 'italic',
  84. 'strikethrough',
  85. 'subscript',
  86. 'superscript',
  87. 'underline',
  88. 'code',
  89. 'alignment',
  90. 'link',
  91. 'removeFormat',
  92. '|',
  93. 'fontBackgroundColor',
  94. 'fontColor',
  95. 'fontFamily',
  96. 'fontSize',
  97. 'highlight',
  98. '|',
  99. 'bulletedList',
  100. 'numberedList',
  101. 'todoList',
  102. 'outdent',
  103. 'indent',
  104. '|',
  105. 'blockQuote',
  106. 'insertTable',
  107. 'mediaEmbed',
  108. 'codeBlock',
  109. 'horizontalLine',
  110. 'pageBreak',
  111. 'specialCharacters',
  112. 'restrictedEditingException',
  113. 'undo',
  114. 'redo'
  115. ],
  116. shouldNotGroupWhenFull: true
  117. },
  118. table: {
  119. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableCellProperties' ]
  120. },
  121. image: {
  122. toolbar: [ 'imageStyle:full', 'imageStyle:side', 'imageTextAlternative' ]
  123. }
  124. } )
  125. .then( newEditor => {
  126. // Editor is not exposed as window.editor to disable CKEditor5 Inspector for performance tests.
  127. editor = newEditor;
  128. addWordCountListener( newEditor );
  129. addUploadMockAdapter( newEditor );
  130. } )
  131. .catch( err => {
  132. console.error( err.stack );
  133. } );
  134. function addWordCountListener( editor ) {
  135. const wordCount = editor.plugins.get( WordCount );
  136. const wordCountElement = document.getElementById( 'word-count' );
  137. const characterCountElement = document.getElementById( 'character-count' );
  138. wordCountElement.innerHTML = wordCount.words;
  139. characterCountElement.innerHTML = wordCount.characters;
  140. wordCount.on( 'change:words', ( evt, name, value ) => {
  141. document.getElementById( 'word-count' ).innerHTML = value;
  142. } );
  143. wordCount.on( 'change:characters', ( evt, name, value ) => {
  144. document.getElementById( 'character-count' ).innerHTML = value;
  145. } );
  146. document.getElementById( 'word-count-wrapper' ).style.display = 'block';
  147. }
  148. function addUploadMockAdapter( editor ) {
  149. editor.plugins.get( 'FileRepository' ).createUploadAdapter = loader => {
  150. return new UploadAdapterMock( loader );
  151. };
  152. }
  153. const fixtures = getPerformanceData();
  154. fixtures.smallTablesInlineCss = smallTablesInlineCssFixture;
  155. const buttons = document.querySelectorAll( '#test-controls button' );
  156. for ( const button of buttons ) {
  157. button.addEventListener( 'click', function() {
  158. const content = fixtures[ this.getAttribute( 'data-file-name' ) ];
  159. editor.setData( content );
  160. } );
  161. button.disabled = false;
  162. }