-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9263 from ckeditor/i/9104-caption-toolbar
Feature (table): Added toolbar buttons for table captions. Closes #9104. Closes #9086. Closes #9304. Closes #9087. Closes #9088. Closes #9085.
- Loading branch information
Showing
24 changed files
with
1,142 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/ckeditor5-table/src/tablecaption/tablecaptionui.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module table/tablecaption/tablecaptionui | ||
*/ | ||
|
||
import { Plugin, icons } from 'ckeditor5/src/core'; | ||
import { ButtonView } from 'ckeditor5/src/ui'; | ||
|
||
import { getCaptionFromModelSelection } from './utils'; | ||
|
||
/** | ||
* The table caption UI plugin. It introduces the `'toggleTableCaption'` UI button. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class TableCaptionUI extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
static get pluginName() { | ||
return 'TableCaptionUI'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
init() { | ||
const editor = this.editor; | ||
const editingView = editor.editing.view; | ||
const t = editor.t; | ||
|
||
editor.ui.componentFactory.add( 'toggleTableCaption', locale => { | ||
const command = editor.commands.get( 'toggleTableCaption' ); | ||
const view = new ButtonView( locale ); | ||
|
||
view.set( { | ||
icon: icons.caption, | ||
tooltip: true, | ||
isToggleable: true | ||
} ); | ||
|
||
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); | ||
view.bind( 'label' ).to( command, 'value', value => value ? t( 'Toggle caption off' ) : t( 'Toggle caption on' ) ); | ||
|
||
this.listenTo( view, 'execute', () => { | ||
editor.execute( 'toggleTableCaption', { focusCaptionOnShow: true } ); | ||
|
||
// Scroll to the selection and highlight the caption if the caption showed up. | ||
if ( command.value ) { | ||
const modelCaptionElement = getCaptionFromModelSelection( editor.model.document.selection ); | ||
const figcaptionElement = editor.editing.mapper.toViewElement( modelCaptionElement ); | ||
|
||
if ( !figcaptionElement ) { | ||
return; | ||
} | ||
|
||
editingView.scrollToTheSelection(); | ||
editingView.change( writer => { | ||
writer.addClass( 'table__caption_highlighted', figcaptionElement ); | ||
} ); | ||
} | ||
} ); | ||
|
||
return view; | ||
} ); | ||
} | ||
} |
Oops, something went wrong.