UNPKG

2.19 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5/**
6 * @module table/tabletoolbar
7 */
8import { Plugin } from 'ckeditor5/src/core';
9import { WidgetToolbarRepository } from 'ckeditor5/src/widget';
10import { getSelectedTableWidget, getTableWidgetAncestor } from './utils/ui/widget';
11/**
12 * The table toolbar class. It creates toolbars for the table feature and its content (for now only for the table cell content).
13 *
14 * The table toolbar shows up when a table widget is selected. Its components (e.g. buttons) are created based on the
15 * {@link module:table/tableconfig~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/tableconfig~TableConfig#contentToolbar `table.contentToolbar` configuration option}.
19 */
20export default class TableToolbar extends Plugin {
21 /**
22 * @inheritDoc
23 */
24 static get requires() {
25 return [WidgetToolbarRepository];
26 }
27 /**
28 * @inheritDoc
29 */
30 static get pluginName() {
31 return 'TableToolbar';
32 }
33 /**
34 * @inheritDoc
35 */
36 afterInit() {
37 const editor = this.editor;
38 const t = editor.t;
39 const widgetToolbarRepository = editor.plugins.get(WidgetToolbarRepository);
40 const tableContentToolbarItems = editor.config.get('table.contentToolbar');
41 const tableToolbarItems = editor.config.get('table.tableToolbar');
42 if (tableContentToolbarItems) {
43 widgetToolbarRepository.register('tableContent', {
44 ariaLabel: t('Table toolbar'),
45 items: tableContentToolbarItems,
46 getRelatedElement: getTableWidgetAncestor
47 });
48 }
49 if (tableToolbarItems) {
50 widgetToolbarRepository.register('table', {
51 ariaLabel: t('Table toolbar'),
52 items: tableToolbarItems,
53 getRelatedElement: getSelectedTableWidget
54 });
55 }
56 }
57}