-
-
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.
Feature (engine): Elements with
data-cke-ignore-events
attribute wi…
…ll not propagate it's events to CKEditor API. Closes #4600.
- Loading branch information
Showing
13 changed files
with
481 additions
and
5 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
41 changes: 41 additions & 0 deletions
41
packages/ckeditor5-engine/tests/manual/tickets/4600/1.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,41 @@ | ||
<style> | ||
.simple-widget-container { | ||
margin: 1em 0; | ||
font-family: sans-serif; | ||
} | ||
|
||
.simple-widget-element { | ||
display: flex; | ||
height: 14em; | ||
} | ||
|
||
.simple-widget-element>fieldset { | ||
display: flex; | ||
align-items: center; | ||
margin: 3em; | ||
width: 50%; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
} | ||
|
||
.simple-widget-element>fieldset>legend { | ||
font-size: 0.85em; | ||
padding: .2em 2em; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
background: #fff; | ||
} | ||
|
||
.simple-widget-element>fieldset>input { | ||
flex: 1; | ||
margin: 1em 1em 1em 0; | ||
} | ||
|
||
.simple-widget-element>fieldset>button { | ||
padding: .2em 3em; | ||
} | ||
</style> | ||
|
||
<div id="editor"> | ||
<section class="simple-widget-container" /> | ||
</div> |
155 changes: 155 additions & 0 deletions
155
packages/ckeditor5-engine/tests/manual/tickets/4600/1.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,155 @@ | ||
/** | ||
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/* globals console, document, window, Event */ | ||
|
||
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; | ||
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials'; | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import Widget from '@ckeditor/ckeditor5-widget/src/widget'; | ||
import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils'; | ||
|
||
import ClickObserver from '../../../../src/view/observer/clickobserver'; | ||
import CompositionObserver from '../../../../src/view/observer/compositionobserver'; | ||
import FocusObserver from '../../../../src/view/observer/focusobserver'; | ||
import InputObserver from '../../../../src/view/observer/inputobserver'; | ||
import KeyObserver from '../../../../src/view/observer/keyobserver'; | ||
import MouseObserver from '../../../../src/view/observer/mouseobserver'; | ||
import MouseEventsObserver from '@ckeditor/ckeditor5-table/src/tablemouse/mouseeventsobserver'; | ||
|
||
class SimpleWidgetEditing extends Plugin { | ||
static get requires() { | ||
return [ Widget ]; | ||
} | ||
|
||
init() { | ||
this._defineSchema(); | ||
this._defineConverters(); | ||
this._addObservers(); | ||
} | ||
|
||
_defineSchema() { | ||
const schema = this.editor.model.schema; | ||
|
||
schema.register( 'simpleWidgetElement', { | ||
inheritAllFrom: '$block', | ||
isObject: true | ||
} ); | ||
} | ||
|
||
_defineConverters() { | ||
const conversion = this.editor.conversion; | ||
|
||
conversion.for( 'editingDowncast' ).elementToElement( { | ||
model: 'simpleWidgetElement', | ||
view: ( modelElement, { writer } ) => { | ||
const widgetElement = createWidgetView( modelElement, { writer } ); | ||
|
||
return toWidget( widgetElement, writer ); | ||
} | ||
} ); | ||
|
||
conversion.for( 'dataDowncast' ).elementToElement( { | ||
model: 'simpleWidgetElement', | ||
view: createWidgetView | ||
} ); | ||
|
||
conversion.for( 'upcast' ).elementToElement( { | ||
model: 'simpleWidgetElement', | ||
view: { | ||
name: 'section', | ||
classes: 'simple-widget-container' | ||
} | ||
} ); | ||
|
||
function createWidgetView( modelElement, { writer } ) { | ||
const simpleWidgetContainer = writer.createContainerElement( 'section', { class: 'simple-widget-container' } ); | ||
const simpleWidgetElement = writer.createRawElement( 'div', { class: 'simple-widget-element' }, domElement => { | ||
domElement.innerHTML = ` | ||
<fieldset data-cke-ignore-events="true"> | ||
<legend>Ignored container with <strong>data-cke-ignore-events="true"</strong></legend> | ||
<input> | ||
<button>Click!</button> | ||
</fieldset> | ||
<fieldset> | ||
<legend>Regular container</legend> | ||
<input> | ||
<button>Click!</button> | ||
</fieldset> | ||
`; | ||
} ); | ||
|
||
writer.insert( writer.createPositionAt( simpleWidgetContainer, 0 ), simpleWidgetElement ); | ||
|
||
return simpleWidgetContainer; | ||
} | ||
} | ||
|
||
_addObservers() { | ||
const view = this.editor.editing.view; | ||
|
||
const observers = new Map( [ | ||
[ ClickObserver, [ 'click' ] ], | ||
[ CompositionObserver, [ 'compositionstart', 'compositionupdate', 'compositionend' ] ], | ||
[ FocusObserver, [ 'focus', 'blur' ] ], | ||
[ InputObserver, [ 'beforeinput' ] ], | ||
[ KeyObserver, [ 'keydown', 'keyup' ] ], | ||
[ MouseEventsObserver, [ 'mousemove', 'mouseup', 'mouseleave' ] ], | ||
[ MouseObserver, [ 'mousedown' ] ] | ||
] ); | ||
|
||
observers.forEach( ( events, observer ) => { | ||
view.addObserver( observer ); | ||
|
||
events.forEach( eventName => { | ||
this.listenTo( view.document, eventName, () => { | ||
console.log( `Received ${ eventName } event.` ); | ||
} ); | ||
} ); | ||
} ); | ||
} | ||
} | ||
|
||
class SimpleWidgetUI extends Plugin {} | ||
|
||
class SimpleWidget extends Plugin { | ||
static get requires() { | ||
return [ SimpleWidgetEditing, SimpleWidgetUI ]; | ||
} | ||
} | ||
|
||
ClassicEditor | ||
.create( document.querySelector( '#editor' ), { | ||
plugins: [ Essentials, SimpleWidget ] | ||
} ) | ||
.then( editor => { | ||
window.editor = editor; | ||
addEventDispatcherForButtons( editor, 'click' ); | ||
} ) | ||
.catch( error => { | ||
console.error( error.stack ); | ||
} ); | ||
|
||
function addEventDispatcherForButtons( editor, eventName ) { | ||
const view = editor.editing.view; | ||
const container = Array | ||
.from( view.document.getRoot().getChildren() ) | ||
.find( element => element.hasClass( 'simple-widget-container' ) ); | ||
|
||
view.domConverter | ||
.viewToDom( container ) | ||
.querySelectorAll( 'button' ) | ||
.forEach( button => { | ||
button.addEventListener( 'click', event => { | ||
if ( !event.isTrusted ) { | ||
return; | ||
} | ||
|
||
console.log( `Dispatched ${ eventName } event.` ); | ||
button.dispatchEvent( new Event( eventName, { bubbles: true } ) ); | ||
} ); | ||
} ); | ||
} |
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,19 @@ | ||
### Ignoring events fired by certain elements [#4600](https://github.com/ckeditor/ckeditor5/issues/4600) | ||
|
||
Events are logged in console. | ||
|
||
### Case 1: Events are ignored and they are not handled by default listeners. | ||
1. Move mouse cursor over a left container named `Ignored container with data-cke-ignore-events="true"`. | ||
2. When it is already there, start moving it around within container boundaries, start typing in text field and start clicking on text field and button. | ||
3. Click on the button. | ||
|
||
**Expected results**: Only then, when the mouse cursor is over the left container, new logs will stop appearing in the console. Clicking inside it, typing in text field and moving mouse cursor inside the container boundaries should not be logged in console. Clicking on a button dispatches the `click` event (the `Dispatched click event` message should be logged), but `Received click event` shouldn't be present in console. | ||
|
||
One note for `focus` nad `blur` events: they will be logged in console, but only when container lost focus or gets it back, respectively. | ||
|
||
### Case 2: Events are not ignored and they are handled by default listeners. | ||
1. Move mouse cursor over a right container named `Regular container`. | ||
2. When it is already there, start moving it around within container boundaries, start typing in text field and start clicking on text field and button. | ||
3. Click on the button. | ||
|
||
**Expected results**: Events should be logged in console. It shouldn't be possible to focus the text field and type anything there. Clicking on a button dispatches the `click` event (the `Dispatched click event` message should be logged) and doubled `Received click event` should be present in console: one from "real" user mouse click and second one from script-generated `click` event. |
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
Oops, something went wrong.