-
-
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.
Add support for balloon toolbar in multi root editor
- Loading branch information
Showing
6 changed files
with
317 additions
and
13 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
29 changes: 29 additions & 0 deletions
29
packages/ckeditor5-ui/tests/manual/balloontoolbar/balloontoolbar-multi-root.html
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,29 @@ | ||
<div id="toolbar"> | ||
<button id="add-root">Add root</button> | ||
<button id="remove-root">Remove root</button> | ||
</div> | ||
|
||
<br /> | ||
|
||
<div id="editables"> | ||
<div id="header">Header root</div> | ||
<div id="content">Content root</div> | ||
</div> | ||
|
||
<style> | ||
#toolbar { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 8px; | ||
} | ||
|
||
#editables { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
|
||
& .ck-editor__editable { | ||
border: 1px solid black; | ||
} | ||
} | ||
</style> |
66 changes: 66 additions & 0 deletions
66
packages/ckeditor5-ui/tests/manual/balloontoolbar/balloontoolbar-multi-root.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,66 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/* globals window, console:false, document */ | ||
|
||
import { MultiRootEditor } from '@ckeditor/ckeditor5-editor-multi-root'; | ||
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset.js'; | ||
import BalloonToolbar from '../../../src/toolbar/balloon/balloontoolbar.js'; | ||
|
||
// Plugin that watches for addRoot and detachRoot events and creates or removes editable elements. | ||
class MultiRootWatchEditables { | ||
constructor( editor ) { | ||
this.editor = editor; | ||
} | ||
|
||
init() { | ||
const { editor } = this; | ||
|
||
editor.on( 'addRoot', ( evt, root ) => { | ||
const domElement = this.editor.createEditable( root ); | ||
|
||
document.getElementById( 'editables' ).appendChild( domElement ); | ||
} ); | ||
|
||
editor.on( 'detachRoot', ( evt, root ) => { | ||
this.editor.detachEditable( root ).remove(); | ||
} ); | ||
} | ||
} | ||
|
||
// Build the editor | ||
MultiRootEditor.create( | ||
{ | ||
header: document.getElementById( 'header' ), | ||
content: document.getElementById( 'content' ) | ||
}, | ||
{ | ||
image: { toolbar: [ 'toggleImageCaption', 'imageTextAlternative' ] }, | ||
plugins: [ ArticlePluginSet, BalloonToolbar, MultiRootWatchEditables ], | ||
toolbar: [ 'bold', 'italic', 'link', 'undo', 'redo' ], | ||
balloonToolbar: [ 'bold', 'italic', 'link' ] | ||
} | ||
) | ||
.then( editor => { | ||
window.editor = editor; | ||
} ) | ||
.catch( err => { | ||
console.error( err.stack ); | ||
} ); | ||
|
||
// Handle adding and removing roots. | ||
document.getElementById( 'add-root' ).addEventListener( 'click', () => { | ||
const id = Date.now(); | ||
|
||
window.editor.addRoot( `root-${ id }`, { | ||
data: `<p>Added root - ${ new Date().toISOString() }</p>` | ||
} ); | ||
} ); | ||
|
||
document.getElementById( 'remove-root' ).addEventListener( 'click', () => { | ||
const rootNames = window.editor.model.document.getRootNames(); | ||
|
||
window.editor.detachRoot( rootNames[ rootNames.length - 1 ] ); | ||
} ); |
4 changes: 4 additions & 0 deletions
4
packages/ckeditor5-ui/tests/manual/balloontoolbar/balloontoolbar-multi-root.md
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,4 @@ | ||
## Contextual toolbar multi root demo | ||
|
||
1. Context toolbar should be usable on all roots. | ||
2. Adding / removal of root should be handled. |
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