decouplededitorui.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module editor-decoupled/decouplededitorui
  7. */
  8. import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
  9. import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus';
  10. import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalizetoolbarconfig';
  11. /**
  12. * The decoupled editor UI class.
  13. *
  14. * @extends module:core/editor/editorui~EditorUI
  15. */
  16. export default class DecoupledEditorUI extends EditorUI {
  17. /**
  18. * Creates an instance of the decoupled editor UI class.
  19. *
  20. * @param {module:core/editor/editor~Editor} editor The editor instance.
  21. * @param {module:ui/editorui/editoruiview~EditorUIView} view The view of the UI.
  22. */
  23. constructor( editor, view ) {
  24. super( editor );
  25. /**
  26. * The main (top–most) view of the editor UI.
  27. *
  28. * @private
  29. * @member {module:ui/editorui/editoruiview~EditorUIView} #_view
  30. */
  31. this._view = view;
  32. /**
  33. * A normalized `config.toolbar` object.
  34. *
  35. * @type {Object}
  36. * @private
  37. */
  38. this._toolbarConfig = normalizeToolbarConfig( editor.config.get( 'toolbar' ) );
  39. }
  40. /**
  41. * The main (top–most) view of the editor UI.
  42. *
  43. * @readonly
  44. * @member {module:ui/editorui/editoruiview~EditorUIView} #view
  45. */
  46. get view() {
  47. return this._view;
  48. }
  49. /**
  50. * Initializes the UI.
  51. */
  52. init() {
  53. const editor = this.editor;
  54. const view = this.view;
  55. view.render();
  56. // Set up the editable.
  57. const editingRoot = editor.editing.view.document.getRoot();
  58. view.editable.bind( 'isReadOnly' ).to( editingRoot );
  59. view.editable.bind( 'isFocused' ).to( editor.editing.view.document );
  60. editor.editing.view.attachDomRoot( view.editable.element );
  61. view.editable.name = editingRoot.rootName;
  62. this._editableElements.set( view.editable.name, view.editable.element );
  63. this.focusTracker.add( view.editable.element );
  64. this.view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
  65. enableToolbarKeyboardFocus( {
  66. origin: editor.editing.view,
  67. originFocusTracker: this.focusTracker,
  68. originKeystrokeHandler: editor.keystrokes,
  69. toolbar: this.view.toolbar
  70. } );
  71. this.fire( 'ready' );
  72. }
  73. /**
  74. * @inheritDoc
  75. */
  76. destroy() {
  77. this._view.destroy();
  78. super.destroy();
  79. }
  80. }