8
0

tabletoolbar.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module table/tabletoolbar
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import { getSelectedTableWidget, getTableWidgetAncestor } from './utils';
  10. import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolbarrepository';
  11. /**
  12. * The table toolbar class. It creates toolbars for the table feature and its content (for now only for a table cell content).
  13. *
  14. * Table toolbar shows up when a table widget is selected. Its components (e.g. buttons) are created based on the
  15. * {@link module:table/table~TableConfig#tableToolbar `table.tableToolbar` configuration option}.
  16. *
  17. * Table content toolbar shows up when the selection is inside the content of a table. It creates its component based on the
  18. * {@link module:table/table~TableConfig#contentToolbar `table.contentToolbar` configuration option}.
  19. *
  20. * @extends module:core/plugin~Plugin
  21. */
  22. export default class TableToolbar extends Plugin {
  23. /**
  24. * @inheritDoc
  25. */
  26. static get requires() {
  27. return [ WidgetToolbarRepository ];
  28. }
  29. /**
  30. * @inheritDoc
  31. */
  32. static get pluginName() {
  33. return 'TableToolbar';
  34. }
  35. /**
  36. * @inheritDoc
  37. */
  38. afterInit() {
  39. const editor = this.editor;
  40. const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
  41. const tableContentToolbarItems = editor.config.get( 'table.contentToolbar' );
  42. const tableToolbarItems = editor.config.get( 'table.tableToolbar' );
  43. if ( tableContentToolbarItems ) {
  44. widgetToolbarRepository.register( 'tableContent', {
  45. items: tableContentToolbarItems,
  46. getRelatedElement: getTableWidgetAncestor
  47. } );
  48. }
  49. if ( tableToolbarItems ) {
  50. widgetToolbarRepository.register( 'table', {
  51. items: tableToolbarItems,
  52. getRelatedElement: getSelectedTableWidget
  53. } );
  54. }
  55. }
  56. }
  57. /**
  58. * Items to be placed in the table content toolbar.
  59. * The {@link module:table/tabletoolbar~TableToolbar} plugin is required to make this toolbar working.
  60. *
  61. * Assuming that you use the {@link module:table/tableui~TableUI} feature, the following toolbar items will be available
  62. * in {@link module:ui/componentfactory~ComponentFactory}:
  63. *
  64. * * `'tableRow'`,
  65. * * `'tableColumn'`,
  66. * * `'mergeTableCells'`.
  67. *
  68. * You can thus configure the toolbar like this:
  69. *
  70. * const tableConfig = {
  71. * contentToolbar: [ 'tableRow', 'tableColumn', 'mergeTableCells' ]
  72. * };
  73. *
  74. * Of course, the same buttons can also be used in the
  75. * {@link module:core/editor/editorconfig~EditorConfig#toolbar main editor toolbar}.
  76. *
  77. * Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
  78. *
  79. * @member {Array.<String>} module:table/table~TableConfig#contentToolbar
  80. */
  81. /**
  82. * Items to be placed in the table toolbar.
  83. * The {@link module:table/tabletoolbar~TableToolbar} plugin is required to make this toolbar working.
  84. *
  85. * You can thus configure the toolbar like this:
  86. *
  87. * const tableConfig = {
  88. * tableToolbar: [ 'blockQuote' ]
  89. * };
  90. *
  91. * Of course, the same buttons can also be used in the
  92. * {@link module:core/editor/editorconfig~EditorConfig#toolbar main editor toolbar}.
  93. *
  94. * Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
  95. *
  96. * @member {Array.<String>} module:table/table~TableConfig#tableToolbar
  97. */