8
0

buildclassiceditor.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. /**
  7. * Bundle configuration with hard coded set of features.
  8. *
  9. * At this moment we don't know a list of every dependency needed in the bundle. It is because
  10. * editor features load automatically during initialization process. To work around this problem
  11. * we have created a custom entry file where we defined some of imports with features
  12. * needed to initialize editor.
  13. */
  14. /**
  15. * Babel helper.
  16. *
  17. * @TODO: Move to bundle task.
  18. * Should be injected by bundle task, because our source code don't have to know that will be transformed.
  19. * But it is not so easy. It is only possible to pass string with file path to rollup,
  20. * so to do it we need to create a temporary file.
  21. */
  22. import '../../../node_modules/regenerator-runtime/runtime.js';
  23. import ClassicEditor from '../../../build/esnext/ckeditor5/creator-classic/classic.js';
  24. import Delete from '../../../build/esnext/ckeditor5/delete/delete.js';
  25. import Enter from '../../../build/esnext/ckeditor5/enter/enter.js';
  26. import Typing from '../../../build/esnext/ckeditor5/typing/typing.js';
  27. import Paragraph from '../../../build/esnext/ckeditor5/paragraph/paragraph.js';
  28. import Undo from '../../../build/esnext/ckeditor5/undo/undo.js';
  29. import BasicStylesBold from '../../../build/esnext/ckeditor5/basic-styles/bold.js';
  30. import BasicStylesItalic from '../../../build/esnext/ckeditor5/basic-styles/italic.js';
  31. /**
  32. * Class for creating editor with defined set of features.
  33. *
  34. * @extends ckeditor5.creator-classic.classic
  35. * @param {HTMLElement} element See {@link ckeditor5.creator-classic.classic#create}'s param.
  36. * @param {Object} config See {@link ckeditor5.creator-classic.classic#create}'s param.
  37. * @returns {Promise} Promise resolved once editor is ready.
  38. * @returns {ckeditor5.editor.StandardEditor} return.editor The editor instance.
  39. */
  40. export default class BuildClassicEditor extends ClassicEditor {
  41. static create( element, config = {} ) {
  42. if ( !config.features ) {
  43. config.features = [];
  44. }
  45. if ( !config.toolbar ) {
  46. config.toolbar = [];
  47. }
  48. config.features = [ ...config.features, Delete, Enter, Typing, Paragraph, Undo, BasicStylesBold, BasicStylesItalic ];
  49. config.toolbar = [ ...config.toolbar, 'bold', 'italic', 'undo', 'redo' ];
  50. return ClassicEditor.create( element, config );
  51. }
  52. }