From 56befedff0fa6402d1fa034267e0468e1c918926 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 3 Sep 2020 17:38:12 +0200 Subject: [PATCH 1/4] Implemented the env#areInputEventsLevel1Supported property. --- packages/ckeditor5-utils/src/env.js | 25 ++++++++++++++++- packages/ckeditor5-utils/tests/env.js | 39 ++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-utils/src/env.js b/packages/ckeditor5-utils/src/env.js index 8fa34e2c639..078df5194ac 100644 --- a/packages/ckeditor5-utils/src/env.js +++ b/packages/ckeditor5-utils/src/env.js @@ -5,6 +5,8 @@ /* globals navigator:false */ +import global from './dom/global'; + /** * @module utils/env */ @@ -71,7 +73,15 @@ const env = { * * @type {Boolean} */ - isRegExpUnicodePropertySupported: isRegExpUnicodePropertySupported() + isRegExpUnicodePropertySupported: isRegExpUnicodePropertySupported(), + + /** + * Indicates that the environment supports at least [Input Events Level 1](https://www.w3.org/TR/input-events-1/) + * (that includes `input` and `beforeinput` events). + * + * @type {Boolean} + */ + areInputEventsLevel1Supported: areInputEventsLevel1Supported( global.window ) } }; @@ -151,3 +161,16 @@ export function isRegExpUnicodePropertySupported() { return isSupported; } + +/** + * Checks if the current environment supports at least [Input Events Level 1](https://www.w3.org/TR/input-events-1/) + * (that includes `input` and `beforeinput` events). + * + * @param {Window} domWindow The DOM Window interface. + * @returns {Boolean} + */ +export function areInputEventsLevel1Supported( domWindow ) { + const inputEvent = new domWindow.InputEvent( 'input' ); + + return ( 'inputType' in inputEvent ) && ( 'getTargetRanges' in inputEvent ); +} diff --git a/packages/ckeditor5-utils/tests/env.js b/packages/ckeditor5-utils/tests/env.js index cc66fa23fef..326a24c632f 100644 --- a/packages/ckeditor5-utils/tests/env.js +++ b/packages/ckeditor5-utils/tests/env.js @@ -3,7 +3,15 @@ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ -import env, { isMac, isGecko, isSafari, isAndroid, isRegExpUnicodePropertySupported, isBlink } from '../src/env'; +import env, { + isMac, + isGecko, + isSafari, + isAndroid, + isBlink, + isRegExpUnicodePropertySupported, + areInputEventsLevel1Supported +} from '../src/env'; function toLowerCase( str ) { return str.toLowerCase(); @@ -54,6 +62,12 @@ describe( 'Env', () => { expect( env.features.isRegExpUnicodePropertySupported ).to.be.a( 'boolean' ); } ); } ); + + describe( 'areInputEventsLevel1Supported', () => { + it( 'is a boolean', () => { + expect( env.features.areInputEventsLevel1Supported ).to.be.a( 'boolean' ); + } ); + } ); } ); describe( 'isMac()', () => { @@ -201,4 +215,27 @@ describe( 'Env', () => { } } ); } ); + + describe( 'areInputEventsLevel1Supported()', () => { + it( 'should detect the Input Events Level 1 support', () => { + class InputEventStubWhenSupported { + constructor() { + this.inputType = ''; + this.getTargetRanges = () => {}; + } + } + + const DOMWindowStubWhenSupported = { + InputEvent: InputEventStubWhenSupported + }; + + const DOMWindowStubWhenUnsupported = { + // eslint-disable-next-line + InputEvent: function () {} + }; + + expect( areInputEventsLevel1Supported( DOMWindowStubWhenSupported ) ).to.be.true; + expect( areInputEventsLevel1Supported( DOMWindowStubWhenUnsupported ) ).to.be.false; + } ); + } ); } ); From 1cccd6c5a753300e514b1b7eba7b35e039a8105f Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 3 Sep 2020 17:39:28 +0200 Subject: [PATCH 2/4] Docs: Minor correction in the env#areInputEventsLevel1Supported. --- packages/ckeditor5-utils/src/env.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-utils/src/env.js b/packages/ckeditor5-utils/src/env.js index 078df5194ac..c1032ea72c1 100644 --- a/packages/ckeditor5-utils/src/env.js +++ b/packages/ckeditor5-utils/src/env.js @@ -77,7 +77,7 @@ const env = { /** * Indicates that the environment supports at least [Input Events Level 1](https://www.w3.org/TR/input-events-1/) - * (that includes `input` and `beforeinput` events). + * (`input` and `beforeinput` events). * * @type {Boolean} */ @@ -164,7 +164,7 @@ export function isRegExpUnicodePropertySupported() { /** * Checks if the current environment supports at least [Input Events Level 1](https://www.w3.org/TR/input-events-1/) - * (that includes `input` and `beforeinput` events). + * (`input` and `beforeinput` events). * * @param {Window} domWindow The DOM Window interface. * @returns {Boolean} From 2d60753fe3020fd96a8bbfe8f396ff79fc3be410 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Tue, 8 Sep 2020 14:58:54 +0200 Subject: [PATCH 3/4] Update packages/ckeditor5-utils/src/env.js Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com> --- packages/ckeditor5-utils/src/env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ckeditor5-utils/src/env.js b/packages/ckeditor5-utils/src/env.js index c1032ea72c1..954544017c7 100644 --- a/packages/ckeditor5-utils/src/env.js +++ b/packages/ckeditor5-utils/src/env.js @@ -172,5 +172,5 @@ export function isRegExpUnicodePropertySupported() { export function areInputEventsLevel1Supported( domWindow ) { const inputEvent = new domWindow.InputEvent( 'input' ); - return ( 'inputType' in inputEvent ) && ( 'getTargetRanges' in inputEvent ); + return 'inputType' in inputEvent && 'getTargetRanges' in inputEvent; } From d744cd2b1587f66780d72dd4b64bf71eeda2de08 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Tue, 8 Sep 2020 15:01:16 +0200 Subject: [PATCH 4/4] Renamed env.areInputEventsLevel1Supported -> env.isInputEventsLevel1Supported. --- packages/ckeditor5-utils/src/env.js | 6 +++--- packages/ckeditor5-utils/tests/env.js | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ckeditor5-utils/src/env.js b/packages/ckeditor5-utils/src/env.js index 954544017c7..f744436c6d1 100644 --- a/packages/ckeditor5-utils/src/env.js +++ b/packages/ckeditor5-utils/src/env.js @@ -81,7 +81,7 @@ const env = { * * @type {Boolean} */ - areInputEventsLevel1Supported: areInputEventsLevel1Supported( global.window ) + isInputEventsLevel1Supported: isInputEventsLevel1Supported( global.window ) } }; @@ -169,8 +169,8 @@ export function isRegExpUnicodePropertySupported() { * @param {Window} domWindow The DOM Window interface. * @returns {Boolean} */ -export function areInputEventsLevel1Supported( domWindow ) { +export function isInputEventsLevel1Supported( domWindow ) { const inputEvent = new domWindow.InputEvent( 'input' ); - return 'inputType' in inputEvent && 'getTargetRanges' in inputEvent; + return 'inputType' in inputEvent && 'getTargetRanges' in inputEvent; } diff --git a/packages/ckeditor5-utils/tests/env.js b/packages/ckeditor5-utils/tests/env.js index 326a24c632f..35eea3b2316 100644 --- a/packages/ckeditor5-utils/tests/env.js +++ b/packages/ckeditor5-utils/tests/env.js @@ -10,7 +10,7 @@ import env, { isAndroid, isBlink, isRegExpUnicodePropertySupported, - areInputEventsLevel1Supported + isInputEventsLevel1Supported } from '../src/env'; function toLowerCase( str ) { @@ -63,9 +63,9 @@ describe( 'Env', () => { } ); } ); - describe( 'areInputEventsLevel1Supported', () => { + describe( 'isInputEventsLevel1Supported', () => { it( 'is a boolean', () => { - expect( env.features.areInputEventsLevel1Supported ).to.be.a( 'boolean' ); + expect( env.features.isInputEventsLevel1Supported ).to.be.a( 'boolean' ); } ); } ); } ); @@ -216,7 +216,7 @@ describe( 'Env', () => { } ); } ); - describe( 'areInputEventsLevel1Supported()', () => { + describe( 'isInputEventsLevel1Supported()', () => { it( 'should detect the Input Events Level 1 support', () => { class InputEventStubWhenSupported { constructor() { @@ -234,8 +234,8 @@ describe( 'Env', () => { InputEvent: function () {} }; - expect( areInputEventsLevel1Supported( DOMWindowStubWhenSupported ) ).to.be.true; - expect( areInputEventsLevel1Supported( DOMWindowStubWhenUnsupported ) ).to.be.false; + expect( isInputEventsLevel1Supported( DOMWindowStubWhenSupported ) ).to.be.true; + expect( isInputEventsLevel1Supported( DOMWindowStubWhenUnsupported ) ).to.be.false; } ); } ); } );