|
@@ -294,8 +294,9 @@ export default class ColorInputView extends View {
|
|
|
*/
|
|
*/
|
|
|
_setInputValue( inputValue ) {
|
|
_setInputValue( inputValue ) {
|
|
|
if ( !this._stillTyping ) {
|
|
if ( !this._stillTyping ) {
|
|
|
|
|
+ const normalizedInputValue = normalizeColor( inputValue );
|
|
|
// Check if the value matches one of our defined colors.
|
|
// Check if the value matches one of our defined colors.
|
|
|
- const mappedColor = this.options.colorDefinitions.find( def => inputValue === def.color );
|
|
|
|
|
|
|
+ const mappedColor = this.options.colorDefinitions.find( def => normalizedInputValue === normalizeColor( def.color ) );
|
|
|
|
|
|
|
|
if ( mappedColor ) {
|
|
if ( mappedColor ) {
|
|
|
this._inputView.value = mappedColor.label;
|
|
this._inputView.value = mappedColor.label;
|
|
@@ -305,3 +306,16 @@ export default class ColorInputView extends View {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// Normalizes color value, by stripping extensive whitespace.
|
|
|
|
|
+// For example., transforms:
|
|
|
|
|
+// * ` rgb( 25 50 0 )` to `rgb(25 50 0)`,
|
|
|
|
|
+// * "\t rgb( 25 , 50,0 ) " to `rgb(25 50 0)`.
|
|
|
|
|
+//
|
|
|
|
|
+// @param {String} colorString The value to be normalized.
|
|
|
|
|
+// @returns {String}
|
|
|
|
|
+function normalizeColor( colorString ) {
|
|
|
|
|
+ // Remove any whitespace at the beginning, after `(`, or `,`, at the end, before `)`, `,`, or another whitespace.
|
|
|
|
|
+ // Then, replace `,` or whitespace with single space.
|
|
|
|
|
+ return colorString.replace( /(?<=^|\(|,)\s*|\s*(?=$|\)|\s|,)|/g, '' ).replace( /,|\s/g, ' ' );
|
|
|
|
|
+}
|