Bladeren bron

Remove feature detection from mention plugin. It's now located in utils.

Mateusz Samsel 6 jaren geleden
bovenliggende
commit
ad80b92df4

+ 0 - 36
packages/ckeditor5-mention/src/featuredetection.js

@@ -1,36 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
-
-/**
- * @module mention/featuredetection
- */
-
-/**
- * Holds feature detection resolutions used by the mention plugin.
- *
- * @protected
- * @namespace
- */
-export default {
-	/**
-	 * Indicates whether the current browser supports ES2018 Unicode groups like `\p{P}` or `\p{L}`.
-	 *
-	 * @type {Boolean}
-	 */
-	isUnicodeGroupSupported: ( function() {
-		let isSupported = false;
-
-		// Feature detection for Unicode groups. Added in ES2018. Currently Firefox and Edge do not support it.
-		// See https://github.com/ckeditor/ckeditor5-mention/issues/44#issuecomment-487002174.
-
-		try {
-			isSupported = 'ć'.search( new RegExp( '[\\p{L}]', 'u' ) ) === 0;
-		} catch ( error ) {
-			// Firefox throws a SyntaxError when the group is unsupported.
-		}
-
-		return isSupported;
-	}() )
-};

+ 3 - 3
packages/ckeditor5-mention/src/mentionui.js

@@ -12,7 +12,7 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
-import featureDetection from './featuredetection';
+import regExpFeatureDetection from '@ckeditor/ckeditor5-utils/src/featuredetection/regexp';
 import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
@@ -536,8 +536,8 @@ function getBalloonPanelPositions( preferredPosition ) {
 export function createRegExp( marker, minimumCharacters ) {
 	const numberOfCharacters = minimumCharacters == 0 ? '*' : `{${ minimumCharacters },}`;
 
-	const openAfterCharacters = featureDetection.isUnicodeGroupSupported ? '\\p{Ps}\\p{Pi}"\'' : '\\(\\[{"\'';
-	const mentionCharacters = featureDetection.isUnicodeGroupSupported ? '\\p{L}\\p{N}' : 'a-zA-ZÀ-ž0-9';
+	const openAfterCharacters = regExpFeatureDetection.isUnicodeGroupSupported ? '\\p{Ps}\\p{Pi}"\'' : '\\(\\[{"\'';
+	const mentionCharacters = regExpFeatureDetection.isUnicodeGroupSupported ? '\\p{L}\\p{N}' : 'a-zA-ZÀ-ž0-9';
 
 	// The pattern consists of 3 groups:
 	// - 0 (non-capturing): Opening sequence - start of the line, space or an opening punctuation character like "(" or "\"",

+ 8 - 8
packages/ckeditor5-mention/tests/mentionui.js

@@ -16,9 +16,9 @@ import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventd
 import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import env from '@ckeditor/ckeditor5-utils/src/env';
+import regExpFeatureDetection from '@ckeditor/ckeditor5-utils/src/featuredetection/regexp';
 
 import MentionUI, { createRegExp } from '../src/mentionui';
-import featureDetection from '../src/featuredetection';
 import MentionEditing from '../src/mentionediting';
 import MentionsView from '../src/ui/mentionsview';
 import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
@@ -449,10 +449,10 @@ describe( 'MentionUI', () => {
 			let regExpStub;
 
 			// Cache the original value to restore it after the tests.
-			const originalGroupSupport = featureDetection.isUnicodeGroupSupported;
+			const originalGroupSupport = regExpFeatureDetection.isUnicodeGroupSupported;
 
 			before( () => {
-				featureDetection.isUnicodeGroupSupported = false;
+				regExpFeatureDetection.isUnicodeGroupSupported = false;
 			} );
 
 			beforeEach( () => {
@@ -465,18 +465,18 @@ describe( 'MentionUI', () => {
 			} );
 
 			after( () => {
-				featureDetection.isUnicodeGroupSupported = originalGroupSupport;
+				regExpFeatureDetection.isUnicodeGroupSupported = originalGroupSupport;
 			} );
 
 			it( 'returns a simplified RegExp for browsers not supporting Unicode punctuation groups', () => {
-				featureDetection.isUnicodeGroupSupported = false;
+				regExpFeatureDetection.isUnicodeGroupSupported = false;
 				createRegExp( '@', 2 );
 				sinon.assert.calledOnce( regExpStub );
 				sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\(\\[{"\'])([@])([_a-zA-ZÀ-ž0-9]{2,})$', 'u' );
 			} );
 
 			it( 'returns a ES2018 RegExp for browsers supporting Unicode punctuation groups', () => {
-				featureDetection.isUnicodeGroupSupported = true;
+				regExpFeatureDetection.isUnicodeGroupSupported = true;
 				createRegExp( '@', 2 );
 				sinon.assert.calledOnce( regExpStub );
 				sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\p{Ps}\\p{Pi}"\'])([@])([_\\p{L}\\p{N}]{2,})$', 'u' );
@@ -564,7 +564,7 @@ describe( 'MentionUI', () => {
 				// Belongs to Pi (Punctuation, Initial quote) group:
 				'«', '‹', '⸌', ' ⸂', '⸠'
 			] ) {
-				testOpeningPunctuationCharacter( character, !featureDetection.isUnicodeGroupSupported );
+				testOpeningPunctuationCharacter( character, !regExpFeatureDetection.isUnicodeGroupSupported );
 			}
 
 			it( 'should not show panel for marker in the middle of other word', () => {
@@ -834,7 +834,7 @@ describe( 'MentionUI', () => {
 			} );
 
 			it( 'should open panel for unicode character ב', function() {
-				if ( !featureDetection.isUnicodeGroupSupported ) {
+				if ( !regExpFeatureDetection.isUnicodeGroupSupported ) {
 					this.skip();
 				}