-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add table caption toolbar button #9263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0541ef5
Add table caption UI.
maxbarnas 2303a3c
Update placement of the toolbar.
maxbarnas d0a868a
Allow toggling the caption from both the table and content toolbar.
maxbarnas cd4e637
Clean up the code. Add tests.
maxbarnas 4924bdf
Add styles.
maxbarnas aa5aee1
Fix QA review issue: table cell buttons enabled when in caption.
maxbarnas 98d7aa3
Fix QA issues: default focus on caption hiding, placeholder styling.
maxbarnas 9cb8fd0
Update tests.
maxbarnas 032d356
Review fixes.
maxbarnas 2d7fe6d
Merge branch 'i/9105-table-algorithms' into i/9104-caption-toolbar
maxbarnas 1e24af8
Add tests.
maxbarnas 2598cfd
Docs and CSS.
maxbarnas aa8d950
Proper imports in tests. Moved the doc section up.
maxbarnas 5a972db
Rename `getClosestParentTable` to `getSelectionAffectedTable`.
maxbarnas 26ae590
Remove `tableToolbar` config from manual tests.
maxbarnas c97ceac
Misc review fixes.
maxbarnas e1be5bf
Cleanup.
maxbarnas 89f7743
New section in docs for installation of the table caption plugin.
maxbarnas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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' ) ); | ||
niegowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.